'Keep getting None after my expected result. Trying to get just the 'nth' item of the list printed [duplicate]
Question:
Write a function nth_item(data, n) that takes a list data and an integer n as parameters and returns the nth item of the list of data, assuming the first item has an index of n = 0. You may assume that data contains at least n + 1 items.
I can get the right item from the list but always followed by "None". Not sure why "None" keeps appearing or where i'm going wrong.
def nth_item(data, n):
"""Takes a list and an integer and returns the nth item of the
list"""
print(data[n])
item = nth_item([10, 20, 30], 0)
print(item)
"""should result with:
10
but keep getting:
10
None
"""
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
