0

I have a function that has takes in a string "secret"

sec = set(secret)
print sec

output: set(['A', 'C', 'E', 'I', 'H', 'M', 'S', 'T'])

Assuming I called the function sending in the string "Mathematics", how do I get an ordered set. I'm looking to get unique characters in the original element order. In other words, I want the output to be "MATHETICS" not "ACEIHMST"

4
Contributors
3
Replies
45
Views
4 Years
Discussion Span
Last Post by snippsat
2

Try this ...

'''
wants
"MATHEICS" not "ACEIHMST"
'''

s = "Mathematics".upper()

s3 = ""
for c in s:
    if c not in s3:
        s3 += c

print(s3)  # MATHEICS
1
>>> from collections import OrderedDict
>>> s = "Mathematics".upper()
>>> ''.join(OrderedDict.fromkeys(s))
'MATHEICS'
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.