<jupyter_start><jupyter_text>Generators<jupyter_code>numbers = range(5)
# This function will return different value 
# three times
# you call the function with next()
def simple_generator():
    yield 1
    yield 2
    yield 3
# Assign the generator to mg object
mg = simple_generator()
# next(mg) will give you the next value yielded by the function
next(mg)
next(mg)
next(mg)
next(mg)
# Generator function
# to generate fibonacci numbers
def next_fibonacci_number():
    yield 0
    yield 1
    first = 0
    second = 1
    while True:
        third = first + second
        first = second
        second = third
        yield third
mf = next_fibonacci_number()
next(mf)
next(mf)
print(next(mf), next(mf), next(mf), next(mf), next(mf))
def dont_write_such_a_function():
    print("Hello")
    return 5
    print ("I still want to do a lot with my life")
x = dont_write_such_a_function()
print(x)<jupyter_output>Hello
5<jupyter_text>Function with variable number of arguments<jupyter_code># print() function takes variable number of arguments
# nums is a number
# kwargs is a dictionary
def average(*nums, **kwargs): # passed in a list
    sum = 0
    for n in nums: # n will have values from the list nums
        sum += n
    return sum / kwargs['divide']


# # passing two positional params
# and one keyword parameter
average(3,4, divide=10) 
average(1,2,3,4,5)
average(1,2,3,4,5,6,7,8,9,10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09887798036465638, 'fraction_numerical': 0.021739130434782608, 'mean_word_length': 3.9377162629757785, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '665332', 'license': 'Apache-2.0', 'n_tokens_mistral': 492, 'n_tokens_neox': 471, 'n_words': 161, 'path': 'Lecture-Notes/2018/Day5.ipynb', 'repo_name': 'unmeshvrije/python-for-beginners', 'size': '1426'}