File tree 3 files changed +18
-18
lines changed
3 files changed +18
-18
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/python
2
2
# -*- coding: utf-8 -*-
3
3
4
- import os , re
5
- from collections import defaultdict
4
+ import os
5
+ import re
6
6
7
7
findhours = re .compile (r'(\d{1,2}(:\d\d)?)-((\d{1,2}(:\d\d)?)(([AP]M)|NOON))' )
8
8
starts = []
26
26
print "found %(count)d total class times" % { "count" : len (starts ) }
27
27
28
28
# dividing up the classes we've found into different timeslots to count them
29
- timeslots = defaultdict (int )
29
+ timeslots = {} # defaultdict(int)
30
30
for i in range (len (starts )):
31
- timeslots [starts [i ]+ "-" + ends [i ]] += 1
31
+ key = starts [i ]+ "-" + ends [i ]
32
+ if timeslots .has_key (key ):
33
+ timeslots [key ] += 1
34
+ else :
35
+ timeslots [key ] = 1
36
+
37
+
38
+ sorted_timeslots = sorted (timeslots .items (), key = lambda x :x [1 ], reverse = True )
39
+ for time in sorted_timeslots :
40
+ print time
41
+
32
42
33
- #print timeslots.items()
34
- print (sorted (timeslots .items (), key = lambda x :x [1 ], reverse = True )[:10 ])
Original file line number Diff line number Diff line change 15
15
16
16
# the below line will cause an error if you uncomment it, because the dictionary doesn't have a key '6-9PM' in it
17
17
# d['6-9PM'] += 1
18
+ #
19
+ # test if a dictionary has a key
20
+ # d.has_key('6-9PM')
18
21
19
-
20
- # we'll use a default dictionary instead, which has a default value
21
- # that means we can add 1 to any key in it, even if it doesn't exist yet
22
- # because the dictionary will take any unknown key and give it the default integer value of 0
23
-
24
- # this is a different type of import statement
25
- from collections import defaultdict
26
-
27
- dd = defaultdict (int )
28
- print dd
29
- dd ['6-9PM' ] += 1
30
- print dd
Original file line number Diff line number Diff line change @@ -7,3 +7,4 @@ def myfunction():
7
7
print "Hello World"
8
8
9
9
myfunction ()
10
+ #myfunction()
You can’t perform that action at this time.
0 commit comments