Skip to content

Commit 09afede

Browse files
authored
Create day_9.py
1 parent e2d64f7 commit 09afede

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

days/07-09 datastructures/day_9.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from data import us_state_abbrev, states_list
2+
3+
def get_nth_item(data, n):
4+
'''print out the nth item in a list or dict'''
5+
if n > 50:
6+
result = 'There are less than {} states in the US...'.format(n)
7+
elif type(data) == list:
8+
result = data[n]
9+
else:
10+
result = list(data)[n]
11+
12+
return result
13+
14+
print(get_nth_item(us_state_abbrev, n=127))
15+
16+
print(get_nth_item(us_state_abbrev, n=7))
17+
18+
print(get_nth_item(states_list, n=28))
19+
20+
print(get_nth_item(states_list, n=112))

0 commit comments

Comments
 (0)