0

i have a list of names:

listA = ('bored','bob','ben','bill')

i'd like to ask if its possible to create X different lists from the names of is listA?

example:

bored = []
bob = []
ben = []
bill = []

i tried this code but i'm not sure it works:

listA = ('bored','bob','ben','bill')
for names in listA:
    lName = 'list_' +str(names)
    exec(lName+ '=[]')
    exec('print '+ lName)

I would greatly appreciate any help on this... thanks in advance!

my list (listA) came first, i'd like to know if its possible to create new lists with names using the string data in listA.

BigBanzai
  • 3
  • 2
  • Hi DeepSpace, doesn't look like it. i have the list first (listA) and from that list, i wanted to ask if i could use the strings inside ('bored','bob','ben','bill') to make new lists. – BigBanzai Sep 29 '16 at 12:22
  • What you *can* and **should** do is `d = dict.fromkeys(listA, [])` to create a mapping from the values in `listA` to empty lists and access them as `keys` in `d`. – Dimitris Fasarakis Hilliard Sep 29 '16 at 12:26
  • Thanks Jim Fasarakis-Hillard, i'll try that out and see if it works. Thanks again! – BigBanzai Sep 29 '16 at 12:28

0 Answers0