1
li1 = [['a','b','c'], ['c','d','e']]
li2 = [['c','a','b'], ['c','e','d']]
c = 1
for i in range(len(l11)):
    if (sorted[li1[i]]!=sorted(li2[i]):
        c = 0
if(c): k = True
else: k = False

How to write this in one line? Also how to use zip() to accomplish this? What if li2 = [['a','c','b']]? Using zip would return True but it should give a False.

Yashu Seth
  • 935
  • 4
  • 9
  • 24

1 Answers1

5

You can use zip:

>>> zip(li1, li2)
<zip object at 0x0000000000723248>
>>> list(zip(li1, li2))
[(['a', 'b', 'c'], ['c', 'a', 'b']), (['c', 'd', 'e'], ['c', 'e', 'd'])]

and all:

>>> all([True, True, True])
True
>>> all([True, False, True])
False

k = all(sorted(x) == sorted(y) for x, y in zip(li1, li2))
falsetru
  • 357,413
  • 63
  • 732
  • 636