title: Assign a number to each unique value in a list
body: <p>I have a list of strings. I want to assign a unique number to each string (the exact number is not important), and create a list of the same length using these numbers, in order. Below is my best attempt at it, but I am not happy for two reasons:</p>
  
  <ol>
  <li><p>It assumes that the same values are next to each other </p></li>
  <li><p>I had to start the list with a <code>0</code>, otherwise the output would be incorrect</p></li>
  </ol>
  
  <p>My code:</p>
  
  <pre><code>names = ['ll', 'll', 'll', 'hl', 'hl', 'hl', 'LL', 'LL', 'LL', 'HL', 'HL', 'HL']
  numbers = [0]
  num = 0
  for item in range(len(names)):
      if item == len(names) - 1:
        break
      elif names[item] == names[item+1]:
          numbers.append(num)
      else:
          num = num + 1
          numbers.append(num)
  print(numbers)
  </code></pre>
  
  <p>I want to make the code more generic, so it will work with an unknown list. Any ideas?</p>