Why is my output a list of characters instead of a list of strings? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Why is my output a list of characters instead of a list of strings?

I was given an assignment to use the enumerate function to return only elements of a list with even indices. I am receiving the correct output when the input is a list of characters. However, when the input is a list of strings, the output is the correct strings split into a long list of characters. https://code.sololearn.com/c9aUPr9Fd7RC/?ref=app https://code.sololearn.com/c9aUPr9Fd7RC/?ref=app

8th Mar 2020, 5:29 PM
Conor
2 Respuestas
+ 2
use append:- for index, element in enumerate(elements): if index % 2 == 0: result.append(element) return result
8th Mar 2020, 5:40 PM
rodwynnejones
rodwynnejones - avatar
0
Thanks so much! Is there any chance you could explain why adding the element to the variable separated it into characters? I'm curious now as to why exactly that didn't work
8th Mar 2020, 5:48 PM
Conor