+ 2

How can i skip every Kth element in a list and add rest ?

in python

29th Jul 2017, 6:55 AM
HIMANSHU SHARMA
HIMANSHU SHARMA - avatar
5 Respuestas
+ 3
#we suppose l is your list and k is already defined The shortest way sum(l) - sum([l[i] for i in range(1,len(l)) if i%k == 0]) + l[0] The cleanest way sum = 0 for i in range(1,len(l)): if i%k: sum+=l[i] if len(l): sum +=l[0]
29th Jul 2017, 7:32 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
How to find 2's complemet of a binary number in python ? we have to check number from last and after 1st one occur then after that convert all one to zero and all zero to one .
25th Aug 2017, 11:42 AM
HIMANSHU SHARMA
HIMANSHU SHARMA - avatar
0
please ans
25th Aug 2017, 11:43 AM
HIMANSHU SHARMA
HIMANSHU SHARMA - avatar
0
25th Aug 2017, 11:43 AM
HIMANSHU SHARMA
HIMANSHU SHARMA - avatar
0
The easiest way is to do : ~n + 1 ~n is the 1 complement operator
25th Aug 2017, 2:37 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar