# File: Erin/list0.py #Increment each element in a list. Different methods """ list? 3 4 5 # will input as "3 4 5" L = ['3', '4', '5'] incremented list: [4, 5, 6] """ def inclist(L): # increment all numbers in a list by index for i in range(len(L)): # be sure to convert to an int L[i] = int(L[i]) + 1 return L def increment(L): # increment all numbers in a list for x in L: x = int(x) + 1 # be sure list is made out of integers return L def incMap(L): # apply the increment function to all L is a list of numbers return list(map(lambda x: int(x) + 1, L)) def main(): # try all methods myL = input( "Input a list of integers(EX: 2 3 4 [ENTER])?" ).split(" ") # reads a string then splits with blank and converts to a list print("L =", myL) L = [(int(x) + 1) for x in myL ] # builds list print(L) print("incremented list with map:", incMap(myL)) print("incremented list with for by index:", inclist(myL)) print("incremented list with for:", increment(myL)) # more python style main()