Return a list containing every other element from an input list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Return a list containing every other element from an input list

Saludos a todos/as! (Greetings!). I need your assistance if it's possible, I'm finding a way to: "return a list containing EVERY OTHER ELEMENT from an input list, starting with the first element (that means included I think)", starting with a def function with one parameter, one variable that is an empty list and other variable that is equal to 0, with no modules, I can only use basic list functions, if anyone would be so kind to give me an example, thanks in advance!

9th Jul 2020, 3:37 AM
Whally O.
Whally O. - avatar
4 Answers
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Now is showing samples of input and output
9th Jul 2020, 4:36 AM
Whally O.
Whally O. - avatar
0
https://code.sololearn.com/c8X7fCiGss7l/?ref=app 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 This is the code that I'm trying to run, instead I'm getting empty lists and not the expected output.
9th Jul 2020, 4:26 AM
Whally O.
Whally O. - avatar
0
Thanks 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 , sorry but, what about the if statement and the i += 1?, I'm asking you because usually on those lessons if we delete something, usually is not approved.
9th Jul 2020, 5:40 AM
Whally O.
Whally O. - avatar
0
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚 Thanks, is showing IndexError in line 18, if elements[i] in elements and i<x:
9th Jul 2020, 3:50 PM
Whally O.
Whally O. - avatar