Python Forum
Making a copy list in a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a copy list in a function
#2
def make_great(magicians_list[:]):
Don't use [:] on the parameter

Use [:] inside the function
def make_great(magicians_list):
    list_aux = []
    for magician in magicians_list[:]:
        ...
        ...

If you actually want to pass in a copy of the list and the function uses the passed-in list, use
magicians_aux = make_great(magicians[:])

def make_great(magicians_list):
    list_aux = []
    for magician in magicians_list:
        ...
        ...
Reply


Messages In This Thread
Making a copy list in a function - by RuyCab - Jul-11-2021, 02:00 PM
RE: Making a copy list in a function - by Yoriz - Jul-11-2021, 02:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 307 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy List Not Copying BAbdulBaki 3 660 Aug-19-2023, 02:03 AM
Last Post: perfringo
  Making a function more efficient CatorCanulis 9 1,919 Oct-06-2022, 07:47 AM
Last Post: DPaul
  About list copy. water 3 1,591 Apr-03-2022, 02:42 AM
Last Post: deanhystad
  Making a code.py file to function, does not run hobbyist 6 2,944 Jan-27-2021, 07:50 AM
Last Post: DeaD_EyE
  making list in looping a dictionary glennford49 9 3,613 Jun-25-2020, 03:23 PM
Last Post: ndc85430
  making a function that writes variables (is possible?) miker2808 3 2,382 Jan-30-2020, 06:27 PM
Last Post: buran
  I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 2,337 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu
  Making a generalised CSV COPY script in Python Sandy7771989 3 2,459 Jul-05-2019, 11:02 PM
Last Post: Larz60+
  making the code easier, list comprehension go127a 2 2,084 May-26-2019, 06:19 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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