For example if I have a list:
[
["nameoffile1","version1","date02/03"],
["nameoffile1","version2","date02/04"],
["nameoffile2","version2","date05/02"],
["nameoffile3","version3","date02/04"]
]
if I have to retrieve just the nameoffile1 based on names how can I retrieve those 2 arrays based on names
thanks
Advertisement
Answer
You can use a dictionary to collect together all the items with the same name. If you use defaultdict to create an empty list the first time a name is encountered, it becomes trivial.
from collections import defaultdict
d = defaultdict(list)
for row in lst:
d[row[0]].append(row)