Skip to content

Commit 543a95c

Browse files
committed
second version list
1 parent 180c546 commit 543a95c

File tree

4 files changed

+41
-64
lines changed

4 files changed

+41
-64
lines changed

02_Day_Variables_builtin_functions/02_variables_builtin_functions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
## Built in functions
3535

36-
In Python we have lots of built-in functions. Built-in functions are globally available for your use that mean you can make use of the built-in functions without importing or configuring. Some of the most commonly used Python built-in functions are the following: _print()_, _len()_, _type()_, _int()_, _float()_, _str()_, _input()_, _list()_, _dict()_, _min()_, _max()_, _sum()_, _sorted()_, _open()_, _file()_, _help()_, and _dir()_. In the following table you will see an exhaustive list of Python built-in functions taken from [python documentation](https://docs.python.org/2/library/functions.html).
36+
In Python we have lots of built-in functions. Built-in functions are globally available for your use that mean you can make use of the built-in functions without importing or configuring. Some of the most commonly used Python built-in functions are the following: _print()_, _len()_, _type()_, _int()_, _float()_, _str()_, _input()_, _list()_, _dict()_, _min()_, _max()_, _sum()_, _sorted()_, _open()_, _file()_, _help()_, and _dir()_. In the following table you will see an exhaustive list of Python built-in functions taken from [python documentation](https://docs.python.org/3.9/library/functions.html).
3737

3838
![Built-in Functions](../images/builtin-functions.png)
3939

04_Day_Strings/04_strings.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ print(challenge.find('th')) # 0
336336

337337
```py
338338
challenge = 'thirty days of python'
339-
print(challenge.find('y')) # 5
340-
print(challenge.find('th')) # 1
339+
print(challenge.rfind('y')) # 5
340+
print(challenge.rfind('th')) # 1
341341
```
342342

343343
- format(): formats string into a nicer output
@@ -414,7 +414,7 @@ print(challenge.isdecimal()) # True
414414
challenge = '\u00B2'
415415
print(challenge.isdigit()) # False
416416
challenge = '12 3'
417-
print(challenge.isdecimal()) # False, no space allowed
417+
print(challenge.isdecimal()) # False, space not allowed
418418
```
419419

420420
- isdigit(): Checks if all characters in a string are numbers (0-9 and some other unicode characters for numbers)

05_Day_Lists/05_lists.md

+37-60
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
<sub>Author:
1111
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
12-
<small> First Edition: Nov 22 - Dec 22, 2019</small>
12+
<small> Second Edition: July - 2021</small>
1313
</sub>
1414

15-
</div>
1615
</div>
1716

1817
[<< Day 4](../04_Day_Strings/04_strings.md) | [Day 6 >>](../06_Day_Tuples/06_tuples.md)
@@ -48,18 +47,18 @@
4847

4948
## Lists
5049

51-
There are four collection data types in python :
50+
There are four collection data types in Python :
5251

5352
- List: is a collection which is ordered and changeable(modifiable). Allows duplicate members.
5453
- Tuple: is a collection which is ordered and unchangeable or unmodifiable(immutable). Allows duplicate members.
55-
- Set: is a collection which is unordered, unindexed and unmodifiable, but you can add new items. No duplicate members.
54+
- Set: is a collection which is unordered, un-indexed and unmodifiable, but we can add new items to the set. Duplicate members are not allowed.
5655
- Dictionary: is a collection which is unordered, changeable(modifiable) and indexed. No duplicate members.
5756

58-
A list is collection of different data types which is ordered and modifiable(mutable). A list can be empty or it may have different data type items or items
57+
A list is collection of different data types which is ordered and modifiable(mutable). A list can be empty or it may have different data type items.
5958

6059
### How to Create a List
6160

62-
In python we can create lists in two ways:
61+
In Python we can create lists in two ways:
6362

6463
- Using list built-in function
6564

@@ -218,9 +217,9 @@ orange_and_lemon = fruits[::2] # here we used a 3rd argument, step. It will take
218217
```py
219218
fruits = ['banana', 'orange', 'mango', 'lemon']
220219
all_fruits = fruits[-4:] # it returns all the fruits
221-
orange_and_mango = fruits[-3:-1] # it does not include the last index
222-
orange_mango_lemon = fruits[-3:] # this will give the same result as the one above
223-
reverse_fruits = fruits[::-1] # a negative step will take the list in reverse order
220+
orange_and_mango = fruits[-3:-1] # it does not include the last index,['orange', 'mango']
221+
orange_mango_lemon = fruits[-3:] # this will give starting from -3 to the end,['orange', 'mango', 'lemon']
222+
reverse_fruits = fruits[::-1] # a negative step will take the list in reverse order,['lemon', 'mango', 'orange', 'banana']
224223
```
225224

226225
### Modifying Lists
@@ -240,6 +239,8 @@ print(fruits) # ['avocado', 'apple', 'mango', 'lime']
240239

241240
### Checking Items in a List
242241

242+
Checking an item if it is a member of a list using *in* operator. See the example below.
243+
243244
```py
244245
fruits = ['banana', 'orange', 'mango', 'lemon']
245246
does_exist = 'banana' in fruits
@@ -250,7 +251,7 @@ print(does_exist) # False
250251

251252
### Adding Items to a List
252253

253-
To add item to the end of an existing list we use the method
254+
To add item to the end of an existing list we use the method *append()*.
254255

255256
```py
256257
# syntax
@@ -268,7 +269,7 @@ print(fruits)
268269

269270
### Inserting Items into a List
270271

271-
Use insert() method to insert a single item at a specified index in a list. Note that other items are shifted to the right.
272+
We can use *insert()* method to insert a single item at a specified index in a list. Note that other items are shifted to the right. The *insert()* methods takes two arguments:index and an item to insert.
272273

273274
```py
274275
# syntax
@@ -297,14 +298,14 @@ lst.remove(item)
297298
```py
298299
fruits = ['banana', 'orange', 'mango', 'lemon', 'banana']
299300
fruits.remove('banana')
300-
print(fruits) # ['orange', 'mango', 'lemon', 'banana'] - this method removes the first occurence of the item in the list
301+
print(fruits) # ['orange', 'mango', 'lemon', 'banana'] - this method removes the first occurrence of the item in the list
301302
fruits.remove('lemon')
302303
print(fruits) # ['orange', 'mango', 'banana']
303304
```
304305

305306
### Removing Items Using Pop
306307

307-
The pop() method removes the specified index, (or the last item if index is not specified):
308+
The *pop()* method removes the specified index, (or the last item if index is not specified):
308309

309310
```py
310311
# syntax
@@ -324,7 +325,7 @@ print(fruits) # ['orange', 'mango']
324325

325326
### Removing Items Using Del
326327

327-
The del keyword removes the specified index and it can also be used to delete items within index range. It can also delete the list completely
328+
The *del* keyword removes the specified index and it can also be used to delete items within index range. It can also delete the list completely
328329

329330
```py
330331
# syntax
@@ -347,7 +348,7 @@ print(fruits) # This should give: NameError: name 'fruits' is not defined
347348

348349
### Clearing List Items
349350

350-
The clear() method empties the list:
351+
The *clear()* method empties the list:
351352

352353
```py
353354
# syntax
@@ -363,7 +364,7 @@ print(fruits) # []
363364

364365
### Copying a List
365366

366-
It is possible to copy a list by reassigning it to a new variable in the following way: list2 = list1. Now, list2 is a reference of list1, any changes we make in list2 will also modify the original, list2. But there are lots of case in which we do not like to modify the original instead we like to have a different copy. One of way avoid the problem above is using _copy()_.
367+
It is possible to copy a list by reassigning it to a new variable in the following way: list2 = list1. Now, list2 is a reference of list1, any changes we make in list2 will also modify the original, list2. But there are lots of case in which we do not like to modify the original instead we like to have a different copy. One of way of avoiding the problem above is using _copy()_.
367368

368369
```py
369370
# syntax
@@ -393,21 +394,15 @@ positive_numbers = [1, 2, 3, 4, 5]
393394
zero = [0]
394395
negative_numbers = [-5,-4,-3,-2,-1]
395396
integers = negative_numbers + zero + positive_numbers
396-
print(integers)
397+
print(integers) # [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
397398
fruits = ['banana', 'orange', 'mango', 'lemon']
398399
vegetables = ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot']
399400
fruits_and_vegetables = fruits + vegetables
400-
print(fruits_and_vegetables )
401-
402-
```
403-
404-
```py
405-
# output
406-
[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
407-
['banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot']
401+
print(fruits_and_vegetables ) # ['banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot']
408402
```
409403

410404
- Joining using extend() method
405+
The *extend()* method allows to append list in a list. See the example below.
411406

412407
```py
413408
# syntax
@@ -418,32 +413,25 @@ list1.extend(list2)
418413

419414
```py
420415
num1 = [0, 1, 2, 3]
421-
num2= [4, 5,6]
416+
num2= [4, 5, 6]
422417
num1.extend(num2)
423-
print('Numbers:', num1)
418+
print('Numbers:', num1) # Numbers: [0, 1, 2, 3, 4, 5, 6]
424419
negative_numbers = [-5,-4,-3,-2,-1]
425420
positive_numbers = [1, 2, 3,4,5]
426421
zero = [0]
427422

428423
negative_numbers.extend(zero)
429424
negative_numbers.extend(positive_numbers)
430-
print('Integers:', negative_numbers)
425+
print('Integers:', negative_numbers) # Integers: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
431426
fruits = ['banana', 'orange', 'mango', 'lemon']
432427
vegetables = ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot']
433428
fruits.extend(vegetables)
434-
print('Fruits and vegetables:', fruits )
435-
436-
```
437-
438-
```py
439-
Numbers: [0, 1, 2, 3, 4, 5, 6]
440-
Integers: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
441-
Fruits and vegetables: ['banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot']
429+
print('Fruits and vegetables:', fruits ) # Fruits and vegetables: ['banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot']
442430
```
443431

444432
### Counting Items in a List
445433

446-
The count() method returns the number of times an item appears in a list:
434+
The *count()* method returns the number of times an item appears in a list:
447435

448436
```py
449437
# syntax
@@ -460,7 +448,7 @@ print(ages.count(24)) # 3
460448

461449
### Finding Index of an Item
462450

463-
The index() method returns the index of an item in the list:
451+
The *index()* method returns the index of an item in the list:
464452

465453
```py
466454
# syntax
@@ -477,7 +465,7 @@ print(ages.index(24)) # 2, the first occurrence
477465

478466
### Reversing a List
479467

480-
The reverse() method reverses the order of a list.
468+
The *reverse()* method reverses the order of a list.
481469

482470
```py
483471
# syntax
@@ -489,15 +477,10 @@ lst.reverse()
489477
```py
490478
fruits = ['banana', 'orange', 'mango', 'lemon']
491479
fruits.reverse()
492-
print(fruits.reverse())
480+
print(fruits.reverse()) # ['lemon', 'mango', 'orange', 'banana']
493481
ages = [22, 19, 24, 25, 26, 24, 25, 24]
494482
ages.reverse()
495-
print(ages.reverse())
496-
```
497-
498-
```py
499-
['lemon', 'mango', 'orange', 'banana']
500-
[24, 25, 24, 26, 25, 24, 19, 22]
483+
print(ages.reverse()) # [24, 25, 24, 26, 25, 24, 19, 22]
501484
```
502485

503486
### Sorting List Items
@@ -518,36 +501,30 @@ To sort lists we can use _sort()_ method or _sorted()_ built-in functions. The _
518501
```py
519502
fruits = ['banana', 'orange', 'mango', 'lemon']
520503
fruits.sort()
521-
print(fruits) # sorted in alphabetical order
504+
print(fruits) # sorted in alphabetical order, ['banana', 'lemon', 'mango', 'orange']
522505
fruits.sort(reverse=True)
523-
print(fruits)
506+
print(fruits) # ['orange', 'mango', 'lemon', 'banana']
524507
ages = [22, 19, 24, 25, 26, 24, 25, 24]
525508
ages.sort()
526-
print(ages)
509+
print(ages) # [19, 22, 24, 24, 24, 25, 25, 26]
510+
527511
ages.sort(reverse=True)
528-
print(ages)
529-
```
530-
531-
```sh
532-
['banana', 'lemon', 'mango', 'orange']
533-
['orange', 'mango', 'lemon', 'banana']
534-
[19, 22, 24, 24, 24, 25, 25, 26]
535-
[26, 25, 25, 24, 24, 24, 22, 19]
512+
print(ages) # [26, 25, 25, 24, 24, 24, 22, 19]
536513
```
537514

538-
sorted(): returns the ordered list without modifying the original
515+
sorted(): returns the ordered list without modifying the original list
539516
**Example:**
540517

541518
```py
542519
fruits = ['banana', 'orange', 'mango', 'lemon']
543-
print(sorted(fruits)) # ['banana', 'lemon', 'mango', 'orange']
520+
print(sorted(fruits)) # ['banana', 'lemon', 'mango', 'orange']
544521
# Reverse order
545522
fruits = ['banana', 'orange', 'mango', 'lemon']
546523
fruits = sorted(fruits,reverse=True)
547524
print(fruits) # ['orange', 'mango', 'lemon', 'banana']
548525
```
549526

550-
🌕 You are diligent and you have already achieved quite a lot. You have just completed day 5 challenges and you are 5 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
527+
🌕 You are diligent and you have already achieved quite a lot. You have just completed day 5 challenges and you are 5 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.
551528

552529
## 💻 Exercises: Day 5
553530

images/builtin-functions.png

-16.7 KB
Loading

0 commit comments

Comments
 (0)