Colab

cheeses = ["adam", "bree", "cheDDar", "GOUDA", "camambert"]
# change the names to Title case

for i in range(len(cheeses)):
    cheeses[i] = cheeses[i].title()

print(cheeses)

['Adam', 'Bree', 'Cheddar', 'Gouda', 'Camambert']
i=0
for cheese in cheeses:
    cheeses[i]= cheese.title()
    i+=1
    
print(cheeses)

['Adam', 'Bree', 'Cheddar', 'Gouda', 'Camambert']
for i, cheese in enumerate(cheeses):
    cheeses[i] = cheese.title()
    
print(cheeses)

['Adam', 'Bree', 'Cheddar', 'Gouda', 'Camambert']
list(enumerate(cheeses))

[(0, 'Adam'), (1, 'Bree'), (2, 'Cheddar'), (3, 'Gouda'), (4, 'Camambert')]
x= [1,2,3]
a=x[0]
b=x[1]
c=x[2]
print(a,b,c)

# unpacking
aa, bb, cc= x
print(aa, bb, cc)

1 2 3
1 2 3
# unpacking doesnt work with unbalanced left and right hand sides of '='
aa, bb, cc = [1,2,3,4]


    ---------------------------------------------------------------------------

    ValueError                                Traceback (most recent call last)

    <ipython-input-11-8b65758a2680> in <module>
          1 # unpacking doesnt work with unbalanced left and right hand sides of '='
    ----> 2 aa, bb, cc = [1,2,3,4]
    

    ValueError: too many values to unpack (expected 3)


x = 10
y = 100

# classic swap
z = x
x = y
y = z

# swap using unpacking
x,y = [y,x] # list
x,y = (y,x) # tuple
x,y =  y,x  # tuple
print(x,y)

10 100
(2+3)*4

20
print( (10, 20, 30) )
print( (10, 20) )
print( (10, ) )
x= 10,  
print(x)

(10, 20, 30)
(10, 20)
(10,)
(10,)
csv = """\
name, family, age, country
moshe, cohen, 20, israel
david, lev, 30, france
"""
lines= csv.splitlines()
print(lines)
header, *content = lines
#header, content= lines[0], lines[1:]
print(header)
print(content)
mosheline = content[0].split()
print(mosheline)
name, *eveything, country = mosheline
print(name, country, eveything)

['name, family, age, country', 'moshe, cohen, 20, israel', 'david, lev, 30, france']
name, family, age, country
['moshe, cohen, 20, israel', 'david, lev, 30, france']
['moshe,', 'cohen,', '20,', 'israel']
moshe, israel ['cohen,', '20,']