Python - intermediate
enumerate in python - write a function
Ans at 1 min
What is a decorator? What is it used for?
Decorators add a wrapper around your function to not change the original function. You pass the wrapper the function. A few good examples are when you want to add logging, test performance, perform caching, verify permissions, and so on. You can also use one when you need to run the same code on multiple functions.
What are the key attributes of a dictionary
Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is ordered*, changeable and do not allow duplicates.
What's a lambda function in python? What's it used for?
If you're only returning one thing, can use a lambda function instead to not have to write a whole separate function (saves room) lambda x: x + 5, for example
Write a map function in python. map through lst = [1...10] and add 3 to each number in the list. What is it used for?
Map is used in place of a for loop. You can iterate over a list and apply a function, https://realpython.com./python-map-function/
What does reduce allow you to do? Use reduce on list = [1...10]
See 8 mins here https://www.youtube.com/watch?v=K83L3PapeFk&ab_channel=PrettyPrinted
can tuples have duplicate values?
Yes. thistuple = ("apple", "banana", "cherry", "apple", "cherry")
txt = "We are the so-called "Vikings" from the north." Write this as a string in python
You need to use escape characters so: \"Vikings\" to get it to work
add lemon to 2nd index of fruits = ["apple", "banana", "cherry"]
fruits.insert(1, "lemon")
b = "Hello, World!" Get the characters from position 2, and all the way to the end get "orl" forwards and backwards in python
https://www.w3schools.com/python/trypython.asp?filename=demo_string2
filter the list [1 - 10] to include only odds in python
https://www.youtube.com/watch?v=09XRMXcCofM&ab_channel=TechWithTim
Get the characters from index 2 to index 4 (llo).
txt[2:5]