Drowning in a teacup?

2016-04-01 Thread Fillmore
notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. I need to scan a list of strings. If one of the elements matches the beginning of a search keyword, that element needs to snap to the front of the list. I achieved that this way: for i in

Re: Drowning in a teacup?

2016-04-01 Thread Rob Gaddi
Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. > > I need to scan a list of strings. If one of the elements matches the > beginning of a search keyword, that element needs to snap to the front > of the list. > I achieved t

Re: Drowning in a teacup?

2016-04-01 Thread MRAB
On 2016-04-01 21:27, Fillmore wrote: notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. I need to scan a list of strings. If one of the elements matches the beginning of a search keyword, that element needs to snap to the front of the list. I achie

Re: Drowning in a teacup?

2016-04-01 Thread Michael Selik
Give this a shot def snap(keyword, words): matches = [i for i, s in enumerate(words) if s.startswith(keyword)] for i in matches: lst.insert(0, lst.pop(i)) Your current implementation is reassigning the local variable ``mylist`` to a new list inside the function. O

Re: Drowning in a teacup?

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi wrote: > Fillmore wrote: >> Nope, wrong! contrary to what I thought I had understood about how >> parameters are passed in Python, the function is acting on a copy(!) and >> my original list is unchanged. >> > > Nope, that's not your problem. Your problem

Re: Drowning in a teacup?

2016-04-01 Thread Chris Kaynor
On Fri, Apr 1, 2016 at 1:52 PM, Ian Kelly wrote: > On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi > wrote: > > Fillmore wrote: > >> Nope, wrong! contrary to what I thought I had understood about how > >> parameters are passed in Python, the function is acting on a copy(!) and > >> my original list is

Re: Drowning in a teacup?

2016-04-01 Thread Ethan Furman
On 04/01/2016 01:27 PM, Fillmore wrote: notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. It's only notorious for folks that don't understand that Python uses neither. It also doesn't help when folks don't understand how name-binding works.

Re: Drowning in a teacup?

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 3:10 PM, Chris Kaynor wrote: > The overall algorithm is O(n^2), as its doing a O(n) operation in a O(n) > loop: Depends on whether the OP expects to find only one match or potentially multiple matches in the list. E did say "if one of the elements matches". If there are on

Re: Drowning in a teacup?

2016-04-01 Thread Mark Lawrence via Python-list
On 01/04/2016 21:27, Fillmore wrote: notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. It is pass by object. By definition your following analysis is wrong. To my knowledge this has been discussed at least twice a year for the past 15 years.

Re: Drowning in a teacup?

2016-04-01 Thread Steven D'Aprano
On Sat, 2 Apr 2016 07:27 am, Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. Python is NEITHER pass by reference nor pass by value. Please read this: http://import-that.dreamwidth.org/1130.html before asking any additiona

Re: Drowning in a teacup?

2016-04-01 Thread Fillmore
On 04/01/2016 04:27 PM, Fillmore wrote: notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. Many thanks to all of those who replied! -- https://mail.python.org/mailman/listinfo/python-list

Re: Drowning in a teacup?

2016-04-01 Thread Vito De Tullio
Fillmore wrote: > I need to scan a list of strings. If one of the elements matches the > beginning of a search keyword, that element needs to snap to the front > of the list. I know this post regards the function passing, but, on you specific problem, can't you just ... sort the list with a cust

Re: Drowning in a teacup?

2016-04-01 Thread Michael Selik
On Sat, Apr 2, 2016, 1:46 AM Vito De Tullio wrote: > Fillmore wrote: > > > I need to scan a list of strings. If one of the elements matches the > > beginning of a search keyword, that element needs to snap to the front > > of the list. > > I know this post regards the function passing, but, on yo

Re: Drowning in a teacup?

2016-04-01 Thread Vito De Tullio
Michael Selik wrote: >> > I need to scan a list of strings. If one of the elements matches the >> > beginning of a search keyword, that element needs to snap to the front >> > of the list. >> >> I know this post regards the function passing, but, on you specific >> problem, >> can't you just ... s

Re: Drowning in a teacup?

2016-04-02 Thread Peter Otten
Vito De Tullio wrote: > Michael Selik wrote: > >>> > I need to scan a list of strings. If one of the elements matches the >>> > beginning of a search keyword, that element needs to snap to the front >>> > of the list. >>> >>> I know this post regards the function passing, but, on you specific >>>

Re: Drowning in a teacup?

2016-04-02 Thread Mark Lawrence via Python-list
On 02/04/2016 06:51, Michael Selik wrote: On Sat, Apr 2, 2016, 1:46 AM Vito De Tullio wrote: Fillmore wrote: I need to scan a list of strings. If one of the elements matches the beginning of a search keyword, that element needs to snap to the front of the list. I know this post regards the

Re: Drowning in a teacup?

2016-04-02 Thread Michael Selik
On Sat, Apr 2, 2016 at 6:32 AM Peter Otten <__pete...@web.de> wrote: > Vito De Tullio wrote: > > > Michael Selik wrote: > > > >>> > I need to scan a list of strings. If one of the elements matches the > >>> > beginning of a search keyword, that element needs to snap to the > front > >>> > of the l

Re: Drowning in a teacup?

2016-04-02 Thread Ned Batchelder
On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. As others have pointed out, this is false dichotomy. There are other possibilities than pass by reference and pass by value. Python

Re: Drowning in a teacup?

2016-04-02 Thread Random832
On Sat, Apr 2, 2016, at 15:28, Ned Batchelder wrote: > On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > > here. Proceeding in order. > > As others have pointed out, this is false dichotomy. There are other

Re: Drowning in a teacup?

2016-04-02 Thread Ethan Furman
On 04/02/2016 12:54 PM, Random832 wrote: On Sat, Apr 2, 2016, at 15:28, Ned Batchelder wrote: On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. As others have pointed out, this is fal

Re: Drowning in a teacup?

2016-04-02 Thread Random832
On Sat, Apr 2, 2016, at 19:15, Ethan Furman wrote: > Also, if "pass-by-value" is being used, even mutation of the passed > object will not show up in the caller. I disagree. I don't think the definition of pass-by-value implies this. -- https://mail.python.org/mailman/listinfo/python-list

Re: Drowning in a teacup?

2016-04-02 Thread Steven D'Aprano
On Sun, 3 Apr 2016 05:54 am, Random832 wrote: > On Sat, Apr 2, 2016, at 15:28, Ned Batchelder wrote: >> On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: >> > notorious pass by reference vs pass by value biting me in the backside >> > here. Proceeding in order. >> >> As others have po