Arranging a List
แจแ แแตแ list elements order แ แแแแแแ แแแแต แแตแจแ แฅแแฝแแแแฃ แญแแแแ แจแแแจแแ แ แฅแแแ methods แแแข
1. sort() method
In a list by default insertion order is preserved แแแตแ แแแแชแซ แแญ แจlistแกแ element แฃแตแแแฅแแ แต แฆแณ แแ แจแแแแแแข
If we want to sort the elements of the list according to default natural sorting order then we should go for sort() method.
แ แแฅแฎแฝ default natural sorting order ascending order แแแข
แ strings default natural sorting order alphabetical order แแแข
sort() method แแแ แแ listแก แฐแแณแณแญ type แซแแธแแ elements แแซแ แ แแ แตแฃ แ แแ แแแซ we will get TypeError.
แแแณแ :
2. reverse() method
This method reverses the order of list elements.
แแแณแ :
...
#Lists
#ArrangingLists
@python_pioneers
@python_pioneers
แจแ แแตแ list elements order แ แแแแแแ แแแแต แแตแจแ แฅแแฝแแแแฃ แญแแแแ แจแแแจแแ แ แฅแแแ methods แแแข
1. sort() method
In a list by default insertion order is preserved แแแตแ แแแแชแซ แแญ แจlistแกแ element แฃแตแแแฅแแ แต แฆแณ แแ แจแแแแแแข
If we want to sort the elements of the list according to default natural sorting order then we should go for sort() method.
แ แแฅแฎแฝ default natural sorting order ascending order แแแข
แ strings default natural sorting order alphabetical order แแแข
sort() method แแแ แแ listแก แฐแแณแณแญ type แซแแธแแ elements แแซแ แ แแ แตแฃ แ แแ แแแซ we will get TypeError.
Syntax :
list_name.sort()
แแแณแ :
yene_list = [4, 5, 3, 1, 2]
yene_list.sort()
print(yene_list)
Output : [1, 2, 3, 4, 5]
2. reverse() method
This method reverses the order of list elements.
Syntax :
list_name.reverse()
แแแณแ :
lela_list = [1, 4, 2, 8, 6]
lela_list.reverse()
print(lela_list)
Output : [8, 6, 4, 2, 1]
...
#Lists
#ArrangingLists
@python_pioneers
@python_pioneers
๐1