Below I have created a function which iterates through a list of numbers and selects the last 3 digits from each numbers and puts them as new numbers in another list.I also sort them from smallest to largest.However, I see a "TypeError: 'int' object is not iterable" message. What is wrong with my code? Also how could. we do the same thing with a lambda function?
ids = [1600,1500,1800,1900,1700]
alist=ids
sorted_ids=[]
def last_four(alist):
for element in alist:
values=str(element)
sorted_ids.append(values[1:4])
return sorted(sorted_ids)
print(last_four(alist))
Thank you very much!