For example if I have a list:
JavaScript
x
7
1
[
2
["nameoffile1","version1","date02/03"],
3
["nameoffile1","version2","date02/04"],
4
["nameoffile2","version2","date05/02"],
5
["nameoffile3","version3","date02/04"]
6
]
7
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.
JavaScript
1
5
1
from collections import defaultdict
2
d = defaultdict(list)
3
for row in lst:
4
d[row[0]].append(row)
5