SHARE
TWEET

Untitled

a guest Feb 21st, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This is a split_in_two function that accepts a list and a numrber.
  2. # if number is even, it returns the list elements from the third  element to the end.
  3. # if the number is odd, it returns the list elements from index 0 to 2
  4.  
  5. def split_in_two(anylist, number):
  6.     if number % 2 == 0:
  7.         print(anylist[3:])
  8.     else:
  9.         print(anylist[:2])
  10.        
  11. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  12. , 2)
  13. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  14. , 1)
  15. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  16. , 15)
  17. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  18. , 6)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top