Sunday 2 October 2022

Sorted String in Python : Example


sort strings

Passing a string to sorted() returns a list containing the sorted characters as elements.

org_str = 'cebad'

new_str_list = sorted(org_str)
print(org_str)
print(new_str_list)
# cebad
# ['a', 'b', 'c', 'd', 'e']

 Source : https://note.nkmk.me/en/python-list-sort-sorted/#:~:text=In%20Python%2C%20there%20are%20two,tuple%20)%2C%20use%20sorted()%20.

No comments:

Post a Comment