Classic, but i’m new to python… and have a problem a can’t manage to solve. I’m assuming it’s fairly easy.
I have two csv files, one scraped from the web(a=[]), containing 20000+ lines, the other exported from a local system [b=[]] 80+ lines.
I have open the files and stored the data in list a and b. Theey are structured like the example below.
a = [[1,'a','b','a@b',11],
[2,'c','d','c@b',22],
[3,'e','f','e@b',33]]
b = [['a','banana','A',100],
['e','apple','A',100]]
Now i would like to go through list a and when index 1 of every sublist in list a is equal to index 0 of the sublist in list b it shall append index 3 and 4 of a. So I would end up with
c= [['a','banana','A',100,'a@b',11],
['e','apple','A',100,'e@b',33],]
How to achive this. The solution don’t need to be fast if it teaches something about the structure in Python. But if solved easy with pandas i’m all ears.
If this fora is not for questions like this i’m sorry for the time.
>Solution :
This is not optimized and isn’t efficient time complexity vice, but it’s readable and does the job.
c = []
for a_entry in a:
for b_entry in b:
if a_entry[1] == b_entry[0]:
c.append(b_entry + a_entry[3:])