Say I've written a function that will take an unlimited number of arguments and store them under different variables.
Since the use is able to input any number of strings, it's not possible to give names to all the variables that might be created.
So, how would I create variables when the program is running ? I would like to create variables that have progressive names like.. (for the example above), string_one, string_two, string_three.. or string1, string2 , string3

EDIT: Just did some googling... Could I use dictionaries?

Edited 7 Years Ago by mahela007: n/a

IMHO, a dictionary would be the way to go ...

str_dict = {}
count = 1
while True:
    mystr = raw_input("Enter a string (just Enter to quit): ")
    if not mystr:
    str_dict[count] = mystr
    count += 1

# test

# show string at key 2
key = 2
if key in str_dict:

"""my output -->
Enter a string (just Enter to quit): aaaa
Enter a string (just Enter to quit): bbbb
Enter a string (just Enter to quit): cccc
Enter a string (just Enter to quit): 
{1: 'aaaa', 2: 'bbbb', 3: 'cccc'}
This question has already been answered. Start a new discussion instead.