Created
August 7, 2014 15:35
-
-
Save sumoward/bfdfcfa91ab6c977fc7b to your computer and use it in GitHub Desktop.
coding test films find most popular decade from a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
short coding test to take a list of movies and | |
their year and rturn the most popular decade | |
""" | |
def movies(): | |
frequency_of_decade = { | |
'1900': 0, | |
'1910': 0, | |
'1920': 0, | |
'1930': 0, | |
'1940': 0, | |
'1950': 0, | |
'1960': 0, | |
'1970': 0, | |
'1980': 0, | |
'1990': 0, | |
'2000': 0, | |
'2010': 0, | |
} | |
a = """ | |
moviea (1971) | |
movieb (1981) | |
moviec (1991) | |
movied (2001) | |
moviee (1982) | |
movief (1983) | |
movief (2009) | |
movief (2012) | |
""" | |
for index, char in enumerate(a): | |
if char == "(": | |
date = a[index + 1:index + 5] | |
date = date[:-1] + "0" | |
frequency_of_decade[date] = frequency_of_decade[date] + 1 | |
ans = max(frequency_of_decade, key=frequency_of_decade.get) | |
print('Your favorite decade for Film is the', ans, "\'s") | |
return ans | |
if __name__ == '__main__': | |
movies() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment