Advertisement
Guest User

Untitled

a guest
Feb 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. >>> string = "this is string"
  2. >>> dict = {}
  3. >>> y=0
  4. >>> for x in string.strip():
  5. ...     if x in dict.keys():
  6. ...             dict[x] = [dict[x], y]
  7. ...     else:
  8. ...             dict[x] = y
  9. ...     y +=1
  10. ...
  11. >>> dict
  12. {'t': [0, 9], 'h': 1, 'i': [[2, 5], 11], 's': [[3, 6], 8], ' ': [4, 7], 'r': 10, 'n': 12, 'g': 13}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement