I need to compare between two lists for a partial match and then create a new list based on the matching items. My current output is empty. Thanks in advance.
JavaScript
x
11
11
1
accounts = ['0x1212 - staff1', '0x65gs - tech01', '0x43nd - staff3', '0x89ng - tech02']
2
stats = ['0x1212 - (23.90)', '0x43nd - (4.70)', '0x342r - (3.76)', '0x323f - (2.76)']
3
4
data = []
5
6
for b in stats:
7
if any(a.startswith(b) for a in accounts):
8
data.append(b)
9
10
print (data)
11
Current Output:
JavaScript
1
2
1
[]
2
Needed Output:
JavaScript
1
3
1
Found: ['0x1212 - (23.90) - staff1, 0x43nd - (4.70) - staff3']
2
Not Found: ['0x65gs - tech01', '0x89ng - tech02']
3
Advertisement
Answer
You seem to only want to look at the first 6 characters of each account. Use this:
JavaScript
1
14
14
1
found = []
2
not_found = []
3
4
for b in stats:
5
for a in accounts:
6
if a[:6] == b[:6]:
7
found.append(b+a[6:])
8
break
9
else:
10
not_found.append(a)
11
12
print(found)
13
print(not_found)
14