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)
final_list = f"{new_list} and {joined_list}"
print(final_list)
['hydrogen', 'lithium', 'boron']
['hydrogen', 'lithium', 'boron'] and magnesium
what is happening here? why dont i get it inside the list?
edit:
managed to almsot get it, but theand is problematic.
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)
final_list = f"{new_list} and {joined_list}"
print(final_list)
['hydrogen', 'lithium', 'boron']
['hydrogen', 'lithium', 'boron'] and ['magnesium']
how do i add and?