Question/Solution - 7
Question
l = [34, 0, -12, -78, 43, 0, 6, -1, 0, 86, -100, 56]
# [56, 0, -12, -78, 43, 0, 6, -1, 0, 86, -100, 34]
Answer
def swap(l):
l.append(l[0])
l.pop(0)
l.insert(0, l[-2])
l.pop(-2)
return l
print(swap([34, 0, -12, -78, 43, 0, 6, -1, 0, 86, -100, 56]))
Post a Comment