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 <pre class='brush: python'>sum()</pre> function^^: <pre class='brush: python'> checkio = lambda a: sum(a[::2])*a[-1] if len(a)!=0 else 0 </pre> Here <pre class='brush: python'>sum(a[::2])</pre> replace the line 5to9 and <pre class='brush: python'>a[-1]</pre> == <pre class='brush: python'>a[len(a)-1]</pre> :)</p>
Oct. 21, 2016
Comments: