Reputation: 627
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])]
Upvotes: 0
Views: 1685
Reputation: 25693
frozenset
s, like set
s, have no defined order. See Does Python have an ordered set? for ways to overcome this with custom classes.
Upvotes: 0