<jupyter_start><jupyter_text>Understanding the asterisk (*) ([reference](https://medium.com/understand-the-python/understanding-the-asterisk-of-python-8b9daaa4a558))  1. Multiplication & power<jupyter_code>print(f"2 * 3 = {2 * 3}")
print(f"2 ** 3 = {2 ** 3}")<jupyter_output>2 * 3 = 6
2 ** 3 = 8<jupyter_text>2. Repeatedly extending list-type containers<jupyter_code>zeros_list = [0] * 10
print(f"list:\n{zeros_list}")

ones_tuple = (1,) * 10
print(f"\ntuple:\n{ones_tuple}")

vector_list = [[1, 2, 3]] * 3
print(f"\nvector list:\n{vector_list}")

import numpy as np
np_array = np.array([[1, 2, 3]]) * 3
print(f"\nDoes not work with numpy array:\n{np_array}")<jupyter_output>list:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

tuple:
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

vector list:
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]

Does not work with numpy array:
[[3 6 9]]<jupyter_text>3. Variadic arguments (* & **)  Positional arguments (*args)packing into **tuple**<jupyter_code>def save_ranking(*args):
    print(args) 
    
save_ranking('ming', 'alice', 'tom', 'wilson', 'roy')<jupyter_output>('ming', 'alice', 'tom', 'wilson', 'roy')<jupyter_text>Keyword arguments (**kwargs)packing into **dict**<jupyter_code>def save_ranking(**kwargs):
    print(kwargs)
    
save_ranking(first='ming', second='alice', fourth='wilson', \
             third='tom', fifth='roy')<jupyter_output>{'first': 'ming', 'second': 'alice', 'fourth': 'wilson', 'third': 'tom', 'fifth': 'roy'}<jupyter_text>Mixing positional and keyword arguments (*args, **kwargs)<jupyter_code>def save_ranking(*args, **kwargs):
    print(args)     
    print(kwargs)
    
save_ranking('ming', 'alice', 'tom', fourth='wilson', fifth='roy')<jupyter_output>('ming', 'alice', 'tom')
{'fourth': 'wilson', 'fifth': 'roy'}<jupyter_text>Unpacking containers (tuple, list, dict)  Into functions<jupyter_code>from functools import reduce

primes = [2, 3, 5, 7, 11, 13]
print(f"\nprimes:\n{primes}")
print("\n*primes:")
print(*primes)

def product(*numbers):
    p = reduce(lambda x, y: x * y, numbers)
    return p 

print(f"\nproduct(*primes):\n{product(*primes)}")

print(f"\nproduct(primes):\n{product(primes)}")

print(f"\nproduct(1,2,3):\n{product(1,2,3)}")<jupyter_output>primes:
[2, 3, 5, 7, 11, 13]

*primes:
2 3 5 7 11 13

product(*primes):
30030

product(primes):
[2, 3, 5, 7, 11, 13]

product(1,2,3):
6<jupyter_text>Into other variables<jupyter_code>numbers = [1, 2, 3, 4, 5, 6]

*a, = numbers
print("*a, = numbers:\n",a)

*a, b = numbers
print("\n*a, b = numbers:\n",a , b)

a, *b, = numbers
print("\na, *b, = numbers:\n",a , b)

a, *b, c = numbers
print("\na, *b, c = numbers:\n",a , b, c)<jupyter_output>*a, = numbers:
 [1, 2, 3, 4, 5, 6]

*a, b = numbers:
 [1, 2, 3, 4, 5] 6

a, *b, = numbers:
 1 [2, 3, 4, 5, 6]

a, *b, c = numbers:
 1 [2, 3, 4, 5] 6<jupyter_text>List literals<jupyter_code>def rotate_first_item(sequence):
    return [*sequence[1:], sequence[0]]

print(rotate_first_item([0,1,2,3]))<jupyter_output>[1, 2, 3, 0]<jupyter_text>Dictionary literals<jupyter_code>date_info = {'year': "2020", 'month': "01", 'day': "01"}
track_info = {'artist': "Beethoven", 'title': 'Symphony No 5'}
all_info = {**date_info, **track_info}
print(all_info)<jupyter_output>{'year': '2020', 'month': '01', 'day': '01', 'artist': 'Beethoven', 'title': 'Symphony No 5'}
{'fraction_non_alphanumeric': 0.2196601941747573, 'fraction_numerical': 0.05279126213592233, 'mean_word_length': 5.620481927710843, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '282934', 'license': 'MIT', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1390, 'n_words': 318, 'path': 'understanding_the_asterisk.ipynb', 'repo_name': 'thomsan/python', 'size': '3296'}