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
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
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
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
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
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
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.
> >>
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
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
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
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
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
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
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?
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
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
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
Thanks all, several possible ways of doing it there.
--
Chris Green
·
--
https://mail.python.org/mailman/listinfo/python-list
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
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
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
·
--
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'
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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/
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
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
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
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
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
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'
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
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
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
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
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
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 /
>>
> 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
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
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 = ''
>
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
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/
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
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
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
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
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:
>
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
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
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
. 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 "
#x27;
>> >> for i in csvfile:
>> >> for j in i:
>> >> print j
>> >> print i[0]
>> >>
>> >> the "print j" statement works, but "print i[0]" re
ncountered an odd
> >> problem. Here's my code:
> >>
> >>csvfile = csv.reader(datastr.split('\n'), delimiter=';')
> >>r = ''
> >>for i in csvfile:
> >>for j in i:
> >>
>> 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?
>
&
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'
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
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
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
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
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
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
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.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
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
See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
"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
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
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
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
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
>
> 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.
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
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
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
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
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
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
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
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
--
>
> 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
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 - 100 of 265 matches
Mail list logo