Insertion of List Elements
โก๏ธ
INSERTION OF LIST ELEMENTS
แ แแต list แแตแฅ แ แณแต element แจแแแจแแญแ แต แฅแ แ แญแแต แแแแต แ แแฃ แจแฅแแแ แแแแถแฝ แแแฑแ แฅแแญแข
1. append() method
แญแแแ method แ แ แแ แ แแต list แแตแฅ แ แฒแต element แแจแแญ แฅแแฝแแแแฃ add แจแแแจแแ element แฐแแ แจแแจแแจแ แจlistแก แแจแจแป แแญ แแแข
แแแณแ:
2. insert() method
แญแแแแ method แฐแแ แ แฒแต element specified แจแแ แฆแณ แแญ แแแตแแฃแต แตแแแแ แฅแแ แแแแแแข แแแต argument แฅแแฐ input แญแแตแณแ one is the index and the other is the element.
An argument refers to the value that is passed to a function or method when it is called.
แแแณแ:
...
#Lists
#Python
@python_pioneers
@python_pioneers
แ แแต list แแตแฅ แ แณแต element แจแแแจแแญแ แต แฅแ แ แญแแต แแแแต แ แแฃ แจแฅแแแ แแแแถแฝ แแแฑแ แฅแแญแข
1. append() method
แญแแแ method แ แ แแ แ แแต list แแตแฅ แ แฒแต element แแจแแญ แฅแแฝแแแแฃ add แจแแแจแแ element แฐแแ แจแแจแแจแ แจlistแก แแจแจแป แแญ แแแข
Syntax :
list_name.append(new_element)
แแแณแ:
countrys = ["Ethiopia", "Uganda", "France"]
#if I want to add "Kenya" in the list I can use append() and it will add the country's name at the end of the list
countrys.append("Kenya")
print(countrys)
#Output : ["Ethiopia", "Uganda", "France", "Kenya"]
2. insert() method
แญแแแแ method แฐแแ แ แฒแต element specified แจแแ แฆแณ แแญ แแแตแแฃแต แตแแแแ แฅแแ แแแแแแข แแแต argument แฅแแฐ input แญแแตแณแ one is the index and the other is the element.
Syntax :
list_name.insert(i, new_element)
แแแณแ:
countrys = ["Ethiopia", "Uganda", "France"]
#I can use the insert method here to add the country name at specified index
countrys.insert(2, "Kenya")
print(countrys)
#Output : ["Ethiopia", "Uganda", "Kenya", "France"]
...
#Lists
#Python
@python_pioneers
@python_pioneers
Forwarded from Zaphnath Paaneah
Join our channel and embark on your coding journey with us!
๐ @python_pioneers
Gain access to free coding lessons in Amharic language. Additionally, stay updated on the latest tech news and new innovations.
Pythonแ แ แ แแญแ แฅแแแญ!
@python_pioneers
@python_pioneers
๐ @python_pioneers
Gain access to free coding lessons in Amharic language. Additionally, stay updated on the latest tech news and new innovations.
Pythonแ แ แ แแญแ แฅแแแญ!
@python_pioneers
@python_pioneers
๐2โค1โก1
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
Python Pioneers: A Beginner's Guide ๐ช๐น
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โฆ
This media is not supported in your browser
VIEW IN TELEGRAM
๐5
๐ Scientists from USA have developed an inexpensive electric bandage that speeds up wound healing by 30%.
To activate the bandage, you just need to moisten it, and it starts delivering a weak current that stimulates cells and suppresses bacterial growth.
It's a single-use product, but itโs expected to cost just $1. However, thereโs no production timeline yet as clinical trials are still ahead.
#Technology
#Tech
#News
@hitechdailynews
@python_pioneers
To activate the bandage, you just need to moisten it, and it starts delivering a weak current that stimulates cells and suppresses bacterial growth.
It's a single-use product, but itโs expected to cost just $1. However, thereโs no production timeline yet as clinical trials are still ahead.
#Technology
#Tech
#News
@hitechdailynews
@python_pioneers
๐2๐จ1
๐3
Nextโก : Mathematical Operations on List (using List Methods)
Mathematical Operations on List (using List Methods)
แ แแต list แแญ mathematical operations แแแซแแต แจแแแ แแแธแ แฅแ แ แญแแต methods แฅแแตแแ แฅแ แฅแญแแต functions แ แแข
Let's see them one by one...
1. len()
แญแแแ len() function แจแแแ แแแ แ แ แแต listแแตแฅ แซแแตแ elements แฅแแต(แจlistแกแ length) แแแแ แตแแแแ แแแข
Syntax:
len(list_name)
แแแณแ :
Items = ["rubber", "pencil", "book", "pen"]
length = len(Items)
print(length)
#Output : 4
2. count() method
แญแแแ method แฐแแ แจแแแ แแแ แ แ แแต list แแตแฅ แซแ แจแแ specific element แแ แซแ แ occur แฅแแณแจแ แแแแ แตแแแแ แแแข
Syntax :
list_name.count(element)
แแแณแ :
alps = ["a", "e", "g", "a", "f", "g", "a"]
occurrence_of_a = alps.count("a")
print(occurrence_of_a)
#Output : 3
3. max()
max() function แ แ แแต list แแตแฅ แตแแแ element return แซแจแแแข
Syntax :
max(list_name)
4. min()
min() function แฐแแ แ แฐแแซแแ แจแ แแตแ list แตแแนแ element return แซแจแแแแแฃ
Syntax :
min(list_name)
max() แฅแ min() function แ แแณแ แฅแแแแจแตแข
nums = [5, 90, 34, 65, 23, 7, 10]
print(max(nums)) #Output : 90
print(min(nums)) #Output : 5
...
#MathsOpOnLists
#Lists
@python_pioneers
๐1
Here are some multiple choice questions: Answer them by reacting for the correct ones as stated below ๐
A == ๐
B == ๐ญ
C == ๐ข
D == ๐ค
A == ๐
B == ๐ญ
C == ๐ข
D == ๐ค