Python Forum
Which approach is better to copy a list?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Which approach is better to copy a list?
#1
I was reading Python Crash Course (excellent book btw!), in it, the author copies a list by slicing it, and demonstrates that the new list is independent, any change in the new list, will not be reflected in the old one. On SO, the accepted answer states the prefer method is:

new_list = list(old_list) 


because it's more readable.

On Slicing:

Quote:it is a weird syntax and it does not make sense to use it ever. ;)

I prefer using the [:], it's simple and understandable to me. Any reason why I should stop using it?
Reply


Messages In This Thread
Which approach is better to copy a list? - by nexusfactor - Oct-15-2017, 05:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Advice needed on how to approach this problem... sawtooth500 1 358 Apr-06-2024, 01:55 PM
Last Post: snippsat
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 388 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy List Not Copying BAbdulBaki 3 711 Aug-19-2023, 02:03 AM
Last Post: perfringo
  About list copy. water 3 1,641 Apr-03-2022, 02:42 AM
Last Post: deanhystad
Question Making a copy list in a function RuyCab 1 1,863 Jul-11-2021, 02:06 PM
Last Post: Yoriz
  Sound Approach for Running a Shell Command? matt_the_hall 8 3,540 Dec-14-2020, 02:52 PM
Last Post: matt_the_hall
  Need feedback on my approach for python dashboard for Asana pashtett 0 1,373 Nov-24-2020, 11:51 AM
Last Post: pashtett
  Approach to creating Audit table pynewbie 4 3,982 Feb-24-2020, 06:12 PM
Last Post: pynewbie
  list approach due nested order 3Pinter 6 2,934 Oct-07-2019, 01:49 PM
Last Post: 3Pinter
  Whats a good design/approach? hshivaraj 1 1,849 Sep-16-2019, 01:44 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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