Re: Empty list as a default param - the problem, and my suggested solution

2021-08-14 Thread Martin Di Paola
On Fri, Aug 13, 2021 at 03:44:20PM -0700, guruyaya wrote: I am fairly sure all of us know about this python quirk: def no_new_func(a=[]): ...a.append('new') ...return a no_new_func() ['new'] no_new_func() ['new', 'new'] For some tim

Empty list as a default param - the problem, and my suggested solution

2021-08-13 Thread guruyaya
I am fairly sure all of us know about this python quirk: >>> def no_new_func(a=[]): ...a.append('new') ...return a >>> no_new_func() ['new'] >>> no_new_func() ['new', 'new'] >>> For some time I was bother

Re: Empty List

2016-06-27 Thread Pierre-Alain Dorange
Elizabeth Weiss wrote: > What is the point of this code?: > > word=[] > print(word) > > The result is [] > > When would I need to use something like this? You often need to intialize a list, sometime with (empty) = []. Then after initializing you should do "something" that perhaps will fill

Re: Empty List

2016-06-26 Thread Christopher Reimer
On 6/26/2016 8:13 PM, Elizabeth Weiss wrote: Hi There, What is the point of this code?: word=[] print(word) The result is [] When would I need to use something like this? Thank you! Sometimes you need to assign an empty list to a variable prior to using it in a looping structure

Re: Empty List

2016-06-26 Thread Steven D'Aprano
ord = [] This creates a variable, "word", and assigns an empty list to it. But once you have an empty list, you can start putting things into it. Once you have a list with items in it, there are all sorts of things you can usefully do: - append items to the end; - insert items at the s

Empty List

2016-06-26 Thread Elizabeth Weiss
Hi There, What is the point of this code?: word=[] print(word) The result is [] When would I need to use something like this? Thank you! -- https://mail.python.org/mailman/listinfo/python-list

Re: IndexError: pop from empty list

2014-05-16 Thread Peter Otten
ch...@freeranger.com wrote: > No, that was pretty much what I was looking for. If anyone has an answer > to the deeper question, that would be icing on the cake. > > What is interesting is that usually the traceback shows the line of code > that I invoke which, deep inside a library I'm using, h

Re: IndexError: pop from empty list

2014-05-15 Thread Steven D'Aprano
On Thu, 15 May 2014 21:36:49 -0700, chris wrote: > Any ideas about what this might mean? [jumping ahead] > digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) > IndexError: pop from empty list sample_bytes is an empty list. Or it could be a list with just a

Re: IndexError: pop from empty list

2014-05-15 Thread chris
; _split_response > > > info[parse_rule[0]] = parse_rule[1](self, info) > > >File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in > > > > > lambda xbee,original: xbee._parse_samples(original['samples']) >

Re: IndexError: pop from empty list

2014-05-15 Thread Gary Herron
, in _parse_samples digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) IndexError: pop from empty list The error means that sample_bytes is an empty list so calling pop is an error. Or were you asking something deeper, like *why* sample_bytes is an empty list? Gary Herron -- https://mail.python.org/mailman/listinfo/python-list

IndexError: pop from empty list

2014-05-15 Thread chris
t;/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in lambda xbee,original: xbee._parse_samples(original['samples']) File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in _parse_samples digital_data_set = (sample_bytes.pop(0) &

Python module Code returns empty list any ideas how to fix

2010-08-19 Thread Andrew Evans
Hello I am trying to modify Python xgoogle module to use yahoo I have hit a road block where I receive no error messages the code I use to test just returns an empty list. and I don't know how to trouble shoot it the module code is here http://pastebin.com/iTibRs1R and the code I am usi

Re: Testing for empty list

2009-12-24 Thread Benjamin Kaplan
On Thu, Dec 24, 2009 at 11:56 PM, Rodrick Brown wrote: p=[] if p is None: > ...   print 'yes' > ... > This doesn't work as expected. That probably means that what you expect is wrong. >>>p = [] # p is now a list object at a certain location >>> if p is None: #check to see if p (a l

Testing for empty list

2009-12-24 Thread Rodrick Brown
>>> p=[] >>> if p is None: ... print 'yes' ... >>> This doesn't work as expected. -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -- http://mail.python.org/mailman/listinfo/python-list

Re: initializing with empty list as default causes freaky problems

2009-07-28 Thread Luis Alberto Zarrabeitia Gomez
Quoting Reckoner : > Hi, > > Observe the following: > > In [202]: class Foo(): >.: def __init__(self,h=[]): >.: self.h=h [...] > In [207]: f.h.append(10) > > In [208]: f.h > Out[208]: [10] > > In [209]: g.h > Out[209]: [10] > > The question is: why is g.h updated

Re: initializing with empty list as default causes freaky problems

2009-07-27 Thread Gary Herron
Reckoner wrote: Hi, Observe the following: In [202]: class Foo(): .: def __init__(self,h=[]): .: self.h=h .: .: In [203]: f=Foo() In [204]: g=Foo() In [205]: g.h Out[205]: [] In [206]: f.h Out[206]: [] In [207]: f.h.append(10) In [208]: f.h Out[208]

Re: initializing with empty list as default causes freaky problems

2009-07-27 Thread Benjamin Kaplan
On Mon, Jul 27, 2009 at 1:40 PM, Reckoner wrote: > Hi, > > Observe the following: > > In [202]: class Foo(): >   .:     def __init__(self,h=[]): >   .:         self.h=h >   .: >   .: > > In [203]: f=Foo() > > In [204]: g=Foo() > > In [205]: g.h > Out[205]: [] > > In [206]: f.h > Out

Re: initializing with empty list as default causes freaky problems

2009-07-27 Thread MRAB
Reckoner wrote: Hi, X-Antispam: NO; Spamcatcher 5.2.1. Score 50 Observe the following: In [202]: class Foo(): .: def __init__(self,h=[]): .: self.h=h .: .: In [203]: f=Foo() In [204]: g=Foo() In [205]: g.h Out[205]: [] In [206]: f.h Out[206]: [] In [

initializing with empty list as default causes freaky problems

2009-07-27 Thread Reckoner
Hi, Observe the following: In [202]: class Foo(): .: def __init__(self,h=[]): .: self.h=h .: .: In [203]: f=Foo() In [204]: g=Foo() In [205]: g.h Out[205]: [] In [206]: f.h Out[206]: [] In [207]: f.h.append(10) In [208]: f.h Out[208]: [10] In [209]:

Re: What way is the best to check an empty list?

2009-03-26 Thread Niklas Norrthon
On 26 Mar, 08:18, Niklas Norrthon wrote: > But that can easily be achieved with the "or" operator as Michiel > Overton notes elsewhere in this thread: Michiel Overtoom was what I meant to write. My apologies! > def some_function(arg, coll=None): >     do_stuff(arg) >     for item in coll or []:

Re: What way is the best to check an empty list?

2009-03-26 Thread Niklas Norrthon
On 26 Mar, 04:31, Steve Holden wrote: > Stef Mientki wrote: > > > Now it would be nice to allow iteration over others too, like None . > >    a = None > >    for item in a : > >          do_something_with_item > > To me that makes about as much sense as writing > >     for x in 1.0: >         prin

Re: What way is the best to check an empty list?

2009-03-25 Thread Steven D'Aprano
On Wed, 25 Mar 2009 21:26:10 +, Martin P. Hellwig wrote: > Raymond Hettinger wrote: >> On Mar 25, 7:38 am, srinivasan srinivas >> wrote: >>> For ex: to check list 'A' is empty or not.. if A == []: >>> if A.count == 0: >>> if len(A) == 0: >>> if not A: ... > Personally I would go for the len

Re: What way is the best to check an empty list?

2009-03-25 Thread Steve Holden
Stef Mientki wrote: > andrew cooke wrote: >> Andre Engels wrote: >> >>> On Wed, Mar 25, 2009 at 4:21 PM, andrew cooke wrote: >>> i will go against the grain slightly and say that "len" is probably the best compromise in most situations (although i admit i don't know what

Re: What way is the best to check an empty list?

2009-03-25 Thread Josh Dukes
I believe "if not A:" is the most pythonic, but depending on what you're doing a list might not be the right thing to use at all. A little while ago I got some help from this malining list in dealing with a situation where lists really were not efficient (finding prime numbers...for fun). In my cas

What way is the best to check an empty list?

2009-03-25 Thread srinivasan srinivas
For ex: to check list 'A' is empty or not.. if A == []: if A.count == 0: if len(A) == 0: if not A: Connect with friends all over the world. Get Yahoo! India Messenger at http://in.messenger.yahoo.com/?wm=n/ -- http://mail.python.org/mailman/listinfo/python-list

Re: What way is the best to check an empty list?

2009-03-25 Thread Carl Banks
On Mar 25, 7:38 am, srinivasan srinivas wrote: > For ex: to check list 'A' is empty or not.. > if A == []: > if A.count == 0: > if len(A) == 0: > if not A: PEP 8 recommends the last one, and most Pythonistas here probably would as well, so that is probably what you should do if you don't otherwis

Re: What way is the best to check an empty list?

2009-03-25 Thread Carl Banks
On Mar 25, 8:27 am, Andre Engels wrote: > On Wed, Mar 25, 2009 at 4:21 PM, andrew cooke wrote: > > > but i may be wrong - are there any containers (apart from pathological > > hand-crafted examples) that would not define __len__()? > > When writing my answer, I thought of generators, but I now fi

Re: What way is the best to check an empty list?

2009-03-25 Thread Carl Banks
On Mar 25, 1:19 pm, "andrew cooke" wrote: > actually, the implication of what you said is probably worth emphasising > to the original poster: often you don't need to test whether a list is > empty or not, you simply iterate over its contents: > >   for x in foo: >     # do something > > this will

Re: What way is the best to check an empty list?

2009-03-25 Thread Martin P. Hellwig
Albert Hopkins wrote: On Wed, 2009-03-25 at 21:26 +, Martin P. Hellwig wrote: PEP 8 recommends the latter. Raymond I can't seem to find where this recommendation is mentioned or implied. Wow, you must not have looked very hard: 1. Point your browser to http://www.python.org/dev/pe

Re: What way is the best to check an empty list?

2009-03-25 Thread Michiel Overtoom
On 25 Mar 2009, at 21:29 , Stef Mientki wrote: Now it would be nice to allow iteration over others too, like None . a = None for item in a : do_something_with_item I saw this technique used in CherryPy: >>> a=None >>> for item in a or []: ...print item ... >>> a=[1,2,3]

Re: What way is the best to check an empty list?

2009-03-25 Thread Albert Hopkins
On Wed, 2009-03-25 at 21:26 +, Martin P. Hellwig wrote: > > > > PEP 8 recommends the latter. > > > > > > Raymond > I can't seem to find where this recommendation is mentioned or implied. Wow, you must not have looked very hard: 1. Point your browser to http://www.python.org/dev/peps/p

Re: What way is the best to check an empty list?

2009-03-25 Thread andrew cooke
Martin P. Hellwig wrote: > Raymond Hettinger wrote: >> On Mar 25, 7:38 am, srinivasan srinivas >> wrote: >>> if not A: >> PEP 8 recommends the latter. > I can't seem to find where this recommendation is mentioned or implied. it's the next-to-last sub-item, just before the references. http://www.p

Re: What way is the best to check an empty list?

2009-03-25 Thread Martin P. Hellwig
Raymond Hettinger wrote: On Mar 25, 7:38 am, srinivasan srinivas wrote: For ex: to check list 'A' is empty or not.. if A == []: if A.count == 0: if len(A) == 0: if not A: PEP 8 recommends the latter. Raymond I can't seem to find where this recommendation is mentioned or implied. Personall

Re: What way is the best to check an empty list?

2009-03-25 Thread Stef Mientki
andrew cooke wrote: Andre Engels wrote: On Wed, Mar 25, 2009 at 4:21 PM, andrew cooke wrote: i will go against the grain slightly and say that "len" is probably the best compromise in most situations (although i admit i don't know what [...] but i may be wrong - are there a

Re: What way is the best to check an empty list?

2009-03-25 Thread andrew cooke
Andre Engels wrote: > On Wed, Mar 25, 2009 at 4:21 PM, andrew cooke wrote: >> i will go against the grain slightly and say that "len" is probably the >> best compromise in most situations (although i admit i don't know what [...] >> but i may be wrong - are there any containers (apart from patholo

Re: What way is the best to check an empty list?

2009-03-25 Thread Raymond Hettinger
On Mar 25, 7:38 am, srinivasan srinivas wrote: > For ex: to check list 'A' is empty or not.. > if A == []: > if A.count == 0: > if len(A) == 0: > if not A: PEP 8 recommends the latter. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: What way is the best to check an empty list?

2009-03-25 Thread John Machin
On Mar 26, 2:21 am, "andrew cooke" wrote: > i will go against the grain slightly and say that "len" is probably the > best compromise in most situations (although i admit i don't know what > count is) because i think it will work when you expect it to and break > when you have a bug in your progra

Re: What way is the best to check an empty list?

2009-03-25 Thread Andre Engels
On Wed, Mar 25, 2009 at 4:21 PM, andrew cooke wrote: > > i will go against the grain slightly and say that "len" is probably the > best compromise in most situations (although i admit i don't know what > count is) because i think it will work when you expect it to and break > when you have a bug i

Re: What way is the best to check an empty list?

2009-03-25 Thread andrew cooke
i will go against the grain slightly and say that "len" is probably the best compromise in most situations (although i admit i don't know what count is) because i think it will work when you expect it to and break when you have a bug in your program. using a simple boolean is more robust (and wha

Re: What way is the best to check an empty list?

2009-03-25 Thread John Machin
On Mar 26, 1:38 am, srinivasan srinivas wrote: Depends on what you mean by "best"; like graduation day at kindergarten, everyone gets a prize: > For ex: to check list 'A' is empty or not.. > if A == []: most obviously correct > if A.count == 0: best use of imagination > if len(A) == 0: best

Re: What way is the best to check an empty list?

2009-03-25 Thread bearophileHUGS
srinivasan srinivas: > For ex: to check list 'A' is empty or not.. Empty collections are "false": if somelist: ... # somelist isn't empty else: ... # somelist is empty Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: What way is the best to check an empty list?

2009-03-25 Thread Tim Chase
srinivasan srinivas wrote: For ex: to check list 'A' is empty or not.. if A == []: if A.count == 0: if len(A) == 0: if not A: "if not A" -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: What way is the best to check an empty list?

2009-03-25 Thread Andre Engels
On Wed, Mar 25, 2009 at 3:38 PM, srinivasan srinivas wrote: > > For ex: to check list 'A' is empty or not.. > if A == []: > if A.count == 0: > if len(A) == 0: > if not A: I would go for the last one, because it has the highest likelihood of doing what is intended when fed with something that is '

What way is the best to check an empty list?

2009-03-25 Thread srinivasan srinivas
For ex: to check list 'A' is empty or not.. if A == []: if A.count == 0: if len(A) == 0: if not A: Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Why does way_1() obtain the correct list but way_2() gets an empty list?

2009-02-12 Thread Gabriel Genellina
En Thu, 12 Feb 2009 07:07:53 -0200, WP escribió: Hello group! This is probably a silly newbie mistake but consider the following program: import libsbml def getSBMLModel(biomodel_path): reader = libsbml.SBMLReader() sbml_doc = reader.readSBML(biomodel_path) sbml_model = No

Re: Why does way_1() obtain the correct list but way_2() gets an empty list?

2009-02-12 Thread Bruno Desthuilliers
WP a écrit : Hello group! This is probably a silly newbie mistake but consider the following program: import libsbml def getSBMLModel(biomodel_path): reader = libsbml.SBMLReader() sbml_doc = reader.readSBML(biomodel_path) sbml_model = None if sbml_doc.getNumErrors() > 0:

Why does way_1() obtain the correct list but way_2() gets an empty list?

2009-02-12 Thread WP
Hello group! This is probably a silly newbie mistake but consider the following program: import libsbml def getSBMLModel(biomodel_path): reader = libsbml.SBMLReader() sbml_doc = reader.readSBML(biomodel_path) sbml_model = None if sbml_doc.getNumErrors() > 0: print 'I c

Re: Testing for an empty list

2008-07-03 Thread Roy Smith
; . > . > . > It's also perfectly legitimate--and arguably even more > precise--to write > > if funList == []: > do_something() Any of these will be true for an empty list and false for a non-empty

Re: Testing for an empty list

2008-07-03 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Matthew Fitzgibbons <[EMAIL PROTECTED]> wrote: >Alexnb wrote: >> Okay this is a simple question I just don't know how. If I have a list, say: >> >> funList = [] >> >> and after a while something possible should have been appended to it, but >> wasn't. How can I te

Re: Testing for an empty list

2008-07-03 Thread Matthew Fitzgibbons
Alexnb wrote: Okay this is a simple question I just don't know how. If I have a list, say: funList = [] and after a while something possible should have been appended to it, but wasn't. How can I test if that list is empty. if not funList: do_something() -Matt -- http://mail.python.o

Testing for an empty list

2008-07-03 Thread Alexnb
Okay this is a simple question I just don't know how. If I have a list, say: funList = [] and after a while something possible should have been appended to it, but wasn't. How can I test if that list is empty. -- View this message in context: http://www.nabble.com/Testing-for-an-

Re: behavior varied between empty string '' and empty list []

2008-03-24 Thread Gabriel Genellina
En Mon, 24 Mar 2008 15:22:43 -0300, Tzury Bar Yochay <[EMAIL PROTECTED]> escribió: > while I can invoke methods of empty string '' right in typing > (''.join(), etc.) I can't do the same with empty list > > example: > >>>> a = [1,2,3

behavior varied between empty string '' and empty list []

2008-03-24 Thread Tzury Bar Yochay
while I can invoke methods of empty string '' right in typing (''.join(), etc.) I can't do the same with empty list example: >>> a = [1,2,3] >>> b = [].extend(a) >>> b >>> b = [] >>> b.extend(a) >>> b [1,2,3] I woul

Re: Glob returning an empty list when passed a variable

2007-02-10 Thread MRAB
On Feb 10, 8:32 am, Steve Holden <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > On Fri, 09 Feb 2007 14:15:51 +, Steve Holden wrote: > > >> area_name_string = '*% s*' % (Area_name) > > >> Interesting, I never realised until now that you can have spaces between > >> the percent sign and

Re: Glob returning an empty list when passed a variable

2007-02-10 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > With some number: > > In [2]: "% 3s" % 'a' > Out[2]: ' a' The space still doesn't have any effect here: In [66]: "%3s" % 'a' Out[66]: ' a' Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Glob returning an empty list when passed a variable

2007-02-10 Thread [EMAIL PROTECTED]
On Feb 10, 3:32 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > > >>> "% s" % 'banana' > 'banana' > >>> "% s" % 1 > '1' > >>> "% s" % -1 > '-1' > >>> > With some number: In [2]: "% 3s" % 'a' Out[2]: ' a' Hieu -- http://mail.python.org/mailman/listinfo/python-list

Re: Glob returning an empty list when passed a variable

2007-02-10 Thread Steve Holden
Steven D'Aprano wrote: > On Fri, 09 Feb 2007 14:15:51 +, Steve Holden wrote: > >> area_name_string = '*% s*' % (Area_name) >> >> Interesting, I never realised until now that you can have spaces between >> the percent sign and th format effector. > > Space is one of the flags. From the docs:

Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Steven D'Aprano
On Fri, 09 Feb 2007 14:15:51 +, Steve Holden wrote: > area_name_string = '*% s*' % (Area_name) > > Interesting, I never realised until now that you can have spaces between > the percent sign and th format effector. Space is one of the flags. From the docs: The conversion flag characters a

Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Neil Webster
On 9 Feb, 14:15, Steve Holden <[EMAIL PROTECTED]> wrote: > Neil Webster wrote: > > Hi, > > > I was wondering whether anybody could help me out. > > > I have a program, for part of it I am trying to pass a variable to a > > glob function, this returns an empty

Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Steve Holden
Neil Webster wrote: > Hi, > > I was wondering whether anybody could help me out. > > I have a program, for part of it I am trying to pass a variable to a > glob function, this returns an empty list. The strange thing is when > I hard code in the variable the glob sec

Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Philipp Pagel
Neil Webster <[EMAIL PROTECTED]> wrote: > area_name_string = '"*% s*"' % (Area_name) > os.chdir(Input) > filename = glob.glob(area_name_string) Too many quotation marks. >>> Area_name='Foo' >>> '"*% s*"' % (Area_name) '"*Foo*"' Unless there are files with funny names containing '"' you will not

Glob returning an empty list when passed a variable

2007-02-09 Thread Neil Webster
Hi, I was wondering whether anybody could help me out. I have a program, for part of it I am trying to pass a variable to a glob function, this returns an empty list. The strange thing is when I hard code in the variable the glob section works. Does anybody have any ideas as why it is not

Re: any() and all() on empty list?

2006-04-10 Thread Piet van Oostrum
> "Steve R. Hastings" <[EMAIL PROTECTED]> (SRH) wrote: [snip] >SRH> vowels = frozenset("aeiouAEIOU") >SRH> f = open("a_file.txt") # note that f is an iterator >SRH> counts = tally(line[0] in vowels for line in f) tally([line[0] in vowels for line in f]) >SRH> # counts is a dict; counts.keys

Re: any() and all() on empty list?

2006-04-01 Thread Ron Adam
Ron Adam wrote: > Steve R. Hastings wrote: >> This neatly replaces truecount(), and you can use it for other things as >> well. > > if True in talley(S): do_somthing() > > Works for me... ;-) > > > Cheers, > Ron Actulley talley isn't needed for this... if True in S: do_domething

Re: any() and all() on empty list?

2006-04-01 Thread Ron Adam
Steve R. Hastings wrote: > On Sat, 01 Apr 2006 14:35:58 -0300, Felipe Almeida Lessa wrote: >> Two changes: >> - Use "is None". >> - Use "try ... except" instead of "in" > > Yes. > > >> Maybe you don't like my version, and the gains aren't that much, but >> please use "is None" instead of "== N

Re: any() and all() on empty list?

2006-04-01 Thread Ron Adam
Steve R. Hastings wrote: > Here is a function called "tally()". It reduces a list to a dictionary > of counts, with one key for each value from the list. The value for > each key is the count of how many times it appeared in the list. > > > def tally(seq, d=None): > if d == None: >

Re: any() and all() on empty list?

2006-04-01 Thread Steve R. Hastings
On Sat, 01 Apr 2006 14:35:58 -0300, Felipe Almeida Lessa wrote: > Two changes: > - Use "is None". > - Use "try ... except" instead of "in" Yes. > Maybe you don't like my version, and the gains aren't that much, but > please use "is None" instead of "== None". Actually, I do like your version.

Re: any() and all() on empty list?

2006-04-01 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-01 às 08:35 -0800, Steve R. Hastings escreveu: > def tally(seq, d=None): > if d == None: > d = {} > > for x in seq: > if x in d: > d[x] += 1 > else: > d[x] = 1 > return d Two changes: - Use "is None". - Use "try ... ex

Re: any() and all() on empty list?

2006-04-01 Thread Steve R. Hastings
On Sat, 01 Apr 2006 00:38:08 -0800, Steve R. Hastings wrote: > my proposed truecount() returns a tuple, with the length and > the count of true values. I never liked the name truecount(), and the more I think about it, the less I like the function. It should either solve a very important need, or

Re: any() and all() on empty list?

2006-04-01 Thread Steve R. Hastings
On Sat, 01 Apr 2006 02:06:29 -0600, Ron Adam wrote: > true_count, count = countall(S), len(S) Unfortunately, this does not solve the problem. An iterator yields its values only once. If you have an iterator "itr", you cannot do all(itr) and then do len(itr). Whichever one you do first will

Re: any() and all() on empty list?

2006-04-01 Thread Paul Rubin
Ron Adam <[EMAIL PROTECTED]> writes: > true_count, count = countall(S), len(S) In general it's preferable to not rely on len being available, since these are arbitrary iterators. -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-04-01 Thread Ron Adam
Steve R. Hastings wrote: > On Fri, 31 Mar 2006 16:29:00 -0800, Paul Rubin wrote: >> I think "S and all(S)" is the right way to express that, if that's >> what's intended. > > I still would like a standard function, because "S and all(S)" does not > work with iterators. I proposed one possible fun

Re: any() and all() on empty list?

2006-03-31 Thread Steve R. Hastings
On Fri, 31 Mar 2006 16:29:00 -0800, Paul Rubin wrote: > I think "S and all(S)" is the right way to express that, if that's > what's intended. I still would like a standard function, because "S and all(S)" does not work with iterators. I proposed one possible function, truecount(S), that returns a

Re: any() and all() on empty list?

2006-03-31 Thread Paul Rubin
Ron Adam <[EMAIL PROTECTED]> writes: > The 'not not S' is just a conversion to bool. Is the following less > contorted to you? > > >>> bool([]) > False Oh ok. Yes, bool(S) is much less contorted than "not not S". > 'Is all True' isn't the same as 'Has all True'. As I said, I'm not > questioni

Re: any() and all() on empty list?

2006-03-31 Thread Ant
lol! -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-03-31 Thread Ron Adam
Carl Banks wrote: > Ron Adam wrote: >> Carl Banks wrote: >> >>> In Python, yes and no are the only possible answers. Probably the only >>> analogous thing you could do in Python would be for all() to raise >>> ValueError when passed an empty sequence. >> There is also 'None' which serves a similar

Re: any() and all() on empty list?

2006-03-31 Thread Carl Banks
Ron Adam wrote: > Carl Banks wrote: > > > In Python, yes and no are the only possible answers. Probably the only > > analogous thing you could do in Python would be for all() to raise > > ValueError when passed an empty sequence. > > There is also 'None' which serves a similar purpose of indicati

Re: any() and all() on empty list?

2006-03-31 Thread Gerard Flanagan
t; Comments? Ant wrote: > all(list) simply means "every element of the list evaluates to True". > This is trivially true in the case of the empty list. This is logically > equivalent to "There are no elements in the list which evaluate to > False". > > any(list) si

Re: any() and all() on empty list?

2006-03-31 Thread Ant
I don't think that there will be any valid examples. all(list) simply means "every element of the list evaluates to True". This is trivially true in the case of the empty list. This is logically equivalent to "There are no elements in the list which evaluate to False". a

Re: any() and all() on empty list?

2006-03-31 Thread Antoon Pardon
Op 2006-03-30, Paul McGuire schreef <[EMAIL PROTECTED]>: > > "Antoon Pardon" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Op 2006-03-30, Steven D'Aprano schreef <[EMAIL PROTECTED]>: >> >> > So, these flying elephants -- are they pink or not? >> >> They are both. >> > > That woul

Re: any() and all() on empty list?

2006-03-30 Thread Fredrik Lundh
Alex Martelli wrote: > > >>>all(flying elephants which are not pink) => true > > >>> > > >>>So, these flying elephants -- are they pink or not? > > >> > > >> No, you ask two different sets whether they are true. > > > > > > No, there is only one empty set. > > > > who said anything about empty set

Re: any() and all() on empty list?

2006-03-30 Thread Ron Adam
Carl Banks wrote: > In Python, yes and no are the only possible answers. Probably the only > analogous thing you could do in Python would be for all() to raise > ValueError when passed an empty sequence. There is also 'None' which serves a similar purpose of indicating an invalid value when pas

Re: any() and all() on empty list?

2006-03-30 Thread Alex Martelli
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Marcin Ciura wrote: > > >>>all(flying elephants which are not pink) => true > >>> > >>>So, these flying elephants -- are they pink or not? > >> > >> No, you ask two different sets whether they are true. > > > > No, there is only one empty set. > > who s

Re: any() and all() on empty list?

2006-03-30 Thread Carl Banks
Steven D'Aprano wrote: > On Thu, 30 Mar 2006 11:28:54 -0800, Paul Rubin wrote: > > > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >> > No, all(seq) is true if you can't point to a specific element in seq > >> > that's false. > >> > >> No, all(seq) is true if every element in seq is true. Surely th

Re: any() and all() on empty list?

2006-03-30 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > >> No, all(seq) is true if every element in seq is true. Surely that's a > >> more intuitive definition than your definition by what you can't do. > > They are different? > Of course they are different -- they differ in the case of an empty > sequence

Re: any() and all() on empty list?

2006-03-30 Thread Steven D'Aprano
ere neither True nor False is correct. In hacker culture, the Chinese word "mu" (literally "without") is sometimes used to mean "I cannot answer that question because your assumptions are not correct". In the case of all(seq), the correct answer is "mu". But since we're stuck with binary logic, the more commonly useful behaviour is True, but sometimes that leads to problems, such as in my first example of Guido being punished because he was found guilty of all the terrorist crimes he committed -- which is an empty list. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-03-30 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > > No, all(seq) is true if you can't point to a specific element in seq > > that's false. > > No, all(seq) is true if every element in seq is true. Surely that's a > more intuitive definition than your definition by what you can't do. They are differen

Re: any() and all() on empty list?

2006-03-30 Thread Paul McGuire
"Antoon Pardon" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Op 2006-03-30, Steven D'Aprano schreef <[EMAIL PROTECTED]>: > > > So, these flying elephants -- are they pink or not? > > They are both. > That would make them Schrödinger elephants! -- Paul -- http://mail.python.or

Re: any() and all() on empty list?

2006-03-30 Thread Antoon Pardon
Op 2006-03-30, Steven D'Aprano schreef <[EMAIL PROTECTED]>: > Paul Rubin wrote: > >> Steven D'Aprano <[EMAIL PROTECTED]> writes: >> >>>Think of it this way: if all(seq) is true, shouldn't it be the case >>>that you can point to a specific element in seq that is true? >> >> >> No, all(seq) is tru

Re: any() and all() on empty list?

2006-03-30 Thread Fredrik Lundh
Marcin Ciura wrote: >>>all(flying elephants which are not pink) => true >>> >>>So, these flying elephants -- are they pink or not? >> >> No, you ask two different sets whether they are true. > > No, there is only one empty set. who said anything about empty sets ? -- http://mail.python.org

Re: any() and all() on empty list?

2006-03-30 Thread Marcin Ciura
Georg Brandl wrote: > Steven D'Aprano wrote: >>all(flying elephants which are pink) => true >>all(flying elephants which are not pink) => true >> >>So, these flying elephants -- are they pink or not? > > No, you ask two different sets whether they are true. No, there is only one empty set. Releva

Re: any() and all() on empty list?

2006-03-30 Thread Ron Adam
Ron Adam wrote: > > hasall(S, True, lambda n: n=42) > That was suppose to be: hasall(S, True, lambda n: n==42) -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-03-30 Thread Ron Adam
Steven D'Aprano wrote: > Paul Rubin wrote: > >> Steven D'Aprano <[EMAIL PROTECTED]> writes: >> >>> Think of it this way: if all(seq) is true, shouldn't it be the case >>> that you can point to a specific element in seq that is true? >> >> >> No, all(seq) is true if you can't point to a specific el

Re: any() and all() on empty list?

2006-03-30 Thread Ron Adam
Duncan Booth wrote: > Ron Adam wrote: > >> Where we are assembling widgets in a manufacturing plant. Where we don't >> want to go to the next step until *all* the sub parts are present. >> >> if all(part.status == 'present' for part in unit): >> do_release() >> >> Oops! Some empty bins show

Re: any() and all() on empty list?

2006-03-30 Thread Georg Brandl
Steven D'Aprano wrote: > Paul Rubin wrote: > >> Steven D'Aprano <[EMAIL PROTECTED]> writes: >> >>>Think of it this way: if all(seq) is true, shouldn't it be the case >>>that you can point to a specific element in seq that is true? >> >> >> No, all(seq) is true if you can't point to a specific e

Re: any() and all() on empty list?

2006-03-30 Thread Peter Otten
Steven D'Aprano wrote: > Okay, Ron's example wasn't the best. How about this > one, from chess: > > The intention is to play cautiously if all threatened > pieces are valuable, and daringly otherwise. Isn't that example even worse? Compare: - You have one of your valuable pieces threatened. You

Re: any() and all() on empty list?

2006-03-30 Thread Carl Banks
Steven D'Aprano wrote: > Paul Rubin wrote: > > > Steven D'Aprano <[EMAIL PROTECTED]> writes: > > > >>Think of it this way: if all(seq) is true, shouldn't it be the case > >>that you can point to a specific element in seq that is true? > > > > > > No, all(seq) is true if you can't point to a specif

Re: any() and all() on empty list?

2006-03-30 Thread Steven D'Aprano
Duncan Booth wrote: > Ron Adam wrote: > > >>Where we are assembling widgets in a manufacturing plant. Where we don't >>want to go to the next step until *all* the sub parts are present. >> >>if all(part.status == 'present' for part in unit): >> do_release() >> >>Oops! Some empty bins showe

Re: any() and all() on empty list?

2006-03-30 Thread Steven D'Aprano
Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >>Think of it this way: if all(seq) is true, shouldn't it be the case >>that you can point to a specific element in seq that is true? > > > No, all(seq) is true if you can't point to a specific element in seq > that's false. No,

Re: any() and all() on empty list?

2006-03-30 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Think of it this way: if all(seq) is true, shouldn't it be the case > that you can point to a specific element in seq that is true? No, all(seq) is true if you can't point to a specific element in seq that's false. -- http://mail.python.org/mailman/li

  1   2   >