def print_vec(x, y, z):
print(f"[{x} \n{y} \n{z}]")
Some Python Utilities
Python Utilities
Function Argument Unpacking
Reference: https://www.youtube.com/watch?v=YWY4BZi_o28
1, 2, 3) print_vec(
[1
2
3]
= (1, 0, 1)
tuple_vec #print_vec(tuple_vec)
0], tuple_vec[1], tuple_vec[2]) print_vec(tuple_vec[
[1
0
1]
= [1, 0, 1]
list_vec
0], tuple_vec[1], tuple_vec[2])
print_vec(tuple_vec[print("*"*20)
*tuple_vec)
print_vec(print("*"*20)
*list_vec) print_vec(
[1
0
1]
********************
[1
0
1]
********************
[1
0
1]
= {"x": 1, "y": 0, "z": 1}
dictionary_vec **dictionary_vec) print_vec(
[1
0
1]
= {"a": 1, "b": 0, "c":1}
dictionary_vec **dictionary_vec) print_vec(
TypeError: print_vec() got an unexpected keyword argument 'a'
print(*dictionary_vec)
a b c
Zip
list(zip([1, 2, 3], ['a', 'b', 'c'], [7, 8, 9]))
[(1, 'a', 7), (2, 'b', 8), (3, 'c', 9)]
Itertools Product
import itertools
list(itertools.product([1, 2], ['a', 'b', 'c'], [7, 8, 9]))
[(1, 'a', 7),
(1, 'a', 8),
(1, 'a', 9),
(1, 'b', 7),
(1, 'b', 8),
(1, 'b', 9),
(1, 'c', 7),
(1, 'c', 8),
(1, 'c', 9),
(2, 'a', 7),
(2, 'a', 8),
(2, 'a', 9),
(2, 'b', 7),
(2, 'b', 8),
(2, 'b', 9),
(2, 'c', 7),
(2, 'c', 8),
(2, 'c', 9)]