0

I have a list of lists and I want to convert to list of frozenset in original order. I've tried the code below but the output isn't in the original order.

data=[[118, 175, 181, 348, 353], [117, 175, 181, 371, 282, 297], [119, 166, 176, 54, 349]]

my code:

>>> transactionList=list()
>>> for rec in data:
      transaction = frozenset(rec)
      transactionList.append(transaction)

output i got is not in original order:

>>> transactionList
    [frozenset([353, 348, 181, 118, 175]), frozenset([297, 175, 371, 181, 282, 117]), frozenset([176, 349, 54, 166, 119])]

my expected output in original order:

>>> transactionList
    [frozenset([118, 175, 181, 348, 353]), frozenset([117, 175, 181, 371, 282, 297]),frozenset([119, 166, 176, 54, 349])]
Erna Piantari
  • 547
  • 2
  • 11
  • 26

1 Answers1

0

frozensets, like sets, have no defined order. See Does Python have an ordered set? for ways to overcome this with custom classes.

Community
  • 1
  • 1
wRAR
  • 25,009
  • 4
  • 84
  • 97