# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.8.8 64-bit (''base'': conda)'
#     name: python3
# ---

def my_function(x,y,z=1.5):
    if z > 1:
        return z * ( x + y )
    else:
        return z / ( x + y )


my_function(5,6,z=0.)

my_function(3.14,7,z=3.5)


def f():
    a = 5
    b = 6
    c = 7
    return a , b , c


a,b,c = f()
print(a)
print(b)
print(c)


import re 
def clean_strings(strings):
    result = []
    for value in strings:
        value = value.strip()
        value = re.sub(r'[!#?]', '', value)
        value = value.title()
        result.append(value)
    return result


states = [' Alabama ', 'Georgia!', 'Georgia', 'georgia', 'FlOrIda', 'south carolina##', 'West virginia?']

clean_strings(states)


# +
def remove_punctuation(value):
    return re.sub(r'[!#?]', '', value)

clean_ops = [str.strip,remove_punctuation,  str.title]

def clean_strings1(strings, ops):
    result = []
    for value in strings:
        for func in ops:
            value = func(value)
        result.append(value)
    return result


# -

clean_strings1(states, clean_ops)

some_dict = {'a':1,'b':2,'c':3}
for key in some_dict:
    print(key)


def squares(n = 10):
    print("Generating squares from 1 to {0}".format(n**2))
    for i in range(1,n+1):
        yield i**2


gen = squares()
gen

list(gen)

gen = (x ** 2 for x in range(100))
gen

list(gen)

# ### itertools

import itertools
first_letter = lambda x: x[0]
names = ['Alan', 'Adam', 'Wes', 'Will', 'Albert','Steven']
for letter , names  in itertools.groupby(names, first_letter):
    print(letter, list(names))  # letter is the first letter of each name

StarcoderdataJupyterScriptsDedupFiltered