Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-09 Thread Cousin Stanley
Caledonian26 wrote: > However, I keep getting the error: > > IndexError: list index out of range. > > Could anyone give me a helping hand > as to where I am going wrong? > I appended a single arbitrary value for limits since the limits list ha

Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread DL Neil via Python-list
On 8/06/20 10:38 AM, MRAB wrote: On 2020-06-07 23:24, DL Neil via Python-list wrote: On 8/06/20 7:06 AM, Caledonian26 wrote: ... However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? When things go wrong

Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread MRAB
On 2020-06-07 23:24, DL Neil via Python-list wrote: On 8/06/20 7:06 AM, Caledonian26 wrote: ... However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? When things go wrong, Python tries to be helpful by

Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread DL Neil via Python-list
On 8/06/20 7:06 AM, Caledonian26 wrote: ... However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? When things go wrong, Python tries to be helpful by providing a "traceback". Please copy-paste

Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread Caledonian26
larMappable(cmap=cmap, norm=norm) plt.gcf().colorbar(sm) plt.show() 4. Here, a different colour is assigned to each bar in the bar chart depending on the values in the column 'colourofbars'. I then try to plot a legend showing this colour gradient scale. However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? -- https://mail.python.org/mailman/listinfo/python-list

Re: What's an elegant way to test for list index existing?

2018-09-30 Thread Alister via Python-list
On Sun, 30 Sep 2018 11:45:21 +0100, Bart wrote: > On 30/09/2018 11:14, Chris Green wrote: >> Chris Angelico wrote: >>> On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote: I have a list created by:- fld = shlex.split(ln) It may contain 3, 4 or 5 entries accordin

Re: What's an elegant way to test for list index existing?

2018-09-30 Thread Chris Green
Bart wrote: > On 30/09/2018 11:14, Chris Green wrote: > > Chris Angelico wrote: > >> On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote: > >>> > >>> I have a list created by:- > >>> > >>> fld = shlex.split(ln) > >>> > >>> It may contain 3, 4 or 5 entries according to data read into ln. > >>

Re: What's an elegant way to test for list index existing?

2018-09-30 Thread Chris Green
Chris Angelico wrote: > On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote: > > > > I have a list created by:- > > > > fld = shlex.split(ln) > > > > It may contain 3, 4 or 5 entries according to data read into ln. > > What's the neatest way of setting the fourth and fifth entries to an > > em

Re: What's an elegant way to test for list index existing?

2018-09-30 Thread Chris Green
Glen D souza wrote: > i have a approach, it may not be best > > fld = [ ] > for data in shlex.split(ln): >fld.append(data) > It's certainly simple! :-) I (OP) have actually done something quite similar:- fld = shlex.split(ln) fld.append(999) fld.append(999) It means I can

Re: What's an elegant way to test for list index existing?

2018-09-30 Thread Peter Otten
Glen D souza wrote: > fld = [ ] > data = shlex.split(ln) > for item in data: >fld.append(item) > fld = fld + [0] * (5 - len(data)) There's no need to make a copy of data, one item at the time. It's a tedious way to build a new list, and you are throwing it away in the next line anyway, a

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Glen D souza
i have a approach, it may not be best fld = [ ] for data in shlex.split(ln): fld.append(data) On Sat, 29 Sep 2018 at 07:52, wrote: > On Friday, September 28, 2018 at 11:03:17 AM UTC-7, Chris Green wrote: > > I have a list created by:- > > > > fld = shlex.split(ln) > > > > It may co

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Glen D souza
fld = [ ] data = shlex.split(ln) for item in data: fld.append(item) fld = fld + [0] * (5 - len(data)) On Sat, 29 Sep 2018 at 11:03, Glen D souza wrote: > i have a approach, it may not be best > > fld = [ ] > for data in shlex.split(ln): >fld.append(data) > > > > On Sat, 29 Sep 20

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Chris Angelico
On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote: > > I have a list created by:- > > fld = shlex.split(ln) > > It may contain 3, 4 or 5 entries according to data read into ln. > What's the neatest way of setting the fourth and fifth entries to an > empty string if they don't (yet) exist? Usi

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Alister via Python-list
On Fri, 28 Sep 2018 19:00:29 +0100, Chris Green wrote: > I have a list created by:- > > fld = shlex.split(ln) > > It may contain 3, 4 or 5 entries according to data read into ln. What's > the neatest way of setting the fourth and fifth entries to an empty > string if they don't (yet) exist?

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Dan Sommers
On 9/28/18 2:00 PM, Chris Green wrote: I have a list created by:- fld = shlex.split(ln) It may contain 3, 4 or 5 entries according to data read into ln. What's the neatest way of setting the fourth and fifth entries to an empty string if they don't (yet) exist? Using 'if len(fld) < 4:' fee

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Peter Otten
Ben Finney wrote: > Ben Finney writes: > >> You can use a comprehension, iterating over the full range of index you >> want:: >> >> words = shlex.split(line) >> padding_length = 5 >> words_padded = [ >> (words[index] if index < len(words)) >> for index in range(paddin

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Ben Finney
Ben Finney writes: > You can use a comprehension, iterating over the full range of index you > want:: > > words = shlex.split(line) > padding_length = 5 > words_padded = [ > (words[index] if index < len(words)) > for index in range(padding_length)] That omits the impo

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Chris Green
Thanks all, several possible ways of doing it there. -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Peter Otten
jlada...@itu.edu wrote: > On Friday, September 28, 2018 at 11:03:17 AM UTC-7, Chris Green wrote: >> I have a list created by:- >> >> fld = shlex.split(ln) >> >> It may contain 3, 4 or 5 entries according to data read into ln. >> What's the neatest way of setting the fourth and fifth entries

Re: What's an elegant way to test for list index existing?

2018-09-28 Thread Ben Finney
Chris Green writes: > I have a list created by:- > > fld = shlex.split(ln) > > It may contain 3, 4 or 5 entries according to data read into ln. Because of what an index means for the 'list' type, that's equivalent to saying "the result of `len(fld)` may be 3, 4, or 5". > What's the neatest

What's an elegant way to test for list index existing?

2018-09-28 Thread Chris Green
I have a list created by:- fld = shlex.split(ln) It may contain 3, 4 or 5 entries according to data read into ln. What's the neatest way of setting the fourth and fifth entries to an empty string if they don't (yet) exist? Using 'if len(fld) < 4:' feels clumsy somehow. -- Chris Green · --

Re: What's an elegant way to test for list index existing?

2018-09-28 Thread jladasky
On Friday, September 28, 2018 at 11:03:17 AM UTC-7, Chris Green wrote: > I have a list created by:- > > fld = shlex.split(ln) > > It may contain 3, 4 or 5 entries according to data read into ln. > What's the neatest way of setting the fourth and fifth entries to an > empty string if they don'

Re: python list index - an easy question

2016-12-20 Thread BartC
On 20/12/2016 00:49, Steve D'Aprano wrote: On Mon, 19 Dec 2016 03:21 am, BartC wrote: On 18/12/2016 10:59, Paul Götze wrote: Hi John, there is a nice short article by E. W. Dijkstra about why it makes sense to start numbering at zero (and exclude the upper given bound) while slicing a list. M

Re: python list index - an easy question

2016-12-19 Thread Steve D'Aprano
On Mon, 19 Dec 2016 03:21 am, BartC wrote: > On 18/12/2016 10:59, Paul Götze wrote: >> Hi John, >> >> there is a nice short article by E. W. Dijkstra about why it makes sense >> to start numbering at zero (and exclude the upper given bound) while >> slicing a list. Might give a bit of additional u

Re: python list index - an easy question

2016-12-19 Thread Gregory Ewing
BartC wrote: But if you needed a table of the frequencies of letters A to Z... An N-based array can simply have bounds of ord('A') to ord('Z') inclusive. That's fine if your language lets you have arrays with arbitrary lower bounds. But if the language only allows a fixed lower bound, and fur

Re: python list index - an easy question

2016-12-19 Thread Ben Bacarisse
Jussi Piitulainen writes: > Ben Bacarisse writes: > >> BartC writes: >> >>> You need to take your C hat off, I think. >> >> It's a computing hat. Indexes are best seen as offsets (i.e. as a >> measured distances from some origin or base). It's a model that grew >> out of machine addressing and

Re: python list index - an easy question

2016-12-19 Thread BartC
On 19/12/2016 13:48, Ben Bacarisse wrote: BartC writes: You need to take your C hat off, I think. It's a computing hat. Indexes are best seen as offsets (i.e. as a measured distances from some origin or base). A 1-based or N-based index can still be seen as an offset from element 0, if

Re: python list index - an easy question

2016-12-19 Thread Jussi Piitulainen
Ben Bacarisse writes: > BartC writes: > >> You need to take your C hat off, I think. > > It's a computing hat. Indexes are best seen as offsets (i.e. as a > measured distances from some origin or base). It's a model that grew > out of machine addressing and assembler address modes many, many > d

Re: python list index - an easy question

2016-12-19 Thread Ben Bacarisse
BartC writes: > On 19/12/2016 01:10, Ben Bacarisse wrote: >> BartC writes: >> >>> On 18/12/2016 10:59, Paul Götze wrote: there is a nice short article by E. W. Dijkstra about why it makes sense to start numbering at zero (and exclude the upper given bound) while slicing a list. Mi

Re: python list index - an easy question

2016-12-19 Thread Ned Batchelder
On Sunday, December 18, 2016 at 11:21:38 AM UTC-5, BartC wrote: > On 18/12/2016 10:59, Paul Götze wrote: > > Hi John, > > > > there is a nice short article by E. W. Dijkstra about why it makes sense > > to start numbering at zero (and exclude the upper given bound) while > > slicing a list. Might g

Re: python list index - an easy question

2016-12-19 Thread BartC
On 19/12/2016 01:10, Ben Bacarisse wrote: BartC writes: On 18/12/2016 10:59, Paul Götze wrote: there is a nice short article by E. W. Dijkstra about why it makes sense to start numbering at zero (and exclude the upper given bound) while slicing a list. Might give a bit of additional understan

Re: python list index - an easy question

2016-12-18 Thread Ben Bacarisse
BartC writes: > On 18/12/2016 10:59, Paul Götze wrote: >> there is a nice short article by E. W. Dijkstra about why it makes sense >> to start numbering at zero (and exclude the upper given bound) while >> slicing a list. Might give a bit of additional understanding. >> >> http://www.cs.utexas.ed

Re: python list index - an easy question

2016-12-18 Thread BartC
On 18/12/2016 22:21, BartC wrote: On 18/12/2016 21:04, Michael Torrie wrote: On 12/18/2016 09:21 AM, BartC wrote: So if you wanted a simple list giving the titles of the chapters in a book or on a DVD, on the colour of the front doors for each house in a street, usually you wouldn't be able t

Re: python list index - an easy question

2016-12-18 Thread BartC
On 18/12/2016 21:04, Michael Torrie wrote: On 12/18/2016 09:21 AM, BartC wrote: So if you wanted a simple list giving the titles of the chapters in a book or on a DVD, on the colour of the front doors for each house in a street, usually you wouldn't be able to use element 0. It also depends

Re: python list index - an easy question

2016-12-18 Thread Cameron Simpson
On 18Dec2016 16:21, BartC wrote: On 18/12/2016 10:59, Paul Götze wrote: there is a nice short article by E. W. Dijkstra about why it makes sense to start numbering at zero (and exclude the upper given bound) while slicing a list. Might give a bit of additional understanding. http://www.cs.utex

Re: python list index - an easy question

2016-12-18 Thread Michael Torrie
On 12/18/2016 09:21 AM, BartC wrote: > On 18/12/2016 10:59, Paul Götze wrote: >> Hi John, >> >> there is a nice short article by E. W. Dijkstra about why it makes sense >> to start numbering at zero (and exclude the upper given bound) while >> slicing a list. Might give a bit of additional understa

Re: python list index - an easy question

2016-12-18 Thread alister
On Sun, 18 Dec 2016 16:21:20 +, BartC wrote: > On 18/12/2016 10:59, Paul Götze wrote: >> Hi John, >> >> there is a nice short article by E. W. Dijkstra about why it makes >> sense to start numbering at zero (and exclude the upper given bound) >> while slicing a list. Might give a bit of additi

Re: python list index - an easy question

2016-12-18 Thread BartC
On 18/12/2016 10:59, Paul Götze wrote: Hi John, there is a nice short article by E. W. Dijkstra about why it makes sense to start numbering at zero (and exclude the upper given bound) while slicing a list. Might give a bit of additional understanding. http://www.cs.utexas.edu/users/EWD/ewd08xx/

Re: python list index - an easy question

2016-12-18 Thread Paul Götze
Hi John, there is a nice short article by E. W. Dijkstra about why it makes sense to start numbering at zero (and exclude the upper given bound) while slicing a list. Might give a bit of additional understanding. http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF - paul http://www.cs.utexas

Re: python list index - an easy question

2016-12-18 Thread alister
On Sat, 17 Dec 2016 11:10:22 -0800, John wrote: > Hi, > >I am new to Python, and I believe it's an easy question. I know R and >Matlab. > > x=[1,2,3,4,5,6,7] x[0] > 1 x[1:5] > [2, 3, 4, 5] * > > My question is: what does x[1:5] mean? By Python

Re: python list index - an easy question

2016-12-17 Thread BartC
On 17/12/2016 19:10, John wrote: Hi, I am new to Python, and I believe it's an easy question. I know R and Matlab. x=[1,2,3,4,5,6,7] x[0] 1 x[1:5] [2, 3, 4, 5] * My question is: what does x[1:5] mean? x[A:B] means the slice consisting of x[A], x[A+1],... x

Re: python list index - an easy question

2016-12-17 Thread Terry Reedy
On 12/17/2016 2:10 PM, John wrote: Hi, I am new to Python, and I believe it's an easy question. I know R and Matlab. x=[1,2,3,4,5,6,7] x[0] 1 x[1:5] [2, 3, 4, 5] * My question is: what does x[1:5] mean? The subsequence between slice positions 1 and 5, leng

Re: python list index - an easy question

2016-12-17 Thread Peter Otten
John wrote: > Hi, > >I am new to Python, and I believe it's an easy question. I know R and >Matlab. > > x=[1,2,3,4,5,6,7] x[0] > 1 x[1:5] > [2, 3, 4, 5] > * > > My question is: what does x[1:5] mean? By Python's convention, the > first ele

Re: python list index - an easy question

2016-12-17 Thread boB Stepp
On Sat, Dec 17, 2016 at 1:10 PM, John wrote: > > Hi, > >I am new to Python, and I believe it's an easy question. I know R and > Matlab. > > > >>> x=[1,2,3,4,5,6,7] > >>> x[0] > 1 > >>> x[1:5] > [2, 3, 4, 5] > * > > My question is: what does x[1:5] mean? By Python'

python list index - an easy question

2016-12-17 Thread John
Hi, I am new to Python, and I believe it's an easy question. I know R and Matlab. >>> x=[1,2,3,4,5,6,7] >>> x[0] 1 >>> x[1:5] [2, 3, 4, 5] * My question is: what does x[1:5] mean? By Python's convention, the first element of a list is indexed as "0". Doesn't x[1

Re: IndexError: list index out of range

2016-12-13 Thread Elnaz
On Tuesday, December 13, 2016 at 12:45:49 PM UTC+3:30, Peter Otten wrote: > Elnaz wrote: > > > hi > > i am begginer in python. I have written a code and given this error: > > IndexError: list index out of range > > > > In my program, I have h=32 bits input

Re: IndexError: list index out of range

2016-12-13 Thread Peter Otten
Elnaz wrote: > hi > i am begginer in python. I have written a code and given this error: > IndexError: list index out of range > > In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block > and every 8-block is n. so n=0:7;(h=int(n/4)) I want to rotate 0 to 7

IndexError: list index out of range

2016-12-12 Thread Elnaz
hi i am begginer in python. I have written a code and given this error: IndexError: list index out of range In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block and every 8-block is n. so n=0:7;(h=int(n/4)) I want to rotate 0 to 7 bits for 2 bits: 0,1,2,3,4,5,6,7

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 = '' >

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

2016-02-27 Thread Ganesh Pal
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 /tmp/file2.txt extract file2.txt """ global filename bad

Re: indexerror: list index out of range??

2013-07-01 Thread Steven D'Aprano
On Mon, 01 Jul 2013 09:45:52 +0100, Robert Kern wrote: > On 2013-06-29 16:52, Joshua Landau wrote: >> On 29 June 2013 15:30, Mark Lawrence wrote: >>> >>> On 29/06/2013 14:44, Dave Angel wrote: Since you're using the arrogant and buggy GoogleGroups, this http://wiki.python.org/moin/

Re: indexerror: list index out of range??

2013-07-01 Thread Robert Kern
On 2013-06-29 16:52, Joshua Landau wrote: On 29 June 2013 15:30, Mark Lawrence wrote: On 29/06/2013 14:44, Dave Angel wrote: Since you're using the arrogant and buggy GoogleGroups, this http://wiki.python.org/moin/GoogleGroupsPython. Please don't make comments like this, you'll upset the P

Re: indexerror: list index out of range??

2013-07-01 Thread Joshua Landau
On 29 June 2013 15:30, Mark Lawrence wrote: > > On 29/06/2013 14:44, Dave Angel wrote: >> >> Since you're using the arrogant and buggy GoogleGroups, this >> http://wiki.python.org/moin/GoogleGroupsPython. >> > Please don't make comments like this, you'll upset the Python Mailing List > Police. *d

Re: indexerror: list index out of range??

2013-06-29 Thread Mark Lawrence
On 29/06/2013 14:44, Dave Angel wrote: On 06/28/2013 11:35 PM, Titiksha wrote: Since you're using the arrogant and buggy GoogleGroups, this http://wiki.python.org/moin/GoogleGroupsPython. Please don't make comments like this, you'll upset the Python Mailing List Police. -- "Steve is going

Re: indexerror: list index out of range??

2013-06-29 Thread Dave Angel
On 06/28/2013 11:35 PM, Titiksha wrote: On Friday, June 28, 2013 8:20:28 PM UTC-5, Titiksha wrote: m=['631138', '601034', '2834', '2908', '64808'] ['LAKEFLD 3227,631138\n', 'NOBLES 3013,601034\n'] Since you're using the arrogant and buggy GoogleGroups, this

Re: indexerror: list index out of range??

2013-06-28 Thread Titiksha
On Friday, June 28, 2013 8:20:28 PM UTC-5, Titiksha wrote: > Hi, > > I am working on the following code but am getting the error: list index out > of range. I surfed through the group but somehow I am not able to fix my > error.Please guide.Structure is given below: >

Re: indexerror: list index out of range??

2013-06-28 Thread Dave Angel
On 06/28/2013 09:20 PM, Titiksha Joshi wrote: Hi, I am working on the following code but am getting the error: list index out of range. I surfed through the group but somehow I am not able to fix my error.Please guide.Structure is given below: m is a list of 5 elements. I have to match

Re: indexerror: list index out of range??

2013-06-28 Thread Chris Angelico
On Sat, Jun 29, 2013 at 11:20 AM, Titiksha Joshi wrote: > Hi, > I am working on the following code but am getting the error: list index out > of range. I surfed through the group but somehow I am not able to fix my > error.Please guide.Structure is given below: > m is a list o

indexerror: list index out of range??

2013-06-28 Thread Titiksha Joshi
Hi, I am working on the following code but am getting the error: list index out of range. I surfed through the group but somehow I am not able to fix my error.Please guide.Structure is given below: m is a list of 5 elements. I have to match elements of m from fields in file ALL_BUSES_FINAL.cvs

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

2010-11-09 Thread Stefan Behnel
. Here's my code: csvfile = csv.reader(datastr.split('\n'), delimiter=';') r = '' for i in csvfile: for j in i: print j print i[0] the "print j" statement works, but "

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

2010-11-09 Thread Costin Gamenț
#x27; >> >>        for i in csvfile: >> >>                for j in i: >> >>                        print j >> >>                print i[0] >> >> >> >> the "print j" statement works, but "print i[0]" re

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

2010-11-09 Thread Nitin Pawar
ncountered an odd > >> problem. Here's my code: > >> > >>csvfile = csv.reader(datastr.split('\n'), delimiter=';') > >>r = '' > >>for i in csvfile: > >>for j in i: > >>

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

2010-11-09 Thread Costin Gamenț
>>                for j in i: >>                        print j >>                print i[0] >> >> the "print j" statement works, but "print i[0]" returns "IndexError: >> list index out of range". Am I missing something? > &

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

2010-11-09 Thread Peter Otten
for j in i: > print j > print i[0] > > the "print j" statement works, but "print i[0]" returns "IndexError: > list index out of range". Am I missing something? Change print i[0] to print i You'

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

2010-11-09 Thread Stefan Behnel
i: print j print i[0] the "print j" statement works, but "print i[0]" returns "IndexError: list index out of range". Am I missing something? Are you sure the output you get from the "print j" is from the same loop ite

List index out of range, but list has enough elements

2010-11-09 Thread Costin Gamenț
print i[0] the "print j" statement works, but "print i[0]" returns "IndexError: list index out of range". Am I missing something? -- http://mail.python.org/mailman/listinfo/python-list

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread Terry Reedy
10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 568, in findsource 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range It is hard to reproduce the error with a script. I will work and send if I succ

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread Wolfgang Rohdewald
On Samstag 25 September 2010, Steven D'Aprano wrote: > My guess is that you've copied the .pyc file onto the server, > BUT there is also an older version of the .py file there as > well. Because the modification date is older than that of the > .pyc file, Python executes the compiled code from the

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread Steven D'Aprano
10:50:38+0300 [-] lines, lnum = findsource(frame) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 568, in findsource > 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break > 2010-09-25 10:50:38+0300 [-] IndexError: list index out of

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread deluxstar
e code works on local development environment both on linux > > and windows. When checked in to production environment, > > inspect.currentframe() or inspect.stack() function gives "List index > > out of range error". > > > When I googled, I found only one clue o

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-24 Thread Peter Otten
inspect module: > > curframe = inspect.currentframe() > calframe = inspect.getouterframes(curframe, 2) > calframe[1][0].f_locals['variable'] > > This sample code works on local development environment both on linux > and windows. When checked in to production environment, > insp

inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-24 Thread deluxstar
= inspect.getouterframes(curframe, 2) calframe[1][0].f_locals['variable'] This sample code works on local development environment both on linux and windows. When checked in to production environment, inspect.currentframe() or inspect.stack() function gives "List index out of range error". Whe

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread TomF
On 2010-02-16 11:44:45 -0800, a...@pythoncraft.com (Aahz) said: In article <4b7a91b1.6030...@lonetwin.net>, steve wrote: On 02/16/2010 05:49 PM, W. eWatson wrote: See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. The most obvious would be a.index(max(a)). Is that what you wante

Is there a simple way to find the list index to the max value?

2010-02-16 Thread W. eWatson
See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Arnaud Delobelle
a...@pythoncraft.com (Aahz) writes: > In article <4b7a91b1.6030...@lonetwin.net>, steve wrote: >>On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >>The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disad

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Tim Golden
On 16/02/2010 19:44, Aahz wrote: In article<4b7a91b1.6030...@lonetwin.net>, steve wrote: On 02/16/2010 05:49 PM, W. eWatson wrote: See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. The most obvious would be a.index(max(a)). Is that what you wanted ? The disadvantage of that is

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Aahz
In article <4b7a91b1.6030...@lonetwin.net>, steve wrote: >On 02/16/2010 05:49 PM, W. eWatson wrote: >> >> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. > >The most obvious would be a.index(max(a)). Is that what you wanted ? The disadvantage of that is that it's O(2N) instead of O

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread W. eWatson
On 2/16/2010 4:41 AM, Arnaud Delobelle wrote: Arnaud Delobelle writes: "W. eWatson" writes: See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. Here are a few ways. [...] My copy past went wrond and I forgot the first one: a = [1,4,9,3] max_index = a.index(max(a)) max_index

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Arnaud Delobelle
Arnaud Delobelle writes: > "W. eWatson" writes: > >> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. > > Here are a few ways. [...] My copy past went wrond and I forgot the first one: >>> a = [1,4,9,3] >>> max_index = a.index(max(a)) >>> max_index 2 -- Arnaud -- http://mail.p

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread steve
On 02/16/2010 05:49 PM, W. eWatson wrote: See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. The most obvious would be a.index(max(a)). Is that what you wanted ? cheers, - steve -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Arnaud Delobelle
"W. eWatson" writes: > See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. Here are a few ways. >>> a = [1,4,9,3] >>> max_index = max(xrange(len(a)), key=a.__getitem__) >>> max_index 2 >>> # Or: ... max_index = max((n, i) for i, n in enumerate(a))[1] >>> max_index 2 >>> # Or: ... from

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
then it gives an error of "list index out of range." The strange thing is that it will sometimes run for 10 iterations sometimes for only a few and sometimes won't run at all (seemingly arbitrary). Here is some of the code: for _ in range(100): handA=deal_hand(DECK) #deals 2 &#x

list index out of range

2008-05-13 Thread Georgy Panterov
I am a relatively new python user. I am writing an economic simulation of a card-game. The simulation runs fine for a few iteration but then it gives an error of "list index out of range." The strange thing is that it will sometimes run for 10 iterations sometimes for only a few and

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: OT: pronounciation [was: list index()]

2007-09-04 Thread Neil Cerutti
On 2007-08-31, Paddy <[EMAIL PROTECTED]> wrote: > On Aug 31, 11:19 am, Tim Golden <[EMAIL PROTECTED]> wrote: >> Tim Golden wrote: >> > Erik Max Francis wrote: >> >> Paddy wrote: >> >> >>> I say the 'oll' in troll like the 'ol' in frolic, and pronounce roll >> >>> and role similarly. >> >> >>> My ac

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

  1   2   3   >