Colab

cheeses = ["adam", "bree", "camambert", "gouda", "grouyer"]

entitled_cheeses = []
i=0
while i<len(cheeses):
    entitled_cheeses.append(cheeses[i].title())
    i+=1
print(entitled_cheeses)

['Adam', 'Bree', 'Camambert', 'Gouda', 'Grouyer']
entitled_cheeses = []
for cheese  in cheeses:
    entitled_cheeses.append(cheese.title())
print(entitled_cheeses)

['Adam', 'Bree', 'Camambert', 'Gouda', 'Grouyer']
[cheese.title() for cheese in cheeses]

['Adam', 'Bree', 'Camambert', 'Gouda', 'Grouyer']
[2**pow  for pow in range(16)]

[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]
[len(cheese) for cheese in cheeses]

[4, 4, 9, 5, 7]
cheese_prices = {
    'Adam' : 2,
    'Bree' : 3,
    'Camambert' : 4,
    'Gouda' : 5
}

missing = { 'Adam' }

buy = ['Adam', 'Bree']
# buy_prices = [ cheese_prices[item]   for item in buy]


total = sum([ cheese_prices[item]   for item in buy])
print(total)

5
total = sum([ cheese_prices[item] for item in buy if item not in missing])
print(total)

3
item in missing


      File "<ipython-input-18-8eff41c05ca1>", line 1
        in missing
         ^
    SyntaxError: invalid syntax



new_prices = { 
    cheese: price*1.1    for cheese, price in cheese_prices.items() }
print(new_prices)

{'Adam': 2.2, 'Bree': 3.3000000000000003, 'Camambert': 4.4, 'Gouda': 5.5}
d144 = { "avi" : "053",
            "ben" : "054",
            "gaddy" : "055"}
d441 = { phone:name      for name, phone in d144.items() } 

print(d441)

{'053': 'avi', '054': 'ben', '055': 'gaddy'}
d = {}
reverse_d = {value:key for key, value in d.items()}