0
one=['nlo_90', 'nlo_90', 'nhi_88']
two=['12', '12', '84']
three=[['a','a','b','c'], ['a','a','b','c'], ['b','g','g','b']]
new_three=[list(dict.fromkeys(q)) for q in three]

z=zip(one,two,new_three)
for a,b,c in z:
        c_str = ', '.join(c)
        print(f'{a}, {b}, {c_str}')

I need to remove duplicate data after i combine the lists using zip()

the output from above code is

nlo_90, 12, a, b, c
nlo_90, 12, a, b, c
nhi_88, 84, b, g

my desired output is

nlo_90, 12, a, b, c
nhi_88, 84, b, g

I tried to code this new=list(dict.fromkeys(z)) to remove duplicate but it shows error

TypeError: unhashable type: 'list'

qwe
  • 27
  • 4
  • The issue is you are using `list()` in `new_three=[list(dict.fromkeys(q)) for q in three]`, just change this to a `tuple()` and you will be able to do `dict.fromkeys(z)` – AChampion Aug 06 '20 at 05:26

1 Answers1

0

This Will Surely At Any Cost Give The Desired Output.

one = ['nlo_90', 'nlo_90', 'nhi_88']
two = ['12', '12', '84']
three = [['a', 'a', 'b', 'c'], ['a', 'a', 'b', 'c'], ['b', 'g', 'g', 'b']]
new_three = [list(dict.fromkeys(q)) for q in three]

z = zip(set(one), two, new_three)

res = []

for a, b, c in z:
    c_str = ', '.join(c)
    res.append(f'{a}, {b}, {c_str}')

for res in reversed(sorted(res)):
    print(res)

Output

nlo_90, 12, a, b, c
nhi_88, 12, a, b, c
Aryan
  • 1,093
  • 9
  • 22