-1

I am trying to create a set from a list which I need it to be in order.

someList = ['from', 'from', 'who', 'are', 'are', 'frost', 'fire', 'are']

someSet = set(list)

Doing that yields a random ordered sets.

I need it to always be in order like

someSet >> {'from', 'who', 'are', 'frost', 'fire', 'are'}
Gavin
  • 2,784
  • 6
  • 41
  • 78

1 Answers1

0

you can do like this

someist = ['from', 'from', 'who', 'are', 'are', 'frost', 'fire', 'are']
new_list[]
for x in somelist:
    if x not in new_list:
        new_list.append(x)

In the above code, if new_list will have the element it will not append, so you will get in order

Hackaholic
  • 19,069
  • 5
  • 54
  • 72
  • 2
    Membership testing in a list is `O(n)`; you should still be using a `set` to keep track of the items already seen. – jonrsharpe Oct 31 '14 at 18:21