How to sort a list alphabetically in Python

2 Answers

0 votes
lst = ['python', 'c', 'c++', 'php', 'java']

lst.sort()

print(lst)



'''
run:

['c', 'c++', 'java', 'php', 'python']

'''

 



answered Apr 19, 2021 by avibootz
0 votes
lst = ['python', 'c', 'c++', 'javascript', 'java', "c#", "swift", "nodejs"]

lst = sorted(lst)

print(lst)



'''
run:

['c', 'c#', 'c++', 'java', 'javascript', 'nodejs', 'python', 'swift']

'''

 



answered Apr 19, 2021 by avibootz

Related questions

1 answer 120 views
1 answer 138 views
1 answer 163 views
1 answer 232 views
1 answer 152 views
4 answers 405 views
...