I have a list in Python:
['first', 'second', 'foo']
I want to create a list of lists named after the list elements:
newlist = ['first':[], 'second':[], 'foo':[]]
I have seen some proposals that use Dictionaries, but when I tried to do it with OrderedDict, I lost the order of the elements in the creation.
Thanks in advance.
'first') to be associated with something (like a list), you have key-value-pairs. These are usually implemendet asdict({'first': [], 'second': []}) but if you really want a list, then I recommend a list oftuples ([('first', []), ('second', [])]).OrderedDict. It's sole purpose is to retain the order in which you insert the elements.