In this project, I learned about sets and dictionaries in Python. I practiced using them
with the lambda
, map
, filter
, and reduce
methods.
-
0. Squared simple
- 0-square_matrix_simple.py: Python function that computes the square value of all integers of a matrix.
- The parameter
matrix
is a two-dimensional array. - Returns a matrix of the same size as
matrix
where each value is the square of the input value. - The initial matrix is not modified.
- Without importing modules.
-
1. Search and replace
- 1-search_replace.py: Python function that replaces all occurences of an element by another in a new list.
- The parameter
my_list
is the initial list. - The parameter
search
is the element to replace in the list. - The parameter
replace
is the new element. - Without importing modules.
-
2. Unique addition
- 2-uniq_add.py: Python function that adds all unique integers in a list (once for each integer).
- Without importing modules.
-
3. Present in both
- 3-common_elements.py: Python function that returns a set of common elements in two sets.
- Without importing modules.
-
4. Only differents
- 4-only_diff_elements.py: Python function that returns a set of all elements present in only one set.
- Without importing modules.
-
5. Number of keys
- 5-number_keys.py: Python function that returns the number of keys in a dictionary.
- Without importing modules.
-
6. Print sorted dictionary
- 6-print_sorted_dictionary.py: Python function that prints a dictionary by ordered keys.
- The function assumes all keys are strings.
- Keys are printed in alphabetic order.
- Keys are only sorted on the first level.
- Dictionary values can have any type.
- Without importing modules.
-
7. Update dictionary
- 7-update_dictionary.py: Python function that replaces or adds key/value pairs in a dictionary.
- The parameter
key
is always a string. - The parameter
value
is any type. - If a key exists in the dictionary, the value is replaced.
- If a key does not exist in the dictionary, it is created.
- Without importing modules.
-
8. Simple delete by key
- 8-simple_delete.py: Python function that deletes a key in a dictionary.
- The paramter
key
is always a string. - If the key does not exist, the dictionary does not change.
- Without importing modules.
-
9. Multiply by 2
- 9-multiply_by_2.py: Python function that returns a new dictionary with all values multiplied by 2.
- The function assumes all values are integers.
- Without importing modules.
-
10. Best score
- 10-best_score.py: Python function that returns a key value with the biggest integer value.
- The function assumes all values are integers.
- The function assumes all students have a different score.
- If no score is found, the functino returns
None
. - Without importing modules.
-
11. Multiply by using map
- 11-multiply_list_map.py: Python function that returns a
list with all values multiplied by a number using
map
. - Returns a new list of the same length as
my_list
with each value multiplied bynumber
. - The initial list is not modified.
- Without using loops or importing modules.
- 11-multiply_list_map.py: Python function that returns a
list with all values multiplied by a number using
-
12. Roman to Integer
- 12-roman_to_int.py: Python function that converts a roman numeral to an integer.
- The function assumes the number will be between 1-3999.
- If the parameter
roman_string
is not a string orNone
, the function returns0
.
-
13. Weighted average!
- 100-weight_average.py: Python function that returns the weighted average of all integers in a list of tuples.
- Tuple format:
(<score>, <weight>)
. - If the list is empty - returns
0
. - Without importing modules.