ba7875658af6e20ef67ace0e80572848 python lab5 v3 rasb14 2018-10-07 10:08:40 v3.1.3 (2018-09-13)
Generated 2018-10-07 12:08:40 by dbwebb lab-utility v3.1.3 (2018-09-13).
“In these exercises we will take a look into lists.”
Concatenate the two lists [Berenger, tiger] and [wasp, wall].
Answer with your list.
Use the list [lion, tiger, ozelot, bobcat, cougar].
Add the words ‘elevator’ and ‘pirate’ as the second and third element.
Answer with the modified list.
Use the list [lion, tiger, ozelot, bobcat, cougar].
Replace the third word with: ‘tablet’.
Answer with the modified list.
Sort the list
[Dafoe, Sheen, Berenger, Depp, Whitaker]
in descending alphabetical order. Answer with the sorted list.
Use remove() to delete the word:
‘chair’
from the list:
[table, wall, desk, chair, floor]
Answer with the modified list.
Some basic built-in functions.
Use a built-in function to sum all numbers in the list:
[67, 50, 2, 39, 15]
Answer with the result as an integer.
Use built-in functions, such as sum and len to get the average value of the list:
[98, 5, 12, 369, 1]
Answer with the result as a float with at most one decimal.
Use the built-in functions split() and join() to fix this string:
“The?sun?is?shining”
into a real sentence, (without ‘?’).
Answer with the fixed string.
Use slice on the list
[tree, stone, grass, water, sky]
and replace the second and third element with
“freezer, fridge”
Answer with the modified list.
Assign the list
[d, c, b, a, e]
to a variable called ‘list1’.
Assign the list again, but to another variable called ‘list2’.
Answer with the result of ‘list1 is list2’.
Use your lists from the last exercise. Assign ‘list1’ to another variable called ‘list3’ like this:
list3 = list1
Answer with the result of ‘list1 is list3’.
Use your lists from the last exercise. Change the first element in ‘list1’ to
“p”
Answer with ‘list3’.
These questions are worth 3 points each. Solve them for extra points.
Create a function that returns the list passed as argument sorted in numerical and ascending order. Also multiply all values with 10.
Use the list:
[123, 4, 125, 69, 155]
and the built-in method sort().
Answer with the sorted list.
Create a function that takes the list:
[98, 5, 12, 369, 1]
as argument.
The function should multiply all even numbers by 2 and add 6 to all odd numbers.
Answer with the modified list sorted in numerical order, descending.
ba7875658af6e20ef67ace0e80572848