Writing a function that alternates plus and minus signs between list indices

后端 未结 7 801
既然无缘
既然无缘 2020-12-10 07:40

In a homework set I\'m working on, I\'ve come across the following question, which I am having trouble answering in a Python-3 function:

\"Write a fun

相关标签:
7条回答
  • 2020-12-10 08:32

    You could try this list comprehension:

    sum([-e if c%2 else e for c,e in enumerate(yourlistylist)])
    
    0 讨论(0)
提交回复
热议问题