How to compare multiple list in range python?

Viewed 12

I have the following code. How do i make it shorter? I just one range?

for x in range(len(list1)):
    if list1[x] == "AU":    
        d1[x] = d1[x]+" "+"not"
for y in range(len(list2)):
    if list2[y] == "AU":    
        d2[y] = d2[y]+" "+"not"
for z in range(len(list3)):
    if list3[z] == "AU":    
        d3[z] = d3[z]+" "+"not"
for a in range(len(list4)):
    if list4[a] == "AU":    
        d4[a] = d4[a]+" "+"not"
for b in range(len(list5)):
    if list5[b] == "AU":    
        d5[b] = d5[b]+" "+"not"

print(str(d1))
print(str(d2))
print(str(d3))
print(str(d4))
print(str(d5))
    

any help or any suggestion would be appreciating.. Thabk you

1 Answers

Using nested loops

lists = [list1, list2, list3, list4, list5]
dlists = [d1, d2, d3, d4, d5]
for lst, d in zip(lists, dlists):
    for i in range(len(lst)):
        if lst[i] == 'AU':
            d[i] += " not"
    print(d)
Related