title: Next bigger number with the same digits - Codewars Kata - How can I improve it
body: <p>So this kata says:</p>
  
  <blockquote>
    <p>You have to create a function that takes a positive integer number and
    returns the next bigger number formed by the same digits:</p>
  
  <pre><code>12 ==&gt; 21
  513 ==&gt; 531
  2017 ==&gt; 2071
  </code></pre>
    
    <p>If no bigger number can be composed using those digits, return -1:</p>
  
  <pre><code>9 ==&gt; -1
  111 ==&gt; -1
  531 ==&gt; -1
  </code></pre>
  </blockquote>
  
  <p>I wrote a code to it after so many failures despite the exercise being pretty simple. I was wondering if there are ways i could improve my code, and if there are , please point them out, I'm only trying to understand how to think better.</p>
  
  <pre><code>def next_bigger(num):
  # First I checked it returns -1 if numbers already have descending digits and there's no bigger number
   if int("".join(sorted(str(num), reverse=True))) == num:  
       return -1
  # Then I converted the number num into a list of strings
   num_list= list(str(num)) 
  # Iterated through the num list. starting from the last number and going backwards
   for i in range(len(num_list) -1, 0, -1):
         # If one digit is bigger than it's predecessor:
          if num_list[i] &gt; num_list[i-1]:     
              A=num_list[:i]    # Slices num_list into 2 lists, A
              B=num_list[i:]    # And B
              break                 
  # I think there's a better way to do this next part, but nothing else came into my mind
  
  #     So I made a clone of the second list and sorted it ascendantly
  # for the smallest number to be in the first place([0])
   B_list_for_min_num=sorted(list(B))   
  
  # And deleted every minimum number (from the copied B list) that
  #was smaller than the last digit in list A through a While loop
   while B_list_for_min_num[0] &lt;= A[-1]:    
       del B_list_for_min_num[0]  
  
  # Then swapped the last digit from list A and the minimum digit from the copied B list, but with the digit from the original B list
   B[B.index(min(B_list_for_min_num))], A[-1] = A[-1], B[B.index(min(B_list_for_min_num))]
  # Then sorted the changed B list ascendently to make sure it will result exactly the next bigger number
   B = sorted(B)
  # Then joined the lists together
   finish = A + B
  # And turned them into an integer     
   result = int(''.join(map(str, finish)))
  # Aaaand returned the result 
   return result 
  </code></pre>