repl.it
@RoselyAlvaradoV/

notes! pt.14

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
34
35
36
37
#a linear collection fo values that stay in order 
#a bag of values each with its own lable 
#dictornaries are python's most powerful data collection 
#so we index the thing we put in the dictionary with a lookup tag 
purse = dict()#dictonary set up 
purse['money']= 12 
purse["candy"] = 3 
purse['tisues']=75 
print(purse)
print(purse['candy']) #works like search query 
purse['candy']= purse['candy'] + 2 
jjj = {'chuck': 100,  'fred': 1, 'jan': 100} #curly braces for dictonaries 
print(jjj)
ccc = dict()
ccc['csec']=1 
ccc['scwen']= 1 
print(ccc)
counts = dict()
names = ['csev', 'cwen', 'csev', 'zqian', 'cwen']
for name in names: 
  if name not in counts:
    counts[name]= 1 
  else: 
    counts[name]= counts[name] +1 
print(counts) 
#get() function to find out how many there are 
print(counts.get("csev", 0)) #value is where everything starts 
counts = dict()
line = input("enter a line of text: ")
words = line.split() #splits words in a list 
print("word:",words)
for word in words: 
  counts[word]= counts.get(word,0) +1 
print("counts", counts)
jjj = {"chuck":1, 'freed': 42, "jan": 100}
for aaa,bbb in jjj.items(): 
  print(aaa,bbb)