List Methods in Python: Copy, Index, Sort, Reverse - Part 2 Series A

Опубликовано: 29 Сентябрь 2024
на канале: Doug Morrow
11
0

This is the second of three videos where I go over the basics of how to work with lists in Python. I am not an expert when it comes to Python, but I know that teaching a subject helps solidify the information we learn about.

This is Series A

Series A = 1
Series B = 2

Each series is intended to be better than the last because of all the practice I'll get in creating them.

✔ Other Places to Connect:
My Website: https://dougm.io/

✔ Support Through Patreon:
https://www.patreon.com/user?u=322207...

✔Learn More about Lists at - w3schools - or search 'Python "in" Keyword'
https://www.w3schools.com/python/pyth...

✔Additional Practice Questions
https://github.com/MorrowG2/YouTube_P...

✔Practice Questions
https://github.com/MorrowG2/YouTube_P...

List Methods Part 2

my_list = ['z', 'f', 'a', 'b', 'c']

print(my_list.index('z', 0, 5))
my_list.sort()
print(my_list.reverse())
print(my_list)

.index()
in
.count()
.sort()
New array
sorted()
.copy() and [:]
.reverse()

Add the below items to a new list
example: new_list = []
0. use .append() to add the items below to a new_list, cool_list or whatever list you want to create
1. add the following to a list --- 'bananas', 'pineapple', 'tomato', 'tortilla', 'beans', 'guac'
2. add the following to a different list ---- False, True, 123, 'bloop'
3. add the following to a different list ---- '?', "(*-*)", '(^_^)', "('')_(^_^)_('')",
4. add the following to a different list ---- 'blue', 'yellow', 'green', 123, True
-------------------------------------------------------------------------------------------------------------------
5. locate the following items at their proper index position (use: (object, start, stop)) ---- 'bananas', 'pineapple', 'tomato', 'tortilla', 'beans', 'guac'
6. locate the following items at their proper index position (use: (object, start, stop)) ----- False, True, 123, 'bloop'
7. locate the following items at their proper index position (use: (object, start, stop)) ----- '?', "(*-*)", '(^_^)', "('')_(^_^)_('')",
-------------------------------------------------------------------------------------------------------------------
8. Can you locate if the following items are IN the proper list?
'bananas', 'pineapple', 'tomato', 'tortilla', 'beans', 'guac', 'blue', 'yellow', 'green', 123, True, False, True, 123, 'bloop'
-------------------------------------------------------------------------------------------------------------------
9. What is the number of occurances of the following items in each list? (How would you count them?)
'bananas', 'pineapple', 'tomato', 'tortilla', 'beans', 'guac', 'blue', 'yellow', 'green', 123, True, False, True, 123, 'bloop'
-------------------------------------------------------------------------------------------------------------------
10. What's the difference between .sort() and sorted()
Which sort is permanent? Which sort is temporary? Which sort returns a NONE value?
-------------------------------------------------------------------------------------------------------------------
11. How can you use a copy of a list with .sort()?
12. How can you copy a list and then sort it in reverse order?