- 1

how to find even index position which is divisible by 2 only

3rd Feb 2017, 6:18 AM
anbarasan
anbarasan - avatar
7 odpowiedzi
+ 2
arr = [ 'a', 'b', 'c', 'd', 'e' ] for index in range(0,len(arr),2): print(arr[index],end='') output: ace
3rd Feb 2017, 8:00 AM
visph
visph - avatar
3rd Feb 2017, 6:43 AM
Víctor Vila Álvarez
Víctor Vila Álvarez - avatar
+ 1
l=[1,1,2,4,6,7,8] [y for x,y in enumerate(l) if x%2==0 and y%2==0]
3rd Feb 2017, 8:13 AM
anbarasan
anbarasan - avatar
0
Try with modulus if (x%2 == 0) { //do stuff } Where x is your index.
3rd Feb 2017, 6:37 AM
Nikolai Russev
Nikolai Russev - avatar
0
I want even index position with divisible by 2
3rd Feb 2017, 6:39 AM
anbarasan
anbarasan - avatar
0
look into Lambdas
3rd Feb 2017, 10:06 AM
LordHill
LordHill - avatar
0
l=[1,1,2,4,6,7,8] [y for x,y in enumerate(l) if x%2==0 and y%2==0] o/p:2,6,8
3rd Feb 2017, 10:09 AM
anbarasan
anbarasan - avatar