From raubvogel at gmail.com Wed Aug 11 10:38:11 2021 From: raubvogel at gmail.com (Mauricio Tavares) Date: Wed, 11 Aug 2021 10:38:11 -0400 Subject: [TriPython] Editing a list in a function Message-ID: Thought process question: I have a list I want to massage a list def massage_list(thelist): # Do things inputlist = [...] If I want to preserve the original list, would it be more logical if 1. massage_list() returns new list. If you want the output to be applied to inputlist, you have to do something like inputlist = massage_list(inputlist) 2. You create a new list which is a deepcopy() of inputlist, and then feed it to massage_list() I am leaning towards #1 (function creates things which are returned) but if #2 makes more sense, do let me know before I go too far. From aikimark at aol.com Wed Aug 11 12:31:01 2021 From: aikimark at aol.com (Mark Hutchinson) Date: Wed, 11 Aug 2021 16:31:01 +0000 (UTC) Subject: [TriPython] Editing a list in a function In-Reply-To: References: Message-ID: <1643990101.1973422.1628699461822@mail.yahoo.com> Once your function begins to 'alter' the input list parameter, it becomes a new list.? Unless your function uses the Global?keyword to refer to the variable in the code outside the function. Mark -------------- next part -------------- Once your function begins to 'alter' the input list parameter, it becomes a new list. Unless your function uses the Global keyword to refer to the variable in the code outside the function. Mark From ironfroggy at gmail.com Wed Aug 11 13:31:51 2021 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 11 Aug 2021 13:31:51 -0400 Subject: [TriPython] Editing a list in a function In-Reply-To: <1643990101.1973422.1628699461822@mail.yahoo.com> References: <1643990101.1973422.1628699461822@mail.yahoo.com> Message-ID: On Wed, Aug 11, 2021 at 12:31 PM Mark Hutchinson via TriZPUG < trizpug at python.org> wrote: > Once your function begins to 'alter' the input list parameter, it > becomes > a new list. Unless your function uses the Global keyword to refer to > the > variable in the code outside the function. > Mark > This is absolutely not true. Lists are mutable, modifying them is a mutation of the original list. > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://hub.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy -------------- next part -------------- On Wed, Aug 11, 2021 at 12:31 PM Mark Hutchinson via TriZPUG <[1]trizpug at python.org> wrote: ** **Once your function begins to 'alter' the input list parameter, it becomes ** **a new list.** Unless your function uses the Global keyword to refer to the ** **variable in the code outside the function. ** **Mark This is absolutely not true. Lists are mutable, modifying them is a mutation of the original list. ** _______________________________________________ TriZPUG mailing list [2]TriZPUG at python.org [3]https://mail.python.org/mailman/listinfo/trizpug [4]http://tripython.org is the Triangle Python Users Group -- Read my blog! I depend on your acceptance of my opinion! I am interesting! [5]http://hub.ironfroggy.com/ Follow me if you're into that sort of thing: [6]http://www.twitter.com/ironfroggy References Visible links 1. mailto:trizpug at python.org 2. mailto:TriZPUG at python.org 3. https://mail.python.org/mailman/listinfo/trizpug 4. http://tripython.org/ 5. http://hub.ironfroggy.com/ 6. http://www.twitter.com/ironfroggy From david at handysoftware.com Wed Aug 11 13:27:49 2021 From: david at handysoftware.com (David Handy) Date: Wed, 11 Aug 2021 13:27:49 -0400 Subject: [TriPython] Editing a list in a function In-Reply-To: References: Message-ID: On 8/11/21 10:38 AM, Mauricio Tavares wrote: > Thought process question: I have a list I want to massage a list > > def massage_list(thelist): > # Do things > > inputlist = [...] > > If I want to preserve the original list, would it be more logical if > > 1. massage_list() returns new list. If you want the output to be > applied to inputlist, you have to do something like > > inputlist = massage_list(inputlist) This is the recommended approach. It is better for functions to not mutate their parameters. That general principle makes it easier to understand the program and not have bugs due to side effects. > > 2. You create a new list which is a deepcopy() of inputlist, and then > feed it to massage_list() > > I am leaning towards #1 (function creates things which are returned) > but if #2 makes more sense, do let me know before I go too far. > _______________________________________________ From aikimark at aol.com Wed Aug 11 20:58:44 2021 From: aikimark at aol.com (Mark Hutchinson) Date: Thu, 12 Aug 2021 00:58:44 +0000 (UTC) Subject: [TriPython] Editing a list in a function In-Reply-To: References: <1643990101.1973422.1628699461822@mail.yahoo.com> Message-ID: <646856846.41224.1628729924207@mail.yahoo.com> Oops.? My bad. Thanks for the catch/correction, Calvin. Mark -----Original Message----- From: Calvin Spealman To: Mark Hutchinson ; Triangle (North Carolina) Python Users Group (formerly TriZPUG) Sent: Wed, Aug 11, 2021 1:31 pm Subject: Re: [TriPython] Editing a list in a function On Wed, Aug 11, 2021 at 12:31 PM Mark Hutchinson via TriZPUG wrote: ? ?Once your function begins to 'alter' the input list parameter, it becomes ? ?a new list.? Unless your function uses the Global keyword to refer to the ? ?variable in the code outside the function. ? ?Mark This is absolutely not true. Lists are mutable, modifying them is a mutation of the original list. ? _______________________________________________ TriZPUG mailing list TriZPUG at python.org https://mail.python.org/mailman/listinfo/trizpug http://tripython.org is the Triangle Python Users Group -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://hub.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy -------------- next part -------------- Oops. My bad. Thanks for the catch/correction, Calvin. Mark -----Original Message----- From: Calvin Spealman To: Mark Hutchinson ; Triangle (North Carolina) Python Users Group (formerly TriZPUG) Sent: Wed, Aug 11, 2021 1:31 pm Subject: Re: [TriPython] Editing a list in a function On Wed, Aug 11, 2021 at 12:31 PM Mark Hutchinson via TriZPUG <[1]trizpug at python.org> wrote: Once your function begins to 'alter' the input list parameter, it becomes a new list. Unless your function uses the Global keyword to refer to the variable in the code outside the function. Mark This is absolutely not true. Lists are mutable, modifying them is a mutation of the original list. _______________________________________________ TriZPUG mailing list [2]TriZPUG at python.org [3]https://mail.python.org/mailman/listinfo/trizpug [4]http://tripython.org is the Triangle Python Users Group -- Read my blog! I depend on your acceptance of my opinion! I am interesting! [5]http://hub.ironfroggy.com/ Follow me if you're into that sort of thing: [6]http://www.twitter.com/ironfroggy References Visible links 1. mailto:trizpug at python.org 2. mailto:TriZPUG at python.org 3. https://mail.python.org/mailman/listinfo/trizpug 4. http://tripython.org/ 5. http://hub.ironfroggy.com/ 6. http://www.twitter.com/ironfroggy From rexadwyer at gmail.com Thu Aug 12 07:23:57 2021 From: rexadwyer at gmail.com (Rex Dwyer) Date: Thu, 12 Aug 2021 07:23:57 -0400 Subject: [TriPython] Massaging list In-Reply-To: References: Message-ID: #1. It?s rare to need to explicitly copy a list. Are you transforming each element of the list? Consider using map(f,lis). On Wed, Aug 11, 2021 at 12:00 PM wrote: > Send TriZPUG mailing list submissions to > trizpug at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/trizpug > or, via email, send a message with subject or body 'help' to > trizpug-request at python.org > > You can reach the person managing the list at > trizpug-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of TriZPUG digest..." > Today's Topics: > > 1. Editing a list in a function (Mauricio Tavares) > > > > ---------- Forwarded message ---------- > From: Mauricio Tavares > To: "Triangle (North Carolina) Python Users Group (formerly TriZPUG)" < > TriZPUG at python.org> > Cc: > Bcc: > Date: Wed, 11 Aug 2021 10:38:11 -0400 > Subject: [TriPython] Editing a list in a function > Thought process question: I have a list I want to massage a list > > def massage_list(thelist): > # Do things > > inputlist = [...] > > If I want to preserve the original list, would it be more logical if > > 1. massage_list() returns new list. If you want the output to be > applied to inputlist, you have to do something like > > inputlist = massage_list(inputlist) > > 2. You create a new list which is a deepcopy() of inputlist, and then > feed it to massage_list() > > I am leaning towards #1 (function creates things which are returned) > but if #2 makes more sense, do let me know before I go too far. > > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > -- Rex A. Dwyer -------------- next part -------------- #1.** It***s rare to need to explicitly copy a list. Are you transforming each element of the list? Consider using map(f,lis). On Wed, Aug 11, 2021 at 12:00 PM <[1]trizpug-request at python.org> wrote: Send TriZPUG mailing list submissions to ** ** ** ** [2]trizpug at python.org To subscribe or unsubscribe via the World Wide Web, visit ** ** ** ** [3]https://mail.python.org/mailman/listinfo/trizpug or, via email, send a message with subject or body 'help' to ** ** ** ** [4]trizpug-request at python.org You can reach the person managing the list at ** ** ** ** [5]trizpug-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of TriZPUG digest..." Today's Topics: ** **1. Editing a list in a function (Mauricio Tavares) ---------- Forwarded message ---------- From:**Mauricio Tavares <[6]raubvogel at gmail.com> To:**"Triangle (North Carolina) Python Users Group (formerly TriZPUG)" <[7]TriZPUG at python.org> Cc:** Bcc:** Date:**Wed, 11 Aug 2021 10:38:11 -0400 Subject:**[TriPython] Editing a list in a function Thought process question: I have a list I want to massage a list def massage_list(thelist): ** ** # Do things inputlist = [...] If I want to preserve the original list, would it be more logical if 1. massage_list() returns new list. If you want the output to be applied to inputlist, you have to do something like inputlist = massage_list(inputlist) 2. You create a new list which is a deepcopy() of inputlist, and then feed it to massage_list() I am leaning towards #1 (function creates things which are returned) but if #2 makes more sense, do let me know before I go too far. _______________________________________________ TriZPUG mailing list [8]TriZPUG at python.org [9]https://mail.python.org/mailman/listinfo/trizpug [10]http://tripython.org is the Triangle Python Users Group -- Rex A. Dwyer References Visible links 1. mailto:trizpug-request at python.org 2. mailto:trizpug at python.org 3. https://mail.python.org/mailman/listinfo/trizpug 4. mailto:trizpug-request at python.org 5. mailto:trizpug-owner at python.org 6. mailto:raubvogel at gmail.com 7. mailto:TriZPUG at python.org 8. mailto:TriZPUG at python.org 9. https://mail.python.org/mailman/listinfo/trizpug 10. http://tripython.org/ From francois.dion at gmail.com Tue Aug 24 20:40:00 2021 From: francois.dion at gmail.com (Francois Dion) Date: Tue, 24 Aug 2021 20:40:00 -0400 Subject: [TriPython] Lunch and learn series Message-ID: <5BA699F3-B557-4596-A4F2-434CFEB5B66F@gmail.com> So, i?m doing a lunch and learn series on python online. It is starting at the beginning next week: what is python, how to install it etc. This first one might be a bit basic for most, but you might learn something just the same? it is under the PYPTUG meetup, but it is easy to join if you are already on meetup. The actual presentation will be on zoom. Might evaluate twitch too in the future. Lunch and learn #1: what is python and install https://meetu.ps/e/KkwMy/3PhvH/i Francois Dion -------------- next part -------------- So, i'm doing a lunch and learn series on python online. It is starting at the beginning next week: what is python, how to install it etc. This first one might be a bit basic for most, but you might learn something just the same... it is under the PYPTUG meetup, but it is easy to join if you are already on meetup. The actual presentation will be on zoom. Might evaluate twitch too in the future. Lunch and learn #1: what is python and install [1]https://meetu.ps/e/KkwMy/3PhvH/i Francois Dion References Visible links 1. https://meetu.ps/e/KkwMy/3PhvH/i