Implement function swap that takes a 2D list (a
list of list of integers) and modifies it
in-place by swapping the first element in
each row with the last element in that row. The return value is
None. You may not use slicing. You maynot use any list method like
append, insert, etc. Modification must be
in-place, you may not move the list
itself or any of its sublists to a new memory location.
Examples:
reverse([[1,2,3],[4,5,6]]) -> [[3,2,1],[6,5,4]]
reverse([[1,2,3,4],[5,6,7,8]]) -> [[4,2,3,1],[8,6,7,5]]
True
False
In python please
Program Code Screenshot:
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to copy:
def swap(l):
for i in range(len(l)):
l[i][0],l[i][-1]=l[i][-1],l[i][0]#swap the first and last elements
in that row
print(l)#print list after swapping
swap([[1,2,3],[4,5,6]])#call the function
swap([[1,2,3,4],[5,6,7,8]])
Note:
Please let me know in case of any help needed in the comments section.
Plese upvote my answer. Thank you.
Get Answers For Free
Most questions answered within 1 hours.