fork download
  1. a = [i for i in range(1, 6)]
  2.  
  3. try:
  4. if len(a) > 0:
  5. [a.remove(a[-2]), a.extend([6, 7, 8]), a.insert(2, "Python") if len(a) >= 2 else None]
  6.  
  7. for _ in range(len(a) // 2):
  8. if len(a) % 2 == 0:
  9. a.pop(0)
  10. else:
  11. a.pop()
  12.  
  13. except (IndexError, ValueError) as e:
  14. print(f"Exception occurred: {e}")
  15.  
  16. finally:
  17. print("Final list:", a)
  18. print("Sum of lengths:", sum(len(str(item)) for item in a))
  19.  
Success #stdin #stdout 0.11s 14144KB
stdin
Standard input is empty
stdout
Final list: ['Python', 3, 5, 6]
Sum of lengths: 9