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 == ๐ค
1. What is the result of the following operation?
- ๐)
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = list1 + list2
- ๐)
[1, 2, 3, 4, 5, 6]
-๐ญ) [5, 7, 9]
-๐ข) [(1, 4), (2, 5), (3, 6)]
-๐ค) None of the above๐8
2. What does the following Python code return?
- ๐)
list1 = [1, 2, 3]
result = list1 * 2
- ๐)
[2, 4, 6]
-๐ญ) [1, 2, 3, 1, 2, 3]
-๐ข) [1, 1, 2, 2, 3, 3]
-๐ค) None of the above๐ญ6๐1
Forwarded from Python Pioneers: A Beginner's Guide ๐ช๐น
Nice question
In case of lists containing strings, when we use max() and min() function, they return the maximum or minimum element based on lexicographical order
แแแณแ:
"name" has higher lexicographic order than "age", so if we use max() for a list containing only the two, the function returns "name"
But also there's something called key, in which you specify the criteria you want to compare by
Is this helpful ๐
In case of lists containing strings, when we use max() and min() function, they return the maximum or minimum element based on lexicographical order
แแแณแ:
"name" has higher lexicographic order than "age", so if we use max() for a list containing only the two, the function returns "name"
But also there's something called key, in which you specify the criteria you want to compare by
Is this helpful ๐
๐2
3. What will be the output of the following code?
๐) 5
๐ญ) 10
๐ข) 25
๐ค) 20
numbers = [5, 10, 15, 20, 25]
print(max(numbers))
๐) 5
๐ญ) 10
๐ข) 25
๐ค) 20
๐ข6
4. What will be the output of the following code?
๐) 9
๐ญ) 4
๐ข) 3
๐ค) 5
numbers = [3, 7, 2, 9, 4]
print(len(numbers))
๐) 9
๐ญ) 4
๐ข) 3
๐ค) 5
๐ค3
5. What will be the output of the following code?
๐) "apple"
๐ญ) "banana"
๐ข) "orange"
๐ค) "kiwi"
words = ["apple", "banana", "orange", "kiwi"]
print(max(words))
๐) "apple"
๐ญ) "banana"
๐ข) "orange"
๐ค) "kiwi"
๐ญ1
6. What will be the output of the following code?
๐) "cat"
๐ญ) "bird"
๐ข) "sheep"
๐ค) "elephant"
words = ["cat", "sheep", "elephant", "bird"]
print(min(words, key=len))
๐) "cat"
๐ญ) "bird"
๐ข) "sheep"
๐ค) "elephant"
๐2๐ค1
Shake off problems:
Moral: Donโt choose to live with your problem. Just shake off your problems and stand on it and step up in life after learning from them. Every bad experience is a new learning. So get the positives out of it and work towards your goals.
#Stories
@python_pioneers
A man and his donkey were on the way to grazing while the donkey fell into a huge pit. The man was shaken and tried hard to pull off his favorite donkey up to the ground.
Despite his strenuous attempts, he failed to bring the donkey back. But he canโt leave the donkey to starve and die with pain for days.
So he decided to bury him alive and make his death smoother. So he started pouring soil over the donkey in the pit. When he poured the soil, the donkey felt the load and shakes it off and he steps on it.
He does the same every time when the soil was poured on his body. In the end, he reached the ground level and easily walked away to graze in the green pastures.
Moral: Donโt choose to live with your problem. Just shake off your problems and stand on it and step up in life after learning from them. Every bad experience is a new learning. So get the positives out of it and work towards your goals.
#Stories
@python_pioneers
โค3๐ฅ2
Memory of the past
This was our first post, at the time there were only 69 subscribers, but now there are so many ppl, who also become part of this family ๐ฅฐ
แแแฝแแแ แตแ แ แฅแฎแแณแฝแแฃ แจแแแฝแ แ แซแ แตแแแแฝแ แฅแแแฐแแแแ!
@python_pioneers
This was our first post, at the time there were only 69 subscribers, but now there are so many ppl, who also become part of this family ๐ฅฐ
แแแฝแแแ แตแ แ แฅแฎแแณแฝแแฃ แจแแแฝแ แ แซแ แตแแแแฝแ แฅแแแฐแแแแ!
@python_pioneers
๐ฅ3
Forwarded from Abiy Ahmed Ali ๐ช๐น
แ แฒแแณแ แขแตแฎแตแซ แแ แ แแต แฅแแญแณ แจแณแจแ แต แฐแจแ แแญ แฐแญแฐแแแข แขแตแฎ แดแแฎแ แจแชแ แฉแฃแแซ แแญ แ แแฐแฃแ แญ แ แขแตแฎแฝแซ แจแแแแชแซแแ แ แชแต แจแแซแ 'แจแญแฑแแ แชแ' แซแญแต แฅแแ แจแฐแปแปแ แจแแแ แ แแแแแต แ แชแ แณแญแฌแญแต แฅแ แ แดแแฅแญ แจแแต แ แ
แญแงแแข
แชแ แณแญแฌแญแต แจ190 แแแซแต แ แแญ แแแ แซแ แจแแแแฅ แแแแแญ แ แแแแแตแ แ แดแแฅแญ แจแญแฑแแ แซแญแต แแฅแญ แ แแซแแแต แจแแซแแแฅแ แญแแแแข แญแ แ แฒแต แ แแแแแต แจ47.55 แแแฎแ แ แแญ แจแแ แจแดแแฅแญ แฐแ แแแแฝแ แซแแแแแแข แขแตแฎ แดแแฎแ แตแแ แตแซ แฐแญแทแแข
A significant milestone in our Digital Ethiopia journey has been achieved with Ethio telecom, in partnership with Visa Inc., launching the country's first wallet-based Virtual Visa Card and enhanced remittance services via Visa Direct and telebirr Remit.
Visa Direct facilitates easy money transfers to Ethiopia from over 190 countries using a telebirr virtual card number. This partnership supports over 47.55 million telebirr users and advances Ethiopia's digital financial services. Well done to EthioTelecom!
แชแ แณแญแฌแญแต แจ190 แแแซแต แ แแญ แแแ แซแ แจแแแแฅ แแแแแญ แ แแแแแตแ แ แดแแฅแญ แจแญแฑแแ แซแญแต แแฅแญ แ แแซแแแต แจแแซแแแฅแ แญแแแแข แญแ แ แฒแต แ แแแแแต แจ47.55 แแแฎแ แ แแญ แจแแ แจแดแแฅแญ แฐแ แแแแฝแ แซแแแแแแข แขแตแฎ แดแแฎแ แตแแ แตแซ แฐแญแทแแข
A significant milestone in our Digital Ethiopia journey has been achieved with Ethio telecom, in partnership with Visa Inc., launching the country's first wallet-based Virtual Visa Card and enhanced remittance services via Visa Direct and telebirr Remit.
Visa Direct facilitates easy money transfers to Ethiopia from over 190 countries using a telebirr virtual card number. This partnership supports over 47.55 million telebirr users and advances Ethiopia's digital financial services. Well done to EthioTelecom!
๐1
Let's have some fun๐
๐คฃ4
What are Tuples?
Tuple แ python แจobjects แตแฅแตแฅ แฒแแ แฃแแแ แฅแแฐแฐแแญแแ we can't change the order of the items in it.
Objectแฆแน strings, lists, tuples, integers etc. แแแ แญแฝแแแข
แจTuple insertion characteristics preserved แแแฃ once elements แซแตแแแฅแ we can't modify them.
Elements แจtuple แจแแแแแ แแแแชแซ แฃแตแแแฅแแ แต order แแแข
แจlist แจแแแซแธแ แแแญ แขแแญ แญแ แแ แก immutable แแแแธแแข
Tuple duplicate data store แแจแ แญแฝแแ unlike set.
Tuple แฐแแณแณแญแ แแ แจแฐแแซแจ data type store แซแจแแ แฅแแฐ list แแแต แแ
to be cont'd...
#Tuple
@python_pioneers
๐4