-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha09.py
More file actions
98 lines (81 loc) · 2.39 KB
/
a09.py
File metadata and controls
98 lines (81 loc) · 2.39 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
## IMPORTS GO HERE
## END OF IMPORTS
### YOUR CODE FOR get_types_counts() FUNCTION GOES HERE ###
def get_types_counts(dic):
s={}
for i in dic:
count=0
a=dic[i]
for j in a:
count +=1
s[i]=count
return s
#### End OF MARKER
### YOUR CODE FOR get_types() FUNCTION GOES HERE ###
def get_types(dic):
lst=[]
for i in dic:
lst.append(i)
return lst
#### End OF MARKER
### YOUR CODE FOR get_author_count() FUNCTION GOES HERE ###
def get_author_count(dic,w):
count = 0
a={}
for i in dic:
if type(dic) == list :
for j in dic:
count +=1
break
return count
else:
q=dic[i]
for j in q:
for k in j :
if k == "author":
a=j[k]
for m in a :
b=a[m]
if b == w :
count +=1
return count
#### End OF MARKER
if __name__ == '__main__':
d = {
"articles": [{
"slug": "how-to-train-your-mule",
"title": "How to train your mule",
"description": "Ever wonder how?",
"body": "It takes a Jacobian",
"tagList": ["mules", "training"],
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:48:35.824Z",
"favoritesCount": 0,
"author": {
"username": "jake",
"bio": "I work at statefarm",
"following": False
}
}, {
"slug": "and another article",
"body": "I'm getting bored",
"tagList": ["bored", "article"],
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:48:35.824Z",
"favoritesCount": 20,
"author": {
"username": "cap",
"following": True
}
}],
"tweets": [{
"body": "See my article on training mules.",
"author": {
"username": "jake"
}
}]
}
print get_types(d)
print get_types_counts(d)
print get_author_count(d, 'cap')
print get_author_count(d, 'jake', ['articles', 'tweets'])