Just a normal question | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Just a normal question

Hello people, I want to separate a serie of string numbers in pairs. How can I do it? (111001 to 11 10 01)

18th Sep 2020, 5:24 PM
āš”šŸ”„ šŸ˜Ž Baby Hater šŸ”„āš”
āš”šŸ”„ šŸ˜Ž Baby Hater šŸ”„āš” - avatar
2 Respostas
+ 3
Create an empty list. Iterate through the string with an index variable with a step of 2. On each iteration slice the string from the index variable to the index varisble + 1 and append the slice to the list.
18th Sep 2020, 5:40 PM
Seb TheS
Seb TheS - avatar
+ 1
s = "111001" l = [] for i in range(0, len(s), 2): l.append(s[i:i + 2]) l #["11", "10", "01"]
19th Sep 2020, 2:11 AM
Seb TheS
Seb TheS - avatar