December, 2021 - François HU
Master of Science - EPITA
This lecture is available here: https://curiousml.github.io/
These exercices are considered "normal-hard" exercices.
Create a function insert
, that produces the following results:
>>> l = [0, 9, 3, 10]
>>> print(insert(l, -1, 1))
[0, -1, 9, 3, 10]
>>> print(insert(l, -1, 2))
[0, 9, -1, 3, 10]
>>> print(insert(l, "epita", 4))
[0, 9, 3, 10, 'epita']
>>> print(insert(l, "epita", 10))
[0, 9, 3, 10, 'epita']
>>> print(l)
[0, 9, 3, 10]
we have the following list of dictionaries
paris = [{"District": 3, "Date":2007, "Pop":34576},
{"District": 5, "Date":2007, "Pop":62664},
{"District": 6, "Date":2007, "Pop":45332},
{"District": 7, "Date":2007, "Pop":57410},
{"District": 8, "Date":2007, "Pop":39165},
{"District": 9, "Date":2007, "Pop":58632},
{"District": 10, "Date":2007, "Pop":93373},
{"District": 11, "Date":2007, "Pop":151421},
{"District": 12, "Date":2007, "Pop":142425},
{"District": 13, "Date":2007, "Pop":179213},
{"District": 14, "Date":2007, "Pop":134382},
{"District": 15, "Date":2007, "Pop":232247},
{"District": 16, "Date":2007, "Pop":159706},
{"District": 17, "Date":2007, "Pop":164673},
{"District": 18, "Date":2007, "Pop":191523},
{"District": 19, "Date":2007, "Pop":184038},
{"District": 20, "Date":2007, "Pop":194018}]
Rounded_pop
which discard the last 3 digits. For example we transform the value 34576
to 34
Rounded_pop
into a list named populations
populations
we have the following list of strings
list_of_strings = [
'EPITA', 'propose', 'trois', 'programmes',
'spécialisés', 'Master', 'of', 'Science',
'dans', 'un', 'environnement', 'international.',
'Cette', 'formation', 'professionnalisante', 'de',
'18', 'mois', 'intégralement', 'en', 'anglais',
'pour','les','étudiants','français', 'et', 'internationaux,',
'permet', 'de', 'se', 'spécialiser', 'dans', 'un',
'domaine', 'après', '3', 'ou', '4', 'ans', 'd’études.']
Write a script that create a variable named text
which concatenante the items of list_of_strings
with exactly one space between words.
arr1
:[[ 0 25 100 225 400]
[ 1 36 121 256 441]
[ 4 49 144 289 484]
[ 9 64 169 324 529]
[ 16 81 196 361 576]]
arr1
(do not generate it) and call it diag1
[ 0, 36, 144, 324, 576]
arr1
, extract the submatrix:[[225 100 25]
[289 144 49]
[256 121 36]]
and name it subarr1
.
arr2
:[[10 9 8 7 6]
[ 9 8 7 6 5]
[ 8 7 6 5 4]
[ 7 6 5 4 3]
[ 6 5 4 3 2]]
arr2
by 0
without explicit loops. You should have:
[[0 9 0 7 0]
[9 0 7 0 5]
[0 7 0 5 0]
[7 0 5 0 3]
[0 5 0 3 0]]
orange
. You should have:
Iris
and defra_consumption
datasets as dataframes and name them respectively iris
and cons
. You should have the following first 5 rows for each dataframe: