Advertisement
ganiyuisholaafeez

Split in two

Feb 22nd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. """The function splits a list argument into depending on whether
  2. a number supplied is even or odd"""
  3. def split_in_two(value, number):
  4.     if number % 2 == 0: # Even Condition
  5.         return value[2:]
  6.     else:               # Odd Condition
  7.         return value[:2]
  8.  
  9. print(split_in_two(["a", "b", "c", "d", "e", "f"], 3)) # ['a', 'b']
  10. print(split_in_two(["a", "b", "c", "d", "e", "f"], 4)) # ['c', 'd', 'e', 'f']
  11. print(split_in_two(["a", "b", "c", "d", "e", "f"], 1)) # ['a', 'b']
  12. print(split_in_two(["a", "b", "c", "d", "e", "f"], 10)) # ['c', 'd', 'e', 'f']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement