First solution in Clear category for Even the Last by mehWincenty
def checkio(array): if len(array)==0: return 0 c=0 i=0 while i Oct. 21, 2016 Comments: danleonard on Aug. 20, 2019, 4:12 p.m. <p>I like the i+=2 part. Don't have to check if even that way.</p> netDrewid on Jan. 7, 2021, 10:01 p.m. <p>Agreed. Very simple and clean.</p> pokryshkin on May 29, 2021, 1:49 p.m. <p>instead of</p> <pre class='brush: python'> c, i = 0, 0 while i<len(array): c+=array[i] i+=2 </pre> <p>You can use something like</p> <pre class='brush: python'>с = sum((array[i] for i in range(0,len(array),2))) </pre> alterGNU on June 13, 2021, 1:16 a.m. <p>Hi^^ nicely done!</p> <p>As @pokryshkin said, you can use the `sum()` function^^: ``` checkio = lambda a: sum(a[::2])*a[-1] if len(a)!=0 else 0 ``` Here `sum(a[::2])` replace the line 5to9 and `a[-1]` == `a[len(a)-1]` :)</p>
Oct. 21, 2016
Comments: