Feed on
Posts
Comments

to iterate over a list in reverse order in python, i use the ‘reverse’ method. i’m sure there are faster ways to do this in terms of running time, but its hard to conceive of anything easier to implement.

here goes: to iterate over ‘my_list’ backwards, write:

my_list.reverse()
for item in my_list:
print item


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

31 Responses to “read a list backwards in python”

  1. on 14 Jun 2007 at 12:02 am Henry

    for i in reversed(my_list):
    print i

    (new builtin from python 2.4)

  2. on 01 Oct 2007 at 2:12 pm Eric Brunson

    Just to show there’s more than one way to do it:

    for i in list[::-1]:
    print i

    :-)

  3. on 24 Jul 2008 at 8:42 pm Zach Dwiel

    correct me if I am wrong, but reversed is the way to go if memory is an issue as the other two solutions first create a copy of the list while rereversed(list) simply returns a reverse iterator?

  4. on 11 Feb 2011 at 10:38 am Paul Man

    If you need the index or the sequence is a string you can always:

    for i in range(len(my_list) – 1, -1, -1):
    print my_list[i]

  5. on 06 Jul 2011 at 4:01 pm paul.reverse

    I would like to emphasize that Zach Dwiel’s solution is side effect free, which he also states.

    In the original solution, if you wanted to print out the list and then process the list again with the original order, then you would need:

    list.reverse()

    # print list in reverse order
    for i in list:
    print i

    list.reverse()

    # print list in original order
    for i in list:
    print i

    where as Zach’s solution allows for the more optimal

    for i in reversed(list):
    print i

    for i in list:
    print i

  6. on 20 Feb 2021 at 10:35 am Daftar Gaple

    Hello to every , as I am truly eager of reading this website’s post to be
    updated daily. It contains good data.

  7. เว็บไซต์ข่าวที่เกี่ยวกับเรื่องกีฬา ข่าวเกี่ยวกับกีฬาวันนี้ ติดตาม ข่าวเรื่องกีฬาออนไลน์
    เว็บข่าวที่เกี่ยวกับเรื่องกีฬา
    หรือ หนทางการต่อว่าดตามข่าวสารเกี่ยวกับ กีฬาแต่ละประเภท เพื่อที่คุณจะไม่พลาดแม้แต่วินาทีเดียวสำหรับเว็บ ข่าวที่เกี่ยวข้องกับกีฬาออนไลน์ นี้จะมีสาระสำหรับคนที่ติดตามอยู่ตลอดเวลาอย่างแน่นอน เราได้เขียนเว็บไซต์ให้มีการเกาะติด ทุกความเคลื่อนไหวในวงการกีฬา มันจึงเหมาะสมเป็นอย่างมากสำหรับท่านใดที่กำลังมองหาเว็บไซต์ ข่าวเรื่องกีฬา ที่คอยอัพเดทเรื่องราวข่าวได้อย่างแม่นยำและก็ถูกต้องแม่นยำ รวดเร็วทันใจ
    ทันใจ อัพเดทข่าวที่เกี่ยวกับเรื่องกีฬาสดใหม่ก่อนคนใดได้แล้วตลอดเวลา ตรงนี้ Sportsnews891 เราพร้อมพรีเซนเทชั่นทุกเรื่องที่เกี่ยวกับกีฬา แต่ว่าเราจะเน้นย้ำไปที่ ข่าวฟุตบอลแบบเรียลไทม์
    เพื่อเอาใจแฟนบอลที่คอยติดตาม ข้อมูลกันแบบ วันต่อวัน อย่าพลาดที่จะอัพเดทข่าวเรื่องกีฬาก่อนผู้ใดกันแน่ติดตามเลยตรงนี้เท่านั้นข่าวสารฟุตบอลวันนี้ ติดตามข่าวสารบอล เรียลไทม์ ข่าวสารบอลล่าสุดคุณจะไม่พลาดสักแมตช์การแข่งขันชิงชัย ของการประลองบอลไม่ว่าจะลีกเล็กหรือลีกใหญ่ พวกเราก็พร้อมนำเสนอข้อมูลครบ เปิดเผยแบบไม่มีปิดกั้น
    ทันทุกเหตุการณ์การเคลื่อนไหวของนักฟุตบอลแต่ละกลุ่ม รายงานสดลงบนเว็บไซต์ถึงข้อมูลของทีมแต่ละกลุ่มที่จะทำการชิงชัย เพื่อที่คุณจะได้ยอดเยี่ยมนัดวิเคราะห์บอลออนไลน์ ที่เก่งที่สุดในไทย จากการตำหนิดตามข่าวสารบนเว็บไซต์ของเราจะทำให้ท่านทราบถึงข้อมูลที่สำคัญๆเพื่อนำไปวิเคราะห์คู่บอลในแต่ละคู่ได้ พวกเราจะอัพเดทข้อมูลในทุกวันลงใน ข่าวบอลวันนี้ สามารถเข้ามารับข้อมูลข่าวสารได้เลยผ่านเว็บของเรา sportsnews891.com เว็บไซต์ข่าวที่ยอดเยี่ยมผลบอลล่าสุด ผลบอลสด อัพเดทใหม่ 2021Sportsnews891 ไม่ได้มีดีแค่นำเสนอข่าวเกี่ยวกับกีฬาสิ่งเดียว แม้กระนั้นได้กระทำสร้างหน้าต่างผลบอลสดไว้เผื่อผู้ชมที่ต้องการติดตาม
    ผลบอลสด ก็สามารถดูได้บนเว็บไซต์ของเรา โดยเราจะแยกหมวดไว้ให้แก่คุณแล้วบนแถบด้านบน สำหรับคนที่อยากว่ากล่าวตดามผลบอลสด หรือติดตามมองตารางการแข่งขันชิงชัยในทุกวัน และที่พิเศษกว่านั้นคือไม่ใช่แค่มองผลบอลสดอย่างเดียวแม้กระนั้นบนเว็บแจ่มแจ้งเตือนรายงานผลเกี่ยวกับ การแจกใบต่างๆของผู้ตัดสิน หรือ การเคลื่อนที่ในแต่ละอย่างในเกมนั้นๆเอาอกเอาใจแฟนบอลยิ่งกว่าผู้ใดกันจำต้อง sportsnews891
    แค่นั้น เรื่องราวนักฟุตบอล ระดับนานาชาติ
    เรื่องราวนักเตะ อัพเดท 2021เราขอนำเสนอ ประวัตินักฟุตบอล หรือ ประวัติความเป็นมานักฟุตบอล คนมีชื่อเสียงในปี 2021 อัพเดทใหม่ปัจจุบันก่อนใครกันแน่ เสนอความเป็นมาของบุคคลสำคัญในวงการบอล จากทั่วทั้งโลกทุกลีก หรือแม้กระทั่งประวัติความเป็นมาของผู้จัดารทีม
    ปีวัติสมาคม เพื่อท่านได้รับรู้ถึงข้อมูลของนักเตะหรือกลุ่มบอลในแต่ละทีม พร้อมด้วยยกย่องผลงานของนักเตะในแต่ละท่าน สามารถติดตามข่าวบอลของ
    sportsnews891.com ได้ตามหนทางไหนบ้าง ?

    ทุกคนจะสามารถติดตามข่าวสารวงการกีฬาพอดีเว็บหลัก sportsnews891.com หรือจะเข้าไปติดตามที่ Facebook fan page :
    Sportsnews891 ข้อมูลข่าวสาารที่พวกเรานำมาเสนอให้ทุกคนได้รู้กันนั้น จะมีประโยชน์อย่างแน่แท้ สำหรับแฟนบอล หรือคนถูกใจดูข่าวเกี่ยวกับกีฬาติดตามอัพเดทข่าวสารกับเราได้ตลอดระยะเวลา 24 ชม.

  8. on 25 Feb 2021 at 5:54 am 김해출장

    Link exchange is nothing else but it is just placing the other person’s webpage link on your page at appropriate place and other person will also do same in support of you.

  9. on 27 Feb 2021 at 9:02 am dominoqq indonesia

    Excellent post. I was checking constantly this blog and I’m
    inspired! Extremely helpful info particularly the final section :
    ) I take care of such information much. I was looking for this particular
    information for a long time. Thank you and good luck.

  10. on 28 Feb 2021 at 4:52 am bonanza.com

    Desktop Computer systems Are Great With All
    The Right Details

    Hello, always i used to check webpage posts here early
    in the morning, since i like to find out more and more.

    All Any person Requirements To Know About Personal computer Pcs

  11. on 01 Mar 2021 at 1:08 pm Chiropractor West Los Angeles

    Chiropractor West Los Angeles

    read a list backwards in python » from the desk of stinkpot

  12. on 02 Mar 2021 at 2:04 am review du lich moi nhat dulichdau.com

    I don’t even understand how I stopped up right here,
    however I thought this post used to be good. I don’t understand who you are however definitely you are going to a
    famous blogger if you happen to aren’t already. Cheers!

  13. on 05 Mar 2021 at 12:31 am hbet63

    It’s an awesome paragraph designed for all the web visitors; they will take benefit
    from it I am sure.

  14. May I simply say what a comfort to uncover somebody that
    genuinely knows what they are discussing over the internet.
    You definitely realize how to bring an issue to light and make
    it important. More and more people have to read this and understand this side of the story.
    I was surprised you are not more popular because you most certainly
    have the gift.

  15. on 08 Mar 2021 at 7:37 pm máy photocopy Tân trang

    We have supplied machines on a rental settlement
    for some weird and wonderful reasons.

  16. Great article.

  17. on 13 Mar 2021 at 3:52 pm W88vn

    Everything is very open with a clear description of the issues.
    It was truly informative. Your website is useful.
    Thank you for sharing!

  18. on 14 Mar 2021 at 1:22 am https://vallesinamarathon.it/urotrin/

    https://vallesinamarathon.it/urotrin/

    read a list backwards in python » from the desk of stinkpot

  19. on 16 Mar 2021 at 1:50 am Britney

    I don’t know if it’s just me or if everyone else encountering problems with your site.
    It looks like some of the written text on your content are running off the
    screen. Can somebody else please provide feedback and let me know if this is happening to them as well?
    This might be a issue with my internet browser because I’ve had this happen before.

    Thank you

  20. on 22 Mar 2021 at 10:08 pm Maybelle

    I am really enjoying the theme/design of your website. Do you ever run into any
    internet browser compatibility issues? A couple
    of my blog audience have complained about my blog not operating correctly in Explorer but looks great in Safari.
    Do you have any tips to help fix this problem?

  21. on 25 Mar 2021 at 6:02 am Quel matelas choisir

    great issues altogether, you simply won a new reader.
    What may you suggest in regards to your publish that you simply made
    a few days ago? Any sure?

  22. on 25 Mar 2021 at 2:18 pm fun88

    What’s up friends, its enormous article on the topic of educationand fully defined, keep it up all the time.

  23. on 25 Mar 2021 at 8:06 pm candid aligners review

    Quality content is the key to invite the visitors to pay a quick visit the site, that’s what this website is providing.

  24. on 28 Mar 2021 at 12:46 am adulrfriendfinder

    Hi there, yup this paragraph is actually fastidious
    and I have learned lot of things from it on the topic
    of blogging. thanks.

  25. on 07 Apr 2021 at 8:51 am 365 bet

    This design is spectacular! You certainly know how to
    keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog
    (well, almost…HaHa!) Excellent job. I really enjoyed what you had to say,
    and more than that, how you presented it. Too cool!

  26. on 19 May 2021 at 3:30 pm Angelica

    Hello everyone, it’s my first visit at this web site, and paragraph is actually fruitful designed for
    me, keep up posting such articles or reviews.

  27. Займы до зарплаты на карту онлайн.
    Мгновенный займ От 0% в сутки!
    На карту, киви или наличными. Выдача займа за 5 минут.

    Быстро. · Мгновенно. Круглосуточное одобрение.
    От 0% в сутки. 99% одобрения. Деньги онлайн.
    Круглосуточно. День в суткие получение.
    Займ от 0% в сутки
    Мое имя: Jung Schlapp
    Лет: 23
    Страна: Germany
    Home town: Lubeck
    ZIP: 23564
    Улица: Rudower Chaussee 5

  28. on 18 Aug 2021 at 3:51 am Magreza

    What’s up, its good article about media print, we all understand media is a impressive source of
    data.

  29. on 29 Aug 2021 at 7:26 am https://Dafabetviet88.Com/

    Thank you for the auspicious writeup. It in truth was
    once a leisure account it. Look complex to more introduced agreeable from
    you! However, how can we be in contact?

  30. on 11 Oct 2021 at 11:27 pm kickass

    I get pleasure from, cause I discovered just what I was having a look for.
    You have ended my four day long hunt! God Bless you man. Have
    a great day. Bye

  31. on 12 Oct 2021 at 9:36 am pertanian dan agrobisnis

    Kostratani membangun pertanian digital.

Did I get this wrong? Let me know!

Trackback URI | Comments RSS