WOW.
First of all, thanks for the huge explanation, really, much appreciation.
Secondly, I actually almost managed to solve it.
I mean, I got the evens out ( as you can see in my code ):
def format_list(my_list):
"""
This function returns the words in the list which is in the even side.
:param my_list: The list of the project.
:type my_list: str, int, float
:rtype: str, int, float
:return: The result of the list on the even only.
"""
if len(my_list) % 2 == 0:
global joined_list
joined_list = [my_list[-1]]
return my_list[0::2]
new_list = format_list(my_list=["hydrogen", "helium", "lithium", "beryllium", "boron", "magnesium"])
print(new_list)
['hydrogen', 'lithium', 'boron']
is the output.
about using in range and for loops, its a little tricky, the course im learning says to use only options which are learnt untill this time. since this course didnt teach for loop, we cant use it, it also says ( atleast in my laungage at the site ) to use only while loop.
about what you said with the items ::2
I know about it, the problem is with def.
My problem with the exercise is mostly about the definition, as I am pretty bad at it. I know how to solve it without definitions, its not that hard that way, but since the course is saying def is a must, I have to use definitions for it ( cus it will make my coding more easier and good, something like that ).
about this: How can you make a generic solution for lists of varying lengths? What would it be for a list of length 2? length 5? length 1?
I didnt really understand what you said here ( mostly cus of english, but even if i translate it to my laungage its not that understandable to me ).
but anyway, I managed to 90% solve the first exercise with the modulo.
the only problem now is getting the "and" inside the list.
also, just to make sure, I just read again the question, I think i dont need to put the words inside a list, am i right? but even if i dont, i want to know how to answer it regarding making it inside a list and without a list ( both ways )