Python Pioneers: A Beginner's Guide ๐Ÿ‡ช๐Ÿ‡น
8.65K subscribers
346 photos
40 videos
24 files
64 links
Welcome to Python Pioneers: Empowering Ethiopian students to embark on their coding journey.

๐Ÿ“ข Channel: @python_pioneers
๐Ÿ‘ฅ Group: @python_pioneers_chat
Download Telegram
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.

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