Python Forum
Reverse list items in a stupid way
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reverse list items in a stupid way
#2
Lists are mutable, and are therefore copied and passed by reference. 'a' is not a list, it is a pointer to a list. word = a copies the pointer not the list. So everything you do to word you do to a, and vice versa. You need to copy the list pointed to by a, with something like word = a[:]. Or just make a new list, word = [''] * len(a), since you are overwriting everything in word anyway.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Reverse list items in a stupid way - by pyth0n123 - Jul-27-2019, 09:52 PM
RE: Reverse list items in a stupid way - by ichabod801 - Jul-28-2019, 12:06 AM
RE: Reverse list items in a stupid way - by ThomasL - Jul-28-2019, 08:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Stupid question int 2 545 Mar-21-2025, 07:24 AM
Last Post: int
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 3,002 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Finding combinations of list of items (30 or so) LynnS 1 1,566 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  For Word, Count in List (Counts.Items()) new_coder_231013 6 7,186 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get list of exactly 10 items? Mark17 1 3,752 May-26-2022, 01:37 PM
Last Post: Mark17
  how to assign items from a list to a dictionary CompleteNewb 3 2,780 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Reading list items without brackets and quotes jesse68 6 6,996 Jan-14-2022, 07:07 PM
Last Post: jesse68
Question How to gather specific second-level items from a list chatguy 2 2,356 Dec-17-2021, 05:05 PM
Last Post: chatguy
  Question about List.reverse() method tomliuwhite 1 2,070 Dec-07-2021, 08:20 AM
Last Post: ndc85430
  deleting select items from a list Skaperen 13 6,945 Oct-11-2021, 01:02 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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