Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k']
  2. K = 4
  3.  
  4.  
  5. def drop(my_list, K):
  6. len_list = len(my_list)
  7. res = []
  8. for i in range(0, len_list):
  9. if (i + 1) % K != 0:
  10. res.append(my_list[i])
  11. return res
  12.  
  13.  
  14. def drop_slice(my_list, K):
  15. len_list = len(my_list)
  16. if K > len_list:
  17. return my_list
  18. res = list()
  19. for i in range(0, (len_list // K) * K, K):
  20. new = my_list[i: (i + K - 1)]
  21. res += new
  22. res += my_list[len_list: (len_list - (len_list % K) - 1):-1]
  23. return res
  24.  
  25.  
  26. if __name__ == '__main__':
  27. for each in range(1, 12):
  28. result = drop_slice(my_list, each)
  29. print(f'K = {each}: {result}\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement