Re: list index out of range Error , need to fix it or ignore it

2016-02-28 Thread Oscar Benjamin
On 27 February 2016 at 16:50, Ganesh Pal wrote: > Iam on python 2.6 and Linux , I need input on the below program , > here is the spinet of my program It would be much better if you presented a complete program here. Otherwise the missing parts will confuse people. See: http://sscce.org/ > file

Re: list index out of range Error , need to fix it or ignore it

2016-02-28 Thread Steven D'Aprano
On Sun, 28 Feb 2016 03:50 am, Ganesh Pal wrote: > Iam on python 2.6 and Linux , I need input on the below program , > here is the spinet of my program > > > filename='/tmp2/2.txt' > > def check_file(): > """ > Run the command parallel on all the machines , if there is a > file named /

Re: list index out of range Error , need to fix it or ignore it

2016-02-28 Thread Ganesh Pal
>> > what is run(...) > The run (_ is a wrapper it uses suprocess.Popen and returns stdout ,error and extitcod e > not a good idea to have catchall exception how to fix this ? > >> > return False >> > if __name__ == '__main__': >> > main() >> > >> -- >> > copy and paste your tr

Re: list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Joel Goldstick
On Sat, Feb 27, 2016 at 12:01 PM, Ganesh Pal wrote: > changed baddr="" to file ="" in the example program , sorry for the typo > > > filename='/tmp2/2.txt' > > > > def check_file(): > don't use global filename. just pass filename into check_file def check_file(filename): > > """ > > R

Re: list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Ganesh Pal
changed baddr="" to file ="" in the example program , sorry for the typo > filename='/tmp2/2.txt' > > def check_file(): > """ > Run the command parallel on all the machines , if there is a > file named /tmp/file2.txt extract file2.txt > > """ > global filename > file = '' >

Re: List index out of range, but list has enough elements

2010-11-09 Thread Stefan Behnel
[rearranged the responses in the right order] Costin Gamenț, 09.11.2010 11:44: On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamenț wrote: On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: Costin Gamenț, 09.11.2010 10:24: Hi, I am trying to read a string as csv, but I encountered an odd problem.

Re: List index out of range, but list has enough elements

2010-11-09 Thread Costin Gamenț
Thank you all for your interest in my problem. As Peter pointed out, there was one row with zero elements in it and that's where my problem was (of course it was the very last row, hence my confidence I have "good" data). Have a nice one, Costin On Tue, Nov 9, 2010 at 12:02 PM, Nitin Pawar wrote

Re: List index out of range, but list has enough elements

2010-11-09 Thread Nitin Pawar
You may want to try a spilt if you are getting 8 different elements then it will give you a list of those elements On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamenț wrote: > Thank you for your timely response. Yes, I am sure "i" and "j" are > from the same iteration. I should point out that "i" actua

Re: List index out of range, but list has enough elements

2010-11-09 Thread Costin Gamenț
Thank you for your timely response. Yes, I am sure "i" and "j" are from the same iteration. I should point out that "i" actually has 8 elements and that str(i) gives a nice printout. On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: > Costin Gamenț, 09.11.2010 10:24: >> >> Hi, I am trying to

Re: List index out of range, but list has enough elements

2010-11-09 Thread Peter Otten
Costin Gamenț wrote: > Hi, I am trying to read a string as csv, but I encountered an odd > problem. Here's my code: > > csvfile = csv.reader(datastr.split('\n'), delimiter=';') > r = '' > for i in csvfile: > for j in i: > print j >

Re: List index out of range, but list has enough elements

2010-11-09 Thread Stefan Behnel
Costin Gamenț, 09.11.2010 10:24: Hi, I am trying to read a string as csv, but I encountered an odd problem. Here's my code: csvfile = csv.reader(datastr.split('\n'), delimiter=';') r = '' for i in csvfile: for j in i: print j

Re: list index out of range

2008-05-13 Thread Mike Kent
On May 13, 2:39 pm, Georgy Panterov <[EMAIL PROTECTED]> wrote: > > def deal_hand(deck): > HAND=[] > for _ in range(2): > i=random.randint(0,len(deck)) #produces a random card from the deck ^ Here i can be from 0 thru (the number of cards in the deck). > HAND.appen

Re: list index out of range

2008-05-13 Thread inhahe
random.randint(x,y) returns a random integer between _and including_ x and y, so randint(0, len(deck)) might return len(deck) and since python's indices start at 0, the maximum index is len(deck)-1. rather than using randint(0,len(deck)-1) you could just do card = random.choice(deck) HAND.append

Re: list index()

2007-09-04 Thread Steve Holden
TheFlyingDutchman wrote: >> I explain it by noting that list.index and dict.get serve totally >> different purposes. The former returns the index given a value; the >> latter returns a value given a key. > > And the former raises an exception if the value is not found, while > the latter returns N

Re: list index()

2007-09-04 Thread TheFlyingDutchman
> > I explain it by noting that list.index and dict.get serve totally > different purposes. The former returns the index given a value; the > latter returns a value given a key. And the former raises an exception if the value is not found, while the latter returns None if the value is not found.

Re: list index()

2007-09-04 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote: > It's probable that a simpler implementation using slice > operations will be faster for shortish lengths of subseq. It was > certainly easier to get it working correctly. ;) > > def find(seq, subseq): > for i, j in itertools.izip(xrange(len(seq)-len(sub

Re: list index()

2007-09-04 Thread Ben Finney
Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes: > In message <[EMAIL PROTECTED]>, > Jason wrote: > > > The reason why the exception is more Pythonic is that the return > > value is always a guaranteed good index into the list. > > How do you explain dict.get, then? I explain it by noting that l

Re: list index()

2007-09-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Jason wrote: > The reason why the exception is more Pythonic is that the return value > is always a guaranteed good index into the list. How do you explain dict.get, then? -- http://mail.python.org/mailman/listinfo/python-list

Re: list index()

2007-09-04 Thread Neil Cerutti
On 2007-09-04, Campbell Barton <[EMAIL PROTECTED]> wrote: > Jason wrote: >> Returning -1 is not a good return value to indicate an error. >> After all, -1 is a valid index in most Python lists. >> (Negative numbers index from the tail of the list.) > > Agree in general tho its a bit inconsistent ho

Re: list index()

2007-09-04 Thread Campbell Barton
Jason wrote: > On Aug 30, 1:27 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Thu, 30 Aug 2007 17:09:36 +1000, Ben Finney wrote: >>> [EMAIL PROTECTED] writes: What's with the index() function of lists throwing an exception on not found? >>> It's letting you know that the it

Re: list index()

2007-09-03 Thread Jason
On Aug 30, 1:27 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 30 Aug 2007 17:09:36 +1000, Ben Finney wrote: > > [EMAIL PROTECTED] writes: > > >> What's with the index() function of lists throwing an exception on not > >> found? > > > It's letting you know that the item isn't in

Re: list index()

2007-09-03 Thread Carsten Haese
On Mon, 03 Sep 2007 19:56:04 -0700, TheFlyingDutchman wrote > [...] my fork of Python 3, which I am > pleased to announce now, is called Python 3.01 while in development, > and will be known as Python 3000 or Python 3K when it gets to a productional > release. I hope you're joking. -Carsten --

Re: list index()

2007-09-03 Thread TheFlyingDutchman
> > Actually there was. The OP's claim > | There are a million situations where you can have an item not be in > | a list and it is not an exception situation. > > ...is just plain nonsense. zzbbaadd neither does understand exceptions > nor what they are used for in Python. An item not being in a

Re: list index()

2007-09-03 Thread Ben Finney
Thorsten Kampe <[EMAIL PROTECTED]> writes: > * Ben Finney (Thu, 30 Aug 2007 18:02:15 +1000) > > Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > > > What's with using your brain instead of whining ? > > > > Now now, no need for snappiness. > > Actually there was. The OP's claim [...] ...is just

Re: list index()

2007-09-03 Thread Thorsten Kampe
* Ben Finney (Thu, 30 Aug 2007 18:02:15 +1000) > Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > > What's with using your brain instead of whining ? > > Now now, no need for snappiness. Actually there was. The OP's claim | There are a million situations where you can have an item not be in | a

Re: list index()

2007-09-03 Thread Thorsten Kampe
* Terry Reedy (Fri, 31 Aug 2007 02:28:36 -0400) > "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | On Thu, 30 Aug 2007 17:09:36 +1000, Ben Finney wrote: > | > [EMAIL PROTECTED] writes: > | >> What's with the index() function of lists throwing an exceptio

Re: list index()

2007-09-02 Thread Francesco Guerrieri
On 9/2/07, Zentrader <[EMAIL PROTECTED]> wrote: > > On Aug 30, 11:23 am, [EMAIL PROTECTED] wrote: > > Neil, Steve, > > > > Thanks for the responses on sets. I have not used them before and was > > not even aware Python had them. I will try them out. > > And if there weren't sets you would still not

Re: list index()

2007-09-02 Thread Zentrader
On Aug 30, 11:23 am, [EMAIL PROTECTED] wrote: > Neil, Steve, > > Thanks for the responses on sets. I have not used them before and was > not even aware Python had them. I will try them out. And if there weren't sets you would still not use find or index but a brute force method or dictionaries for

Re: list index()

2007-09-01 Thread Alex Martelli
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Sat, 01 Sep 2007 13:44:28 -0600, Michael L Torrie wrote: > > > Alex Martelli wrote: > > > >> is the "one obvious way to do it" (the set(...) is just a simple and > >> powerful optimization -- checking membership in a set is roughly O(1), >

Re: list index()

2007-09-01 Thread Marc 'BlackJack' Rintsch
On Sat, 01 Sep 2007 13:37:29 -0600, Michael L Torrie wrote: > What's wrong, then, with doing: > > if i in list: >print list.index(i) If `i` is in the list this does the linear lookup twice. > If we were to program this .index() method in some language that > enforces contracts, like haskell

Re: list index()

2007-09-01 Thread Marc 'BlackJack' Rintsch
On Sat, 01 Sep 2007 13:44:28 -0600, Michael L Torrie wrote: > Alex Martelli wrote: > >> is the "one obvious way to do it" (the set(...) is just a simple and >> powerful optimization -- checking membership in a set is roughly O(1), >> while checking membership in a list of N items is O(N)...). >

Re: list index()

2007-09-01 Thread Michael L Torrie
Alex Martelli wrote: > is the "one obvious way to do it" (the set(...) is just a simple and > powerful optimization -- checking membership in a set is roughly O(1), > while checking membership in a list of N items is O(N)...). Depending on a how a set is stored, I'd estimate any membership check

Re: list index()

2007-09-01 Thread Michael L Torrie
[EMAIL PROTECTED] wrote: > In my case of have done os.listdir() on two directories. I want to see > what files are in directory A that are not in directory B. > I have used exceptions in other languages and only do so on logic that > should never happen. In this case it is known that some of the fi

Re: list index()

2007-09-01 Thread Nicko
On Aug 30, 7:00 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > You can also generate the files that are in one directory but ot the > other with > > (afiles | bfiles) - (afiles & bfiles) Or just (afiles ^ bfiles). Nicko -- (lambda f: lambda *a:f(f,*a))( lambda f,l,i:l[i][1]+f(f,l,l[i][0]

Re: list index() (OT)

2007-09-01 Thread Ricardo Aráoz
Steve Holden wrote: > Ricardo Aráoz wrote: >> Paddy wrote: >>> On Sep 1, 7:57 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: "Richie Hindle" wrote: > But - the word for someone who posts to the internet with the intention of > stirring up trouble derives from the word for what fi

Re: list index() (OT)

2007-09-01 Thread Steve Holden
Ricardo Aráoz wrote: > Paddy wrote: >> On Sep 1, 7:57 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: >>> "Richie Hindle" wrote: But - the word for someone who posts to the internet with the intention of stirring up trouble derives from the word for what fishermen do, not from t

Re: list index() (OT)

2007-09-01 Thread Ricardo Aráoz
Paddy wrote: > On Sep 1, 7:57 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: >> "Richie Hindle" wrote: >>> But - the word for someone who posts to the internet with the intention of >>> stirring up trouble derives from the word for what fishermen do, not from >>> the word for something that l

Re: list index() (OT)

2007-09-01 Thread Hendrik van Rooyen
"Steve Holden" wrote: > Where's Godwin's Law when yo need it? Hitler would not have spellt "you" like that... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list

Re: list index()

2007-09-01 Thread Hendrik van Rooyen
"Steve Holden" <[EMAIL PROTECTED]> wrote: > Paddy wrote: > > My accent is probably from the East Midlands of the UK, but is not > > pronounced. > > > If your accent isn't pronounced how do we know what it sounds like? > When he says pronounced, he doesn't mean pronounced, he means pronounced

Re: list index()

2007-09-01 Thread Steven D'Aprano
On Sat, 01 Sep 2007 17:23:04 +1000, Ben Finney wrote: > Dennis Lee Bieber <[EMAIL PROTECTED]> writes: > >> I suppose you also add an extra "i" to aluminum > > We're not out to rewrite the table of elements. There's no such thing as > "aluminum", and "aluminium" always has just the two "i"s. Al

Re: list index() (OT) and definitely trolling :-)

2007-09-01 Thread Paddy
On Sep 1, 7:32 am, Steve Holden <[EMAIL PROTECTED]> wrote: > Dennis Lee Bieber wrote: > > On Fri, 31 Aug 2007 21:15:10 +0100, DaveM <[EMAIL PROTECTED]> > > declaimed the following in comp.lang.python: > > >> No - but I would pronounce "lever" and "fever" the same way, if that helps. > > > To me

Re: list index() (OT)

2007-09-01 Thread Paddy
On Sep 1, 7:57 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Richie Hindle" wrote: > > But - the word for someone who posts to the internet with the intention of > > stirring up trouble derives from the word for what fishermen do, not from > > the word for something that lives under a bri

Re: list index()

2007-09-01 Thread Ben Finney
Dennis Lee Bieber <[EMAIL PROTECTED]> writes: > I suppose you also add an extra "i" to aluminum We're not out to rewrite the table of elements. There's no such thing as "aluminum", and "aluminium" always has just the two "i"s. -- \ "Rightful liberty is unobstructed action, according

Re: list index() (OT)

2007-09-01 Thread Steve Holden
Hendrik van Rooyen wrote: > "Richie Hindle" wrote: > >> But - the word for someone who posts to the internet with the intention of >> stirring up trouble derives from the word for what fishermen do, not from >> the word for something that lives under a bridge. It derives from "trolling >> for su

Re: list index() (OT)

2007-08-31 Thread Hendrik van Rooyen
"Richie Hindle" wrote: > But - the word for someone who posts to the internet with the intention of > stirring up trouble derives from the word for what fishermen do, not from > the word for something that lives under a bridge. It derives from "trolling > for suckers" or "trolling for newbies".

Re: list index()

2007-08-31 Thread Hendrik van Rooyen
"Paddy" wrote: > > I say the 'oll' in troll like the 'ol' in frolic, and pronounce roll > and role similarly. > > My accent is probably from the East Midlands of the UK, but is not > pronounced. Same here - when the Troll lives under a bridge - I could not think of something to rhyme with it -

Re: list index()

2007-08-31 Thread Steve Holden
Dennis Lee Bieber wrote: > On Fri, 31 Aug 2007 21:15:10 +0100, DaveM <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > >> No - but I would pronounce "lever" and "fever" the same way, if that helps. >> >To me, those are different... I suppose you also add an > extra "i

Re: list index()

2007-08-31 Thread Hendrik van Rooyen
"Erik Max Francis" wrote: > Hendrik van Rooyen wrote: > > > weird this - maybe a native English speaker can comment - > > when I pronounce what fishermen do - it rhymes with roll, > > but when I am talking about the thing that lives under bridges > > and munches goats, the "O" sound is shorte

Re: list index()

2007-08-31 Thread Carsten Haese
On Sat, 2007-09-01 at 13:50 +1200, Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Carsten > Haese wrote: > > has_key() will go away, period. It has been made obsolete by "in", which > > is faster and more concise. > > And is also a backdoor way of introducing non-virtual methods into

Re: list index()

2007-08-31 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Carsten Haese wrote: > On Thu, 2007-08-30 at 11:21 -0700, [EMAIL PROTECTED] wrote: > >> I wish they were not >> getting rid of dict.has_key() in Python 3, which I prefer to IN. > > That wish will only come true if you maintain your own fork of Python 3. > has_key()

Re: list index()

2007-08-31 Thread DaveM
On Fri, 31 Aug 2007 02:37:15 -0700, Erik Max Francis <[EMAIL PROTECTED]> wrote: >_Troll_ and _frolic_ aren't pronounced with the same "o" sound in any >accent I've ever heard of. You've never heard an English accent then. >Which you pronounce _boat_ and _bot_ the same way, too? No - but I wo

Re: list index()

2007-08-31 Thread Steve Holden
Alex Martelli wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >... >> Why wouldn't "the one obvious way" be: >> >> def inAnotB(A, B): >> inA = set(os.listdir(A)) >> inBs = set(os.listdir(B)) >> return inA.difference(inBs) > > If you want a set as the result, that's one p

Re: list index()

2007-08-31 Thread Steve Holden
Paddy wrote: > On Aug 31, 8:47 am, Erik Max Francis <[EMAIL PROTECTED]> wrote: >> Hendrik van Rooyen wrote: >>> weird this - maybe a native English speaker can comment - >>> when I pronounce what fishermen do - it rhymes with roll, >>> but when I am talking about the thing that lives under bridges

troll vs. trawl [was: Re: list index()]

2007-08-31 Thread David Naughton
On Fri, Aug 31, 2007 at 10:27:34AM +0100, Richie Hindle wrote: > > [Carsten] > > .. If we start labeling > > people, this thread will earn you a label that rhymes with "roll". > > [Hendrik] > > weird this - maybe a native English speaker can comment - > > when I pronounce what fi

Re: list index()

2007-08-31 Thread MRAB
On Aug 31, 11:05 am, Jon Ribbens <[EMAIL PROTECTED]> wrote: > On 2007-08-31, Erik Max Francis <[EMAIL PROTECTED]> wrote: > > >> I say the 'oll' in troll like the 'ol' in frolic, and pronounce roll > >> and role similarly. > > >> My accent is probably from the East Midlands of the UK, but is not > >

Re: list index()

2007-08-31 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > Why wouldn't "the one obvious way" be: > > def inAnotB(A, B): > inA = set(os.listdir(A)) > inBs = set(os.listdir(B)) > return inA.difference(inBs) If you want a set as the result, that's one possibility (although possibly a bi

Re: list index()

2007-08-31 Thread BJörn Lindqvist
On 8/30/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > Is the Pythonic way > > try: > i = somelist.index(thing) > # Do something with i > except IndexError: > # Do something if thing not found That is not the Pythonic way. "# Do something with i" might also raise an IndexError and they

Re: list index()

2007-08-31 Thread TheFlyingDutchman
> > Fair enough, but that's a tutorial. It would be foolish to demand that a > tutorial be a complete reference for everything that can be done with a list. I wasn't demanding anything of the page. I was pointing out how I made the assumption there was no way to find out if a list has a value oth

Re: list index()

2007-08-31 Thread Carsten Haese
On Thu, 30 Aug 2007 21:33:43 -0700, TheFlyingDutchman wrote > On Aug 30, 9:06 pm, "Carsten Haese" <[EMAIL PROTECTED]> wrote: > > On Thu, 30 Aug 2007 20:17:00 -0700, zzbbaadd wrote > > > > > Well IN was what I was looking for and would have saved this thread. > > > However I don't believe IN showed

Re: list index()

2007-08-31 Thread Richie Hindle
[Carsten] > .. If we start labeling > people, this thread will earn you a label that rhymes with "roll". [Hendrik] > weird this - maybe a native English speaker can comment - > when I pronounce what fishermen do - it rhymes with roll, > but when I am talking about the thing that

Re: list index()

2007-08-31 Thread Jon Ribbens
On 2007-08-31, Erik Max Francis <[EMAIL PROTECTED]> wrote: >> I say the 'oll' in troll like the 'ol' in frolic, and pronounce roll >> and role similarly. >> >> My accent is probably from the East Midlands of the UK, but is not >> pronounced. > > _Troll_ and _frolic_ aren't pronounced with the same

Re: list index()

2007-08-31 Thread Tim Golden
Erik Max Francis wrote: > Paddy wrote: > >> I say the 'oll' in troll like the 'ol' in frolic, and pronounce roll >> and role similarly. >> >> My accent is probably from the East Midlands of the UK, but is not >> pronounced. > > _Troll_ and _frolic_ aren't pronounced with the same "o" sound in any

Re: list index()

2007-08-31 Thread Erik Max Francis
Paddy wrote: > I say the 'oll' in troll like the 'ol' in frolic, and pronounce roll > and role similarly. > > My accent is probably from the East Midlands of the UK, but is not > pronounced. _Troll_ and _frolic_ aren't pronounced with the same "o" sound in any accent I've ever heard of. Which y

Re: list index()

2007-08-31 Thread Paddy
On Aug 31, 8:47 am, Erik Max Francis <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen wrote: > > weird this - maybe a native English speaker can comment - > > when I pronounce what fishermen do - it rhymes with roll, > > but when I am talking about the thing that lives under bridges > > and munches

Re: list index()

2007-08-31 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip) > I don't think that is the definition used across computer science. > > It suddenly dawned on me that what would be best would be a contains() > (or IN syntax for those who can't afford to wait) for lists. No need to wait: >>> 'a' in ['a', 'b'] True >>> ['a'

Re: list index()

2007-08-31 Thread Erik Max Francis
Hendrik van Rooyen wrote: > weird this - maybe a native English speaker can comment - > when I pronounce what fishermen do - it rhymes with roll, > but when I am talking about the thing that lives under bridges > and munches goats, the "O" sound is shorter, and more > towards the back of my mout

Re: list index()

2007-08-31 Thread Hendrik van Rooyen
"Carsten Haese" wrote: > .. If we start labeling > people, this thread will earn you a label that rhymes with "roll". weird this - maybe a native English speaker can comment - when I pronounce what fishermen do - it rhymes with roll, but when I am talking about the thing that li

Re: list index()

2007-08-31 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Aug 30, 4:28 pm, Ben Finney <[EMAIL PROTECTED]> > wrote: >> [EMAIL PROTECTED] writes: >>> On Aug 30, 12:09 am, Ben Finney <[EMAIL PROTECTED]> >>> wrote: It's letting you know that the item isn't in the list. There's no sensible return value from an "index"

Re: list index()

2007-08-30 Thread Terry Reedy
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Thu, 30 Aug 2007 17:09:36 +1000, Ben Finney wrote: | | > [EMAIL PROTECTED] writes: | > | >> What's with the index() function of lists throwing an exception on not | >> found? | > | > It's letting you know

Re: list index()

2007-08-30 Thread TheFlyingDutchman
On Aug 30, 9:06 pm, "Carsten Haese" <[EMAIL PROTECTED]> wrote: > On Thu, 30 Aug 2007 20:17:00 -0700, zzbbaadd wrote > > > Well IN was what I was looking for and would have saved this thread. > > However I don't believe IN showed up on the doc web page that has > > list methods, where I found index(

Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 30 Aug 2007 20:06:38 -0700, zzbbaadd wrote > On Aug 30, 4:48 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > > > It suddenly dawned on me that what would be best would be a contains() > > > (or IN syntax for those who can't afford to wait) for lists. > > > > > if mylist.contains("hello): >

Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 30 Aug 2007 20:17:00 -0700, zzbbaadd wrote > Well IN was what I was looking for and would have saved this thread. > However I don't believe IN showed up on the doc web page that has > list methods, where I found index(). They're not on the exact same page, but index() is in section 3.6.4

Re: list index()

2007-08-30 Thread [EMAIL PROTECTED]
On Aug 30, 9:26 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > <[EMAIL PROTECTED]> wrote: > >... > > > In my case of have done os.listdir() on two directories. I want to see > > what files are in directory A that are not in directory B. > > So why would you care about WHERE, in the listdir of B

Re: list index()

2007-08-30 Thread zzbbaadd
> Either I'm misunderstanding what you mean or you need to get a clue > about what Python can already do before you go around making suggestions > for what Python needs. Lists have supported "in" tests since at least > version 1.5.2: > Well IN was what I was looking for and would have saved this t

Re: list index()

2007-08-30 Thread zzbbaadd
On Aug 30, 4:48 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On 8/30/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > On Aug 30, 4:31 pm, Ben Finney <[EMAIL PROTECTED]> > > wrote: > > > [EMAIL PROTECTED] writes: > > > > In my case of have done os.listdir() on two directories. I want to

Re: list index()

2007-08-30 Thread Alex Martelli
Ricardo Aráoz <[EMAIL PROTECTED]> wrote: ... > Alex Martelli wrote: > > <[EMAIL PROTECTED]> wrote: > >... > >> In my case of have done os.listdir() on two directories. I want to see > >> what files are in directory A that are not in directory B. > > > > So why would you care about WHERE, in

Re: list index()

2007-08-30 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Ben Finney wrote: > [EMAIL PROTECTED] writes: > >> What's with the index() function of lists throwing an exception on not >> found? > > It's letting you know that the item isn't in the list. There's no > sensible return value from an "index" function in that condi

Re: list index()

2007-08-30 Thread Ricardo Aráoz
Alex Martelli wrote: > <[EMAIL PROTECTED]> wrote: >... >> In my case of have done os.listdir() on two directories. I want to see >> what files are in directory A that are not in directory B. > > So why would you care about WHERE, in the listdir of B, are to be found > the files that are in A b

Re: list index()

2007-08-30 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: ... > In my case of have done os.listdir() on two directories. I want to see > what files are in directory A that are not in directory B. So why would you care about WHERE, in the listdir of B, are to be found the files that are in A but not B?! You should call .inde

Re: list index()

2007-08-30 Thread Carsten Haese
On Fri, 2007-08-31 at 12:57 +1200, Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Steve > Holden wrote: > > > But why would you want to ignore built-in support like "value in dict"? > > Because a function can be passed as a value in its own right, a built-in > construct cannot. ...

Re: list index()

2007-08-30 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steve Holden wrote: > But why would you want to ignore built-in support like "value in dict"? Because a function can be passed as a value in its own right, a built-in construct cannot. -- http://mail.python.org/mailman/listinfo/python-list

Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 16:42 -0700, [EMAIL PROTECTED] wrote: > It suddenly dawned on me that what would be best would be a contains() > (or IN syntax for those who can't afford to wait) for lists. Either I'm misunderstanding what you mean or you need to get a clue about what Python can already do b

Re: list index()

2007-08-30 Thread Chris Mellon
On 8/30/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > On Aug 30, 4:31 pm, Ben Finney <[EMAIL PROTECTED]> > wrote: > > [EMAIL PROTECTED] writes: > > > In my case of have done os.listdir() on two directories. I want to see > > > what files are in directory A that are not in directory B. > > > >

Re: list index()

2007-08-30 Thread zzbbaadd
On Aug 30, 4:31 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > In my case of have done os.listdir() on two directories. I want to see > > what files are in directory A that are not in directory B. > > You get that information unambiguously. It's an exceptional case, > sin

Re: list index()

2007-08-30 Thread zzbbaadd
On Aug 30, 4:28 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > On Aug 30, 12:09 am, Ben Finney <[EMAIL PROTECTED]> > > wrote: > > > It's letting you know that the item isn't in the list. There's no > > > sensible return value from an "index" function in that condition. >

Re: list index()

2007-08-30 Thread Ben Finney
[EMAIL PROTECTED] writes: > In my case of have done os.listdir() on two directories. I want to see > what files are in directory A that are not in directory B. You get that information unambiguously. It's an exceptional case, since there's no index to return, so it throws an exception. > I have

Re: list index()

2007-08-30 Thread Ben Finney
[EMAIL PROTECTED] writes: > On Aug 30, 12:09 am, Ben Finney <[EMAIL PROTECTED]> > wrote: > > It's letting you know that the item isn't in the list. There's no > > sensible return value from an "index" function in that condition. > > for str: > find( sub[, start[, end]]) > [...] > Return -

Re: list index()

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 09:41:00 -0700, zzbbaadd wrote: > On Aug 30, 12:09 am, Ben Finney <[EMAIL PROTECTED]> > wrote: >> [EMAIL PROTECTED] writes: >> > What's with the index() function of lists throwing an exception on not >> > found? >> >> It's letting you know that the item isn't in the list. There

Re: list index()

2007-08-30 Thread MRAB
On Aug 30, 5:41 pm, [EMAIL PROTECTED] wrote: > On Aug 30, 12:09 am, Ben Finney <[EMAIL PROTECTED]> > wrote: > > > [EMAIL PROTECTED] writes: > > > What's with the index() function of lists throwing an exception on not > > > found? > > > It's letting you know that the item isn't in the list. There's

Re: list index()

2007-08-30 Thread MRAB
On Aug 30, 7:00 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> How could it not be an exception, in the plain English sense of the > >> word? Most certainly you're asking for the index because you want to do > >> something with the index. If the item is not found, you h

Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 11:45 -0700, [EMAIL PROTECTED] wrote: > > That wish will only come true if you maintain your own fork of Python 3. > > has_key() will go away, period. It has been made obsolete by "in", which > > is faster and more concise. > > Is there really some reason "key" IN dict can b

Re: list index()

2007-08-30 Thread Chris Mellon
On 8/30/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > That wish will only come true if you maintain your own fork of Python 3. > > has_key() will go away, period. It has been made obsolete by "in", which > > is faster and more concise. > > Is there really some reason "key" IN dict can be

Re: list index()

2007-08-30 Thread Neil Cerutti
On 2007-08-30, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> That wish will only come true if you maintain your own fork of >> Python 3. has_key() will go away, period. It has been made >> obsolete by "in", which is faster and more concise. > > Is there really some reason "key" IN dict can be im

Re: list index()

2007-08-30 Thread zzbbaadd
> That wish will only come true if you maintain your own fork of Python 3. > has_key() will go away, period. It has been made obsolete by "in", which > is faster and more concise. Is there really some reason "key" IN dict can be implemented faster than dict.has_key("key")??? -- http://mail.p

Re: list index()

2007-08-30 Thread Steve Holden
[EMAIL PROTECTED] wrote: >> While I agree that Bruno's response was perhaps needlessly snippy, your >> original question was needlessly inflammatory, as if you somehow wanted >> some "religious zealot" to act the way Bruno did. If we start labeling >> people, this thread will earn you a label that

Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 11:21 -0700, [EMAIL PROTECTED] wrote: > I wish they were not > getting rid of dict.has_key() in Python 3, which I prefer to IN. That wish will only come true if you maintain your own fork of Python 3. has_key() will go away, period. It has been made obsolete by "in", which is

Re: list index()

2007-08-30 Thread zzbbaadd
Neil, Steve, Thanks for the responses on sets. I have not used them before and was not even aware Python had them. I will try them out. -- http://mail.python.org/mailman/listinfo/python-list

Re: list index()

2007-08-30 Thread zzbbaadd
> While I agree that Bruno's response was perhaps needlessly snippy, your > original question was needlessly inflammatory, as if you somehow wanted > some "religious zealot" to act the way Bruno did. If we start labeling > people, this thread will earn you a label that rhymes with "roll". > That is

RE: list index()

2007-08-30 Thread Hamilton, William
> From: [EMAIL PROTECTED] > > > > How could it not be an exception, in the plain English sense of the > > word? Most certainly you're asking for the index because you want to do > > something with the index. If the item is not found, you have no index, > > so that's a special case that must be hand

Re: list index()

2007-08-30 Thread Neil Cerutti
On 2007-08-30, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> How could it not be an exception, in the plain English sense >> of the word? Most certainly you're asking for the index >> because you want to do something with the index. If the item >> is not found, you have no index, so that's a spec

  1   2   >