Python Forum
how to reverse a list and store in another list in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to reverse a list and store in another list in python
#2
(Jul-02-2022, 03:41 PM)SuperNinja3I3 Wrote: I want to reverse a list but want to store it in another list...

reverse the elements of the ‘myList’ and store that in ‘reversedList’

reversedList = mylist.reverse()
Now, if it is homework and you have to right a function to do this yourself, my hints would be:
#1  Using a negative indexes you can start at the end of the list and move backwards.
myList[-1] #the last item in the list
myList[-2] #the second to last item...  

# 2    Python's len() function tells you how many items in the list and therefor how times it needs to loop and copy the item to a new list.
Reply


Messages In This Thread
RE: how to reverse a list and store in another list in python - by XavierPlatinum - Jul-03-2022, 03:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 1 569 May-23-2024, 05:39 AM
Last Post: Pedroski55
Question Python - List - Int List sophi 8 2,819 Apr-21-2022, 07:55 PM
Last Post: sophi
  Reverse Function in Python Voraman 7 3,458 Feb-13-2021, 07:21 PM
Last Post: Voraman
  reverse math in python, who will find the correct answer? Kakha 11 4,625 Jan-11-2021, 11:59 AM
Last Post: Gribouillis
  question on list in Python spalisetty06 1 2,120 Jun-30-2020, 09:03 AM
Last Post: pyzyx3qwerty
  Python list exercize ESTOUR 3 2,026 May-23-2020, 11:10 PM
Last Post: ESTOUR
  Read data from a CSV file in S3 bucket and store it in a dictionary in python Rupini 3 7,179 May-15-2020, 04:57 PM
Last Post: snippsat
  Python Adding +1 to a list item cointained in a dict ElReyZero 1 2,150 Apr-30-2020, 05:12 AM
Last Post: deanhystad
  Check if a list exists in given list of lists Daniel94 2 2,343 Apr-07-2020, 04:54 PM
Last Post: deanhystad
  list of strings to list of float undoredo 3 2,863 Feb-19-2020, 08:51 AM
Last Post: undoredo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020