This file contains hidden or 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
def number_game(x,y): | |
if x > y: | |
return [n for n in range(y,x) if n%2==0] | |
elif y==x: | |
return [] | |
else: | |
return [n for n in range(x,y) if n%2!=0] |
This file contains hidden or 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
def myFunc(e): | |
return len(e) | |
states = ["Abia", "Adamawa", "Anambra", "Akwa Ibom", "Bauchi", "Bayelsa", "Benue", "Borno", | |
"Cross River", "Delta", "Ebonyi", "Enugu", "Edo", "Ekiti", "Gombe", "Imo", "Jigawa", | |
"Kaduna", "Kano", "Katsina", "Kebbi", "Kogi", "Kwara", "Lagos", "Nasarawa", "Niger", | |
"Ogun", "Ondo", "Osun", "Oyo", "Plateau", "Rivers", "Sokoto", "Taraba", "Yobe", "Zamfara"] | |
states.sort(reverse=True,key=myFunc) | |
print(states[5]) |
This file contains hidden or 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
def numbertoordinal(number): | |
number_string = str(number) | |
SUFFIXES = {1: '1st', 2: '2nd', 3: '3rd'} | |
# Checking for 11-14 because those are akward | |
if int(number_string[-2:]) > 10 and int(number_string[-2:]) < 14: | |
return number_string + 'th' | |
else: | |
suffix = SUFFIXES.get(int(number_string[-1:]), number_string + 'th') |
NewerOlder