-2

I cant create like [12,34,56,78]

I tried used list(),but can't get the answer.

A=12345678,list(A)=[1,2,3,4,5,6,7,8]

i need the result like 12345678=[12,34,56,78].Any answer?

DirtyBit
  • 16,613
  • 4
  • 34
  • 55
Kai Long
  • 15
  • 5

2 Answers2

1

Perhaps:

A = '12345678'

print([int(A[x:x+2]) for x in range(0, len(A), 2)])

OUTPUT:

[12, 34, 56, 78]
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
0

you could try:

s = '12345678'
n = 2
result=[s[i:i + n] for i in range(0, len(s), n)]
print(result)

['12', '34', '56', '78']
Frenchy
  • 16,386
  • 3
  • 16
  • 39