repl.it
@RoselyAlvaradoV/

Notes! pt 14.5

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#creat empty dict capitals 
Capital = dict()

#fill it with some values 
Capital["Russia"] = "moscow"
Capital['Ukraine']= "kiev"
Capital["USA"]= "washington"

countries = ['Russia', 'France', "USA", "Russia"]
for country in countries: 
  #for each country from the list check to see weatheer it is in the dictionary 
  if country in Capital: 
    print("The captial of " + country + ' is ' + Capital[country])
  else: 
    print("The capital of " + country + " is unknown")

A = dict(zip("abcdef", list(range(6))))
for key in A: 
  print(key,A[key])

A = dict(zip("abcdef", list(range(6))))
for key,val in A.items(): 
  print(key,val)

A = {"ab": 'ba', 'aa':'aa', 'bb': 'bb', 'ba':'ab'}
key = 'ab'
if key in A: 
  del A[key]
try: 
  del A[key]
except KeyError: 
  print("There is no element with key '" + key + "' in dict")
print(A)