'How to add a word in the list of Alphabetical order in python programming language without repeating letters from the alphabet?
How to add a word in the list of Alphabetical order in python programming language without repeating letters from the alphabet?
Here's my code:
key=input("Enter key:")
key=key.replace(" ", "")
key=key.upper()
result=list()
for c in key: #storing key
if c not in result:
result.append(c)
flag=0
for i in range(65,91):
result.append(chr(i))
print(result)
Solution 1:[1]
You can take input from user
key=input("Enter key:")
key=key.replace(" ", "") #to remove space if any between characters
key=key.upper() #to convert to upper case
Take set of key to remove duplicates from key:
key=set(key)
Finally, sorted the set with sorted, it will return a list:
result=sorted(key)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Talha Tayyab |