Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def swap_operation(the_list, index1, index2):
  2.     new_list = the_list[:]
  3.  
  4.     if index1 < 0 or index1 > len(the_list) - 1 or index2 < 0 or index2 > len(the_list) - 1 or index1 > index2:
  5.         print(*new_list)
  6.     else:
  7.         new_list[index1], new_list[index2] = new_list[index2], new_list[index1]
  8.         print(*new_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement