Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-21 Thread Alan Gauld
On 22/01/16 00:00, Steven D'Aprano wrote: > Also, you have a problem -- what happens if the incomplete postcode is > missing the first digit? (I suppose for that case, you just have to do a > slow linear search.) Which is why a different solution may be better suited. What about an in-memory S

Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-21 Thread Steven D'Aprano
Further thoughts on your question... On Wed, Jan 20, 2016 at 01:33:17PM +, Albert-Jan Roskam wrote: > Hi, > > Like the subject says: Why is an OrderedDict not sliceable? (From the > collections library). Was that an intentional omission, or a mistake? > [1] > > Background: I do not use Or

Re: [Tutor] How to call the path of an input file

2016-01-21 Thread Steven D'Aprano
Hi John, and welcome. My responses interleaved between yours below. On Thu, Jan 21, 2016 at 11:51:09AM -0500, John Villarraga wrote: > I would like to know what is the syntax to call the path of the input file. Python only has one syntax for calling anything, and that is to put parentheses (ro

Re: [Tutor] How to call the path of an input file

2016-01-21 Thread Ben Finney
John Villarraga writes: > I would like to know what is the syntax to call the path of the input > file. It's not clear to me what “call the path of the input file” would mean. A filesystem path is not “callable” in a programming as you seem to be using it. > Below, my code is calling the input

Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-21 Thread Ben Finney
Ben Finney writes: > Oscar Benjamin writes: > > > According to a narrow definition of indexed access. I would say that > > d[k] is index access even if d is a dict and k a key. The sense of “index” implied is used consistently throughout Python https://docs.python.org/3/glossary.html> to refer

Re: [Tutor] How to call the path of an input file

2016-01-21 Thread Martin A. Brown
Greetings John, >I would like to know what is the syntax to call the path of the >input file. Below, my code is calling the input file, but not the >path. >import sys >path = sys.argv[1] Are you looking for os.path.abspath() [0]? import os import sys path = os.path.abspath(sys.argv[1])

[Tutor] How to call the path of an input file

2016-01-21 Thread John Villarraga
I would like to know what is the syntax to call the path of the input file. Below, my code is calling the input file, but not the path. Sorry for the inconvenience and thank you for your time. import sys path = sys.argv[1] y = map(str.lower, path.split())

Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-21 Thread Ben Finney
Oscar Benjamin writes: > According to a narrow definition of indexed access. I would say that > d[k] is index access even if d is a dict and k a key. An index implies the ordinal position in a sequence. In a mapping, the key is *not* referring to the position in a sequence, so is not a key. So

Re: [Tutor] Why is the name "self" optional instead of mandatory?

2016-01-21 Thread Francois Dion
On Thu, Jan 21, 2016 at 6:49 AM, Steven D'Aprano wrote: > On Wed, Jan 20, 2016 at 09:42:29PM -0600, boB Stepp wrote: > > > So I really only have one question: Why not make Python's > > *traditional* name, "self", mandatory? Why give the programmer this > > kind of choice? [OK, that was two qu

Re: [Tutor] Why is the name "self" optional instead of mandatory?

2016-01-21 Thread Steven D'Aprano
On Wed, Jan 20, 2016 at 09:42:29PM -0600, boB Stepp wrote: > So I really only have one question: Why not make Python's > *traditional* name, "self", mandatory? Why give the programmer this > kind of choice? [OK, that was two questions.] Why bother making it mandatory? That just makes more work

Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-21 Thread Oscar Benjamin
On 21 January 2016 at 09:19, Ben Finney wrote: > Albert-Jan Roskam writes: > >> Why is an OrderedDict not sliceable? > > Because slicing implies index access. The built-in ‘dict’ and > ‘collections.OrderedDict’ both do not support indexed access:: According to a narrow definition of indexed acce

Re: [Tutor] Why do I not get an error when I mistakenly type "humdrum.sigh_strenght" instead of the correct "humdrum.sigh_strength"?

2016-01-21 Thread Steven D'Aprano
On Wed, Jan 20, 2016 at 09:54:32PM -0800, Danny Yoo wrote: > Just to be explicit: you are pointing out that: > > humdrum.sigh_strenght = 'high' > > was a typo, and it would have been nice if it could be caught as an error. > > If that's the case, then yes, I agree. Unfortunately, this isn

Re: [Tutor] Extract several arrays from a large 2D array

2016-01-21 Thread Peter Otten
Alan Gauld wrote: > So in pseudo code: > > data = {} > for row in myArray: > data.get((row[0],row[1]),[]).append row[3] Replace get() with setdefault() to go from pseudo to Python code. ___ Tutor maillist - Tutor@python.org To unsubscribe or ch

Re: [Tutor] Extract several arrays from a large 2D array

2016-01-21 Thread Peter Otten
Ek Esawi wrote: > Hi All-- > I have a 2D array (2000, 4); an example is given abelow. On the 1st > column I have 15 variables, on the 2nd 4 variables. Ignore column 3 for > now. I want a code that generate 4 arrays for each variable on the 1st > column; each array contains all the values from co

Re: [Tutor] Extract several arrays from a large 2D array

2016-01-21 Thread Oscar Benjamin
On 21 January 2016 at 04:22, Ek Esawi wrote: > I have a 2D array (2000, 4); Do you mean a numpy array? I'm going to assume that you do. > an example is given abelow. On the 1st column > I have 15 variables, on the 2nd 4 variables. Ignore column 3 for now. I > want a code that generate 4 arrays

Re: [Tutor] Extract several arrays from a large 2D array

2016-01-21 Thread Alan Gauld
On 21/01/16 04:22, Ek Esawi wrote: > I have a 2D array (2000, 4); an example is given abelow. On the 1st column > I have 15 variables, on the 2nd 4 variables. Your terminology is a little confusing since variables in Python normally means names. You have values in your columns. So I suspect whe

Re: [Tutor] Why is the name "self" optional instead of mandatory?

2016-01-21 Thread Alan Gauld
On 21/01/16 03:42, boB Stepp wrote: > So I really only have one question: Why not make Python's > *traditional* name, "self", mandatory? Why give the programmer this > kind of choice? [OK, that was two questions.] Because to do otherwise would introduce all sorts of extra complexity into the s

[Tutor] Extract several arrays from a large 2D array

2016-01-21 Thread Ek Esawi
Hi All-- I have a 2D array (2000, 4); an example is given abelow. On the 1st column I have 15 variables, on the 2nd 4 variables. Ignore column 3 for now. I want a code that generate 4 arrays for each variable on the 1st column; each array contains all the values from column 4. Then I want to fi

Re: [Tutor] Why is the name "self" optional instead of mandatory?

2016-01-21 Thread DiliupG
The answer to this will be an interesting read... :) This email has been sent from a virus-free computer protected by Avast. www.avast.com

Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-21 Thread Ben Finney
Albert-Jan Roskam writes: > Why is an OrderedDict not sliceable? Because slicing implies index access. The built-in ‘dict’ and ‘collections.OrderedDict’ both do not support indexed access:: >>> import collections >>> foo = collections.OrderedDict([ ... ('a', 1), ('b', 2), ('

Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-21 Thread Albert-Jan Roskam
> Date: Thu, 21 Jan 2016 12:00:29 +1100 > From: st...@pearwood.info > To: tutor@python.org > Subject: Re: [Tutor] Why is an OrderedDict not sliceable? > > On Wed, Jan 20, 2016 at 01:33:17PM +, Albert-Jan Roskam wrote: > > Hi, > > > > Like the subject says: Why is an OrderedDict not sliceabl