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"

Try ''.join(sorted(sec))

Try this ...


s = "Mathematics".upper()

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

print(s3)  # MATHEICS
>>> from collections import OrderedDict
>>> s = "Mathematics".upper()
>>> ''.join(OrderedDict.fromkeys(s))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.