We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e2d64f7 commit 09afedeCopy full SHA for 09afede
days/07-09 datastructures/day_9.py
@@ -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