studying Python as crazy and have many many questions.
This time about function, i need to create 2 functions, first for numbers to sum up everything that user inputs in
Judging by your question it seems you are learning functions in python
, you can reverse the list using a function like this:
strings_ = [str(x) for x in input("Please input at least 5 words (Use Space): ").split()]
for index,item in enumerate(strings_):
def recursion_reverse(string_1):
if not string_1:
return ""
else:
front_part=recursion_reverse(string_1[1:])
back_part=string_1[0]
return front_part+back_part[0]
strings_[index]=recursion_reverse(item)
print(strings_)
output:
Please input at least 5 words (Use Space): Hello world this is me
['olleH', 'dlrow', 'siht', 'si', 'em']
For your first function, that already exists as a built-in function of same name (sum()
). For the second, you can use a simple list comprehension.
def rever(strings):
return [x[::-1] for x in strings]