1

i need to access strings using raw_input.

list1 = ["one","Two","three"]

list2 = ["1","2","3"]

while True:

        ip = raw_input("enter list: ")
        for i  in  ip:
                    print i
        break

When "list1" is given as input, it takes as string but not as list. I need to access the list defined above. I need a way to access the lists and print the list.

trinaldi
  • 2,872
  • 2
  • 32
  • 37
kiran6
  • 1,247
  • 2
  • 13
  • 19

1 Answers1

1

Use a dict:

lists = {
    "list1": ["one","Two","three"],
    "list2": ["1","2","3"],       
}

while True:
    choice = raw_input("enter the list name: ")
    try:
        for item in lists[choice]:
            print item
    except KeyError:
        print "I never heard of any list named '{}'! Try again.".format(choice)
    else:
        break
Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153