+ 2
How can i skip every Kth element in a list and add rest ?
in python
5 Antworten
+ 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]
+ 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 .
0
please ans
0
in python
0
The easiest way is to do :
~n + 1
~n is the 1 complement operator