Re: How to filter a dictionary ?

2012-04-10 Thread Dave Angel
On 04/10/2012 02:04 AM, Shashank Singh wrote:
> On Mon, Apr 9, 2012 at 10:49 PM, Nikhil Verma wrote:
> 
>> I am trying this but its giving me a generator object.
>>
>> In [9]: (k for k,v in for_patient_type.iteritems() if v == 'Real')
>>
> Iterating over a dict gives you all the keys, not the key value pairs
>

But that line does not iterate over the dict, it iterates over an
iterator consisting of key/value pairs.  Note he had a call to iteritems().



-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to filter a dictionary ?

2012-04-10 Thread Shashank Singh
On Tue, Apr 10, 2012 at 12:16 AM, Dave Angel  wrote:

> On 04/10/2012 02:04 AM, Shashank Singh wrote:
> > On Mon, Apr 9, 2012 at 10:49 PM, Nikhil Verma  >wrote:
> > 
> >> I am trying this but its giving me a generator object.
> >>
> >> In [9]: (k for k,v in for_patient_type.iteritems() if v == 'Real')
> >>
> > Iterating over a dict gives you all the keys, not the key value pairs
> >
>
> But that line does not iterate over the dict, it iterates over an
> iterator consisting of key/value pairs.  Note he had a call to iteritems().
>

Thanks Dave.
My bad. Nikhil, you could get the data that you wanted by your initial
approach. All you needed was to either run through the generator or just
use list comprehension

>>> g = (k for k,v in for_patient_type.iteritems() if v == 'Real')
>>> for k in g: print k
...
80
81
83
84
91
93
79
>>>


>>> [k for k,v in for_patient_type.iteritems() if v == 'Real']
[80, 81, 83, 84, 91, 93, 79]


-- 
Regards
Shashank Singh
http://www.flipora.com
http://r ationalpie.wordpress.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to filter a dictionary ?

2012-04-10 Thread Nikhil Verma
Thanks Dave and Shashank . I cleared the concept also.
I got it guys. In my piece of code where i was doing this

In [25]: [k for k,v in for_patient_type.iteritems() if v == "Real"]
Out[25]: [80, 81, 83, 84, 91, 93, 79]


thats what shashank suggest later. Thanks to you Dave.I cleared my concept
which i just forgot.

On Tue, Apr 10, 2012 at 12:54 PM, Shashank Singh <
shashank.sunny.si...@gmail.com> wrote:

>
>
> On Tue, Apr 10, 2012 at 12:16 AM, Dave Angel  wrote:
>
>> On 04/10/2012 02:04 AM, Shashank Singh wrote:
>> > On Mon, Apr 9, 2012 at 10:49 PM, Nikhil Verma > >wrote:
>> > 
>> >> I am trying this but its giving me a generator object.
>> >>
>> >> In [9]: (k for k,v in for_patient_type.iteritems() if v == 'Real')
>> >>
>> > Iterating over a dict gives you all the keys, not the key value pairs
>> >
>>
>> But that line does not iterate over the dict, it iterates over an
>> iterator consisting of key/value pairs.  Note he had a call to
>> iteritems().
>>
>
> Thanks Dave.
> My bad. Nikhil, you could get the data that you wanted by your initial
> approach. All you needed was to either run through the generator or just
> use list comprehension
>
> >>> g = (k for k,v in for_patient_type.iteritems() if v == 'Real')
> >>> for k in g: print k
> ...
> 80
> 81
> 83
> 84
> 91
> 93
> 79
> >>>
>
>
> >>> [k for k,v in for_patient_type.iteritems() if v == 'Real']
> [80, 81, 83, 84, 91, 93, 79]
>
>
> --
> Regards
> Shashank Singh
> http://www.flipora.com
> http://r 
> ationalpie.wordpress.com
>
>


-- 
Regards
Nikhil Verma
+91-958-273-3156
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python randomly exits with Linux OS error -9 or -15

2012-04-10 Thread Janis
I have confirmed that the signal involved is SIGKILL and, yes,
apparently OS is simply running out of memory.

Thank you all, again!

Best Regards,
Janis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python randomly exits with Linux OS error -9 or -15

2012-04-10 Thread Paul Rubin
Janis  writes:
> I have confirmed that the signal involved is SIGKILL and, yes,
> apparently OS is simply running out of memory.

This is the notorious OOM killer, sigh.  There are some links from

 http://en.wikipedia.org/wiki/OOM_Killer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-10 Thread Seymour J.
In <20120409111329@kylheku.com>, on 04/09/2012
   at 06:55 PM, Kaz Kylheku  said:

>Null-terminated C strings do the same thing.

C arrays are not LISP strings; there is no C analog to car and cdr.

>Code that needs to deal with null "characters" is manipulating
>binary data, not text,

That's a C limitation, not a characteristic of text. It is certainly
not true in languages unrelated to C, e.g., Ada, Algol 60, PL/I.

>If we scan for a null terminator which is not there, we have a
>buffer overrun.

You're only thinking of scanning an existing string; think of
constructing a string. The null only indicates the current length, not
the amount allocated.

>If a length field in front of string data is incorrect, we also have
>a buffer overrrun.

The languages that I'm aware of that use a string length field also
use a length field for the allocated storage. More precisely, they
require that attempts to store beyond the allocated length be
detected.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamt...@library.lspace.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] help with pygame-tutorial

2012-04-10 Thread aapeetnootjes
Op maandag 9 april 2012 22:51:48 UTC+2 schreef Roy Smith het volgende:
> In article 
> <1a558398-3984-4b20-8d67-a0807871b...@v1g2000yqm.googlegroups.com>,
>  aapeetnootjes  wrote:
> 
> > I'm trying out the pygame tutorial at 
> > http://www.pygame.org/docs/tut/intro/intro.html
> > If I try out the code I'm facing an error:
> > ./game.py: line 4: syntax error  at unexpected symbol 'size'
> > ./game.py: line 4: `size = width, height = 320, 240'
> > 
> > can anyone here tell me what's going wrong?
> > 
> > thanks
> 
> How did you run the code?  Did you do "python game.py", or did you just 
> make game.py executable and run ./game.py?  If the later, my guess is 
> it's being interpreted by the shell because there's no #! line.

you are right, I tried to start it the wrong way

thanks a lot!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-10 Thread Seymour J.
In <87vcl81wtw@sapphire.mobileactivedefense.com>, on 04/09/2012
   at 09:20 PM, Rainer Weikusat  said:

>This is logically very similar to the LISP list 

FSVO similar.

>This is, I think, a case where the opinions of people who have used
>C strings and the opinions of people who haven't differ greatly.

You would be wrong. It is a case where the opinions of people who are
oriented to a particular language and the opinions of people who have
lost count of the languages they have used greatly differ.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamt...@library.lspace.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functions which take functions

2012-04-10 Thread Ulrich Eckhardt
Am 09.04.2012 20:57, schrieb Kiuhnm:
> Do you have some real or realistic (but easy and self-contained)
> examples when you had to define a (multi-statement) function and pass it
> to another function?

Take a look at decorators, they not only take non-trivial functions but
also return them. That said, I wonder what your intention behind this
question is...

:)

Uli

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functions which take functions

2012-04-10 Thread Kiuhnm

On 4/10/2012 14:29, Ulrich Eckhardt wrote:

Am 09.04.2012 20:57, schrieb Kiuhnm:

Do you have some real or realistic (but easy and self-contained)
examples when you had to define a (multi-statement) function and pass it
to another function?


Take a look at decorators, they not only take non-trivial functions but
also return them. That said, I wonder what your intention behind this
question is...

:)


That won't do. A good example is when you pass a function to re.sub, for 
instance.


Kiuhnm
--
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-10 Thread Devin Jeanpierre
On Tue, Apr 10, 2012 at 6:52 AM, Shmuel  Metz
 wrote:
> In <20120409111329@kylheku.com>, on 04/09/2012
>   at 06:55 PM, Kaz Kylheku  said:
>
>>Null-terminated C strings do the same thing.
>
> C arrays are not LISP strings; there is no C analog to car and cdr.

The post you're criticising specifically gave a definition for cdr
that had the semantics he wanted. "where cdr(s) is conveniently
defined as s + 1."

(car can be defined as s[0]). The real difference is the lack of error
checking and the lack of cons.

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python 3 shell restarting

2012-04-10 Thread Franck Ditter
In article 
<19745339.1683.1333981625966.JavaMail.geo-discussion-forums@yncc41>,
 Miki Tebeka  wrote:

> > How may I get a fresh Python shell with Idle 3.2 ?
> Open the configuration panel (Options -> Configure IDLE). 
> Look in the "Keys" tab for the shortcut to "restart-shell"

Fine, thanks, but WHY isn't it in a menu (e.g. Debug) ?
Moreover, I see :

restart-shell - 

Hum, but when I press, Ctl-F6, nothing happens !!??!! F6 gives me char.
(MacOS-X Lion, France, Idle 3.3.0a2)

I tried to replace "restart-shell " with F6 (which does nothing except 
displaying a 
strange character inside a square), but that was refused "already in use"...

franck

P.S. There is no "configuration panel (Options -> Configure IDLE)",
only a Preferences menu with a "Key" tab on MacOS-X. May I suggest to the
Python Idle 3 team to test their software on a Mac ? Please :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python 3 shell restarting

2012-04-10 Thread Benjamin Kaplan
On Tue, Apr 10, 2012 at 2:36 PM, Franck Ditter  wrote:
> In article
> <19745339.1683.1333981625966.JavaMail.geo-discussion-forums@yncc41>,
>  Miki Tebeka  wrote:
>
>> > How may I get a fresh Python shell with Idle 3.2 ?
>> Open the configuration panel (Options -> Configure IDLE).
>> Look in the "Keys" tab for the shortcut to "restart-shell"
>
> Fine, thanks, but WHY isn't it in a menu (e.g. Debug) ?
> Moreover, I see :
>
>    restart-shell - 
>
> Hum, but when I press, Ctl-F6, nothing happens !!??!! F6 gives me char.
> (MacOS-X Lion, France, Idle 3.3.0a2)
>
> I tried to replace "restart-shell " with F6 (which does nothing except 
> displaying a
> strange character inside a square), but that was refused "already in use"...
>
>    franck
>
> P.S. There is no "configuration panel (Options -> Configure IDLE)",
> only a Preferences menu with a "Key" tab on MacOS-X. May I suggest to the
> Python Idle 3 team to test their software on a Mac ? Please :-)


IDLE is tested on the Mac. But Mac OS X has very different design
guidelines from programs on other systems. The Preferences menu is
pretty much required to be under the Program Name menu, for example.
And all the keyboard shortcuts that use Ctrl on Windows and Linux use
Command on Mac OS X. If you don't specify Mac, we're going to give you
the options that work on Windows and Linux.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-10 Thread BartC
"Shmuel (Seymour J.)Metz"  wrote in 
message news:4f8410ff$2$fuzhry+tra$mr2...@news.patriot.net...

In <20120409111329@kylheku.com>, on 04/09/2012
  at 06:55 PM, Kaz Kylheku  said:



If we scan for a null terminator which is not there, we have a
buffer overrun.


You're only thinking of scanning an existing string; think of
constructing a string. The null only indicates the current length, not
the amount allocated.


If a length field in front of string data is incorrect, we also have
a buffer overrrun.


The languages that I'm aware of that use a string length field also
use a length field for the allocated storage. More precisely, they
require that attempts to store beyond the allocated length be
detected.


I would have thought trying to *read* beyond the current length would be an
error.

Writing beyond the current length, and perhaps beyond the current allocation
might be OK if the string is allowed grow, otherwise that's also an error.

In any case, there is no real need for an allocated length to be passed
around with the string, if you are only going to be reading it, or only
modifying the existing characters. And depending on the memory management
arrangements, such a length need not be stored at all.

--
Bartc


--
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-10 Thread Rainer Weikusat
Shmuel (Seymour J.) Metz  writes:
> In <20120409111329@kylheku.com>, on 04/09/2012
>at 06:55 PM, Kaz Kylheku  said:
>
>>Null-terminated C strings do the same thing.
>
> C arrays are not LISP strings; there is no C analog to car and cdr.

'car' and 'cdr' refer to cons cells in Lisp, not to strings. How the
first/rest terminology can be sensibly applied to 'C strings' (which
are similar to linked-lists in the sense that there's a 'special
termination value' instead of an explicit length) was already
explained elsewhere.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functions which take functions

2012-04-10 Thread Eelco
On Apr 10, 3:36 am, Kiuhnm  wrote:
> On 4/10/2012 14:29, Ulrich Eckhardt wrote:
>
> > Am 09.04.2012 20:57, schrieb Kiuhnm:
> >> Do you have some real or realistic (but easy and self-contained)
> >> examples when you had to define a (multi-statement) function and pass it
> >> to another function?
>
> > Take a look at decorators, they not only take non-trivial functions but
> > also return them. That said, I wonder what your intention behind this
> > question is...
>
> > :)
>
> That won't do. A good example is when you pass a function to re.sub, for
> instance.
>
> Kiuhnm

Wont do for what? Seems like a perfect example of function-passing to
me.

If you have such a precise notion of what it is you are looking for,
why even ask?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functions which take functions

2012-04-10 Thread Chris Angelico
On Tue, Apr 10, 2012 at 11:36 PM, Kiuhnm
 wrote:
> On 4/10/2012 14:29, Ulrich Eckhardt wrote:
>>
>> Am 09.04.2012 20:57, schrieb Kiuhnm:
>>>
>>> Do you have some real or realistic (but easy and self-contained)
>>> examples when you had to define a (multi-statement) function and pass it
>>> to another function?
>>
>>
>> Take a look at decorators, they not only take non-trivial functions but
>> also return them. That said, I wonder what your intention behind this
>> question is...
>>
>
> That won't do. A good example is when you pass a function to re.sub, for
> instance.

The most common case of such a thing is a structure walking utility.
For instance, a linked-list walker could be written as:

def walk(tree,func):
node=tree.head
while node:
func(node.data)
node=tree.sibling

This could equally reasonably be written with yield, though I'm not
sure that it's possible to write a recursive generator as cleanly (eg
to walk a binary tree). Perhaps the new "yield from" syntax would be
good here, but I've never used it. In any case, it's a classic use of
passing a function-like as a parameter, even if there's another way to
do it.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python 3 shell restarting

2012-04-10 Thread Terry Reedy

On 4/10/2012 3:28 PM, Benjamin Kaplan wrote:

On Tue, Apr 10, 2012 at 2:36 PM, Franck Ditter  wrote:

In article



Hum, but when I press, Ctl-F6, nothing happens !!??!! F6 gives me char.
(MacOS-X Lion, France, Idle 3.3.0a2)


This is what Ctrl-F6 does on Windows.
>>>  RESTART 


>>>


IDLE is tested on the Mac. But Mac OS X has very different design
guidelines from programs on other systems. The Preferences menu is
pretty much required to be under the Program Name menu, for example.
And all the keyboard shortcuts that use Ctrl on Windows and Linux use
Command on Mac OS X. If you don't specify Mac, we're going to give you
the options that work on Windows and Linux.



--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-10 Thread Terry Reedy

On 4/10/2012 4:10 PM, Rainer Weikusat wrote:


'car' and 'cdr' refer to cons cells in Lisp, not to strings. How the
first/rest terminology can be sensibly applied to 'C strings' (which
are similar to linked-lists in the sense that there's a 'special
termination value' instead of an explicit length) was already
explained elsewhere.


The idea of partitioning a collection into one item and the rest can be 
applied to any collection (or subcollection). Python iterators embody 
this generic idea. An iterator represents a collection (or 
subcollection). Built-in next(iter) either returns an item while 
updating iter to represent the subcollection without the item, or raises 
StopIteration. *How* to test emptiness, 'remove' an item, and mutate the 
iterator are all implementation details hidden inside the iterator. They 
are mostly irrelevant to the abstract operation of repeated partitioning 
to process each item of a collection.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python 3 shell restarting

2012-04-10 Thread Ned Deily
In article 
,
 Benjamin Kaplan  wrote:

> On Tue, Apr 10, 2012 at 2:36 PM, Franck Ditter  wrote:
> > In article
> > <19745339.1683.1333981625966.JavaMail.geo-discussion-forums@yncc41>,
> >  Miki Tebeka  wrote:
> >
> >> > How may I get a fresh Python shell with Idle 3.2 ?
> >> Open the configuration panel (Options -> Configure IDLE).
> >> Look in the "Keys" tab for the shortcut to "restart-shell"
> >
> > Fine, thanks, but WHY isn't it in a menu (e.g. Debug) ?
> > Moreover, I see :
> >
> >    restart-shell - 
> >
> > Hum, but when I press, Ctl-F6, nothing happens !!??!! F6 gives me char.
> > (MacOS-X Lion, France, Idle 3.3.0a2)
> >
> > I tried to replace "restart-shell " with F6 (which does nothing except 
> > displaying a
> > strange character inside a square), but that was refused "already in 
> > use"...

It is in a menu item but *only* when the IDLE shell window has the focus.

> > P.S. There is no "configuration panel (Options -> Configure IDLE)",
> > only a Preferences menu with a "Key" tab on MacOS-X. May I suggest to the
> > Python Idle 3 team to test their software on a Mac ? Please :-)
> 
> 
> IDLE is tested on the Mac. But Mac OS X has very different design
> guidelines from programs on other systems. The Preferences menu is
> pretty much required to be under the Program Name menu, for example.
> And all the keyboard shortcuts that use Ctrl on Windows and Linux use
> Command on Mac OS X. If you don't specify Mac, we're going to give you
> the options that work on Windows and Linux.

Yes, and one of the differences is that, on OS X, there is only menu bar 
per application, not per window as in many other windowing systems.  To 
deal with that OS X Aqua Tk (and, hence, IDLE) alters the menu options 
and menu keyboard accelerators to match the currently selected window, 
i.e. the window currently with focus.  So, in IDLE,  if you have an IDLE 
Shell window, an IDLE edit window, and an IDLE debug window open, you 
will see somewhat different menu options depending on which of those 
windows you click on.  If you click on the IDLE shell window, you'll see 
a Shell menu option with a Restart Shell menu item that has a ^F6 
accelerator.  If you click on the edit window, that menu item is no 
longer available.

-- 
 Ned Deily,
 n...@acm.org

-- 
http://mail.python.org/mailman/listinfo/python-list