Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- name=input("Enter your name:")
- #string to list conversion
- list_char=list(name)
- print("\n")
- print(list_char)
- #simple sort for list items
- for i in range(len(list_char)):
- for j in range(i+1,len(list_char)):
- if (list_char[i]>list_char[j]):
- temp=list_char[i]
- list_char[i]=list_char[j]
- list_char[j]=temp
- #list to string conversion
- new_string=""
- for i in range(len(list_char)):
- new_string+=list_char[i]
- #string with sorted characters
- print("Sorted String: "+new_string)
- '''
- Output
- Python 3.6.1 (default, Dec 2015, 13:05:11)
- [GCC 4.8.2] on linux
- Enter your name: axouprbnfgr
- ['a', 'x', 'o', 'u', 'p', 'r', 'b', 'n', 'f', 'g', 'r']
- Sorted String: abfgnoprrux
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement