Skip to content

Instantly share code, notes, and snippets.

@shamikalashawn
Created February 6, 2017 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamikalashawn/fdaea62a3d2b9e008b8251d7ea4c9ee5 to your computer and use it in GitHub Desktop.
Save shamikalashawn/fdaea62a3d2b9e008b8251d7ea4c9ee5 to your computer and use it in GitHub Desktop.
A string is collected then each element of the string is turned into a value in a dictionary while its key is its index.
string = input('Please type in a string.')
if type(string) != str:
string = input('That is not a string! Please type a string.')
else:
strindex = range(len(string))
strlist = []
for letter in string:
strlist.append(letter)
stringdict = dict(zip(strindex, strlist))
print (stringdict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment