I need this code in PYTHON please and read the bold phase TH
I need this code in PYTHON please!!! and read the bold phase!!! THank you!
Write a function called modify that adds an element (passed in as an argument) to the end of every inner list in a two dimensional list passed in as an argument. Return the modified list. For example, if the incoming list is [[3, 4], [1], [5, 3, 4]] and the incoming element is 5, your code would return the list 03, 4, 5], [1, 5], [5, 3, 4, 5]]. You may not use any built in functions/methods besides len() and .append()|Solution
The following code gives the required functionality:
# your code goes here
def modify():
for num in list:
num.append(5)
print (list)
list = [[3,4], [1], [5,3,4]];
modify()
Output:
[[3, 4, 5], [1, 5], [5, 3, 4, 5]]
For more clarity, please go to the following url:
http://ideone.com/Ofczn0
hope it helps, do give your response.
Solution in while loop:
# your code goes here
def modify(obj):
i = 0
length = len(list)
while(i<length):
list[i].append(obj)
i=i+1
print (list)
list = [[3,4], [1], [5,3,4]];
modify(5)
Output:
[[3, 4, 5], [1, 5], [5, 3, 4, 5]]
The following url will help you to get more clarity.
http://ideone.com/CsJqgo
Hope it helps.
