Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

return value of function looping through list in reverse is the last element in it

this function is supposed to return the list in reverse but instead, it is only returning the last element of the list. I would like to know what is the issue.

def reverse_list(lt):
    for f in lt[::-1]:
        return f
lt = [1,2,3,4]
print(reverse_list(lt))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def reverse_list(lt):
    return lt[::-1]

lt = [1,2,3,4]
print(reverse_list(lt))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading