-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathdate converter.py
More file actions
36 lines (24 loc) · 910 Bytes
/
date converter.py
File metadata and controls
36 lines (24 loc) · 910 Bytes
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
def date_converter(d, s):
month = s[:s.find('/')]
month = d[int(month)]
day = s[s.find('/')+1:]
day = day[:day.find('/')]
year = s[s.find('/')+1:]
year = year[year.find('/')+1:]
return day +' '+ month +' '+ year
english = {1:"January", 2:"February", 3:"March", 4:"April", 5:"May",
6:"June", 7:"July", 8:"August", 9:"September",10:"October",
11:"November", 12:"December"}
# then "5/11/2012" should be converted to "11 May 2012".
# If the dictionary is in Swedish
swedish = {1:"januari", 2:"februari", 3:"mars", 4:"april", 5:"maj",
6:"juni", 7:"juli", 8:"augusti", 9:"september",10:"oktober",
11:"november", 12:"december"}
print date_converter(english, '11/3/1848')
#>>> 11 May 2012
print date_converter(english, '5/11/12')
#>>> 11 May 12
print date_converter(swedish, '5/11/2012')
#>>> 11 maj 2012
print date_converter(swedish, '12/5/1791')
#>>> 5 december 1791