xlist.py 544 B

12345678910111213141516171819202122232425262728
  1. # update: 2022-6-17
  2. def get_last(data_list, amount):
  3. """获取尾部元素"""
  4. return data_list[-amount:]
  5. def cut_last(data_list, amount):
  6. """去掉尾部元素"""
  7. return data_list[:-amount]
  8. def get_head(data_list, amount):
  9. """获取头部元素"""
  10. return data_list[:amount]
  11. def cut_head(data_list, amount):
  12. """去掉头部元素"""
  13. return data_list[amount:]
  14. def reverse(string_or_list):
  15. """倒序"""
  16. if type(string_or_list) not in [str, list]:
  17. return ''
  18. return string_or_list[::-1]