Re: [Tutor] list of dict question

2010-10-12 Thread Francesco Loffredo
On 11/10/2010 19.23, Alan Gauld wrote: ... HTH, Sure it did! Very enlightening, Alan. THANK YOU! Nessun virus nel messaggio in uscita. Controllato da AVG - www.avg.com Versione: 9.0.862 / Database dei virus: 271.1.1/3190 - Data di rilascio: 10/11/10 08:34:00 ___

Re: [Tutor] list of dict question

2010-10-11 Thread Alan Gauld
"Francesco Loffredo" wrote lst = [] for n in range(3): obj = {} I didn't know that this creates a new obj if obj already exists, I thought it would just update it. That's my mistake. Yes you have to remember that in Python, unlike C etc, names are not aliases for memory locations. They are

Re: [Tutor] list of dict question

2010-10-11 Thread Francesco Loffredo
Thank you, Alan and Dave, for your spotting this weak point in my understanding of Python! On 11/10/2010 2.11, Dave Angel wrote: On 2:59 PM, Alan Gauld wrote: "Francesco Loffredo" wrote did, Roelof's code would work perfectly, and you could store in a list all the subsequent changes of a d

Re: [Tutor] list of dict question

2010-10-10 Thread Dave Angel
On 2:59 PM, Alan Gauld wrote: "Francesco Loffredo" wrote did, Roelof's code would work perfectly, and you could store in a list all the subsequent changes of a dictionary without calling them with different names. You don;'t need dfifferent names. Provided the name creates a new object ins

Re: [Tutor] list of dict question

2010-10-10 Thread Alan Gauld
"Francesco Loffredo" wrote did, Roelof's code would work perfectly, and you could store in a list all the subsequent changes of a dictionary without calling them with different names. You don;'t need dfifferent names. Provided the name creates a new object inside the loop you can reuse the

Re: [Tutor] list of dict question

2010-10-10 Thread Francesco Loffredo
On 09/10/2010 10.25, Alan Gauld wrote: "Francesco Loffredo" wrote > On the next iteration you overwrite those two dictionaries > with new values then append them to the list again. > So you wind up with 2 copies of the updated dictionaries. > ... This is difficult for me too: why does this hap

Re: [Tutor] list of dict question

2010-10-09 Thread Alan Gauld
"Francesco Loffredo" wrote > On the next iteration you overwrite those two dictionaries > with new values then append them to the list again. > So you wind up with 2 copies of the updated dictionaries. > ... This is difficult for me too: why does this happen? Or, more correctly, why should th

Re: [Tutor] list of dict question

2010-10-09 Thread Francesco Loffredo
On 09/10/2010 9.37, Steven D'Aprano wrote: On Sat, 9 Oct 2010 06:05:57 pm Francesco Loffredo wrote: Alan's answer to Roelof made me think... I'm sorry, I don't know what your question is. You seem to have quoted various bits and pieces of text from earlier emails (text beginning with> signs).

Re: [Tutor] list of dict question

2010-10-09 Thread Steven D'Aprano
On Sat, 9 Oct 2010 06:05:57 pm Francesco Loffredo wrote: > Alan's answer to Roelof made me think... I'm sorry, I don't know what your question is. You seem to have quoted various bits and pieces of text from earlier emails (text beginning with > signs). Apart from the sentence beginning with "Al

[Tutor] list of dict question

2010-10-09 Thread Francesco Loffredo
Alan's answer to Roelof made me think... On 08/10/2010 13.40, Francesco Loffredo wrote: Il 08/10/2010 10.02, Alan Gauld ha scritto: "Roelof Wobben" wrote I have this programm : tournooi = [{'thuis': 'A','uit': "B",'thuisscore': 20, 'uitscore': ... This was your answer to Roelof: On the

Re: [Tutor] list of dict question

2010-10-08 Thread Francesco Loffredo
Il 08/10/2010 10.02, Alan Gauld ha scritto: "Roelof Wobben" wrote I have this programm : tournooi = [{'thuis': 'A','uit': "B",'thuisscore': 20, 'uitscore': ... for wedstrijd in tournooi : if wedstrijd['thuis'] in stand : print "True" stand is a list of dictionaries so this will never be

Re: [Tutor] list of dict question

2010-10-08 Thread Roelof Wobben
> To: tutor@python.org > From: alan.ga...@btinternet.com > Date: Fri, 8 Oct 2010 09:02:05 +0100 > Subject: Re: [Tutor] list of dict question > > > "Roelof Wobben" wrote > >> I have this programm : >> >&

Re: [Tutor] list of dict question

2010-10-08 Thread Alan Gauld
"Roelof Wobben" wrote I have this programm : tournooi = [{'thuis': 'A','uit': "B",'thuisscore': 20, 'uitscore': 15},{'thuis': 'C','uit': "D",'thuisscore': 80, 'uitscore': 40}] stand = [] tussen_thuis = {} tussen_uit = {} Here you create your dictionary objects. You never create any more d

[Tutor] list of dict question

2010-10-08 Thread Roelof Wobben
Hello, I have this programm : tournooi = [{'thuis': 'A','uit': "B",'thuisscore': 20, 'uitscore': 15},{'thuis': 'C','uit': "D",'thuisscore': 80, 'uitscore': 40}] stand = [] tussen_thuis = {} tussen_uit = {} for wedstrijd in tournooi : if wedstrijd['thuis'] in stand : print "True"

Re: [Tutor] list comprehension, efficiency?

2010-10-03 Thread bob gailer
On 10/2/2010 8:02 PM, Steven D'Aprano wrote: On Sun, 3 Oct 2010 01:17:39 am bob gailer wrote: I ran dis on a for loop and the equivalent comprehension. I was surprised to see almost identical code. I had assumed (and now wish for) that a comprehension would be a primitive written in C and th

Re: [Tutor] list comprehension, efficiency?

2010-10-02 Thread Steven D'Aprano
On Sun, 3 Oct 2010 01:17:39 am bob gailer wrote: > I ran dis on a for loop and the equivalent comprehension. > > I was surprised to see almost identical code. > > I had assumed (and now wish for) that a comprehension would be a > primitive written in C and thus much faster! How could it be? A lis

Re: [Tutor] list comprehension, efficiency?

2010-10-02 Thread bob gailer
[snip] I ran dis on a for loop and the equivalent comprehension. I was surprised to see almost identical code. I had assumed (and now wish for) that a comprehension would be a primitive written in C and thus much faster! -- Bob Gailer 919-636-4239 Chapel Hill NC ___

Re: [Tutor] list comprehension, efficiency?

2010-09-28 Thread Bill Campbell
On Tue, Sep 28, 2010, Lie Ryan wrote: >On 09/28/10 13:57, Bill Allen wrote: >> I can now see that quite a bit of the code I write dealing with lists >> can be done with list >> comprehensions. My question is this, is the list comprehension styled >> code generally >> more efficient at runtime? I

Re: [Tutor] list comprehension, efficiency?

2010-09-28 Thread Steven D'Aprano
On Tue, 28 Sep 2010 01:57:23 pm Bill Allen wrote: > I can now see that quite a bit of the code I write dealing with lists > can be done with list > comprehensions. My question is this, is the list comprehension > styled code generally > more efficient at runtime? If so, why? List comprehensio

Re: [Tutor] list comprehension, efficiency?

2010-09-27 Thread Lie Ryan
On 09/28/10 13:57, Bill Allen wrote: > I can now see that quite a bit of the code I write dealing with lists > can be done with list > comprehensions. My question is this, is the list comprehension styled > code generally > more efficient at runtime? If so, why? Yes, because the looping in list

[Tutor] list comprehension, efficiency?

2010-09-27 Thread Bill Allen
I have seen list comprehensions used, but have not quite got the hang of it yet. So, I was writing a bit of code to do some work with file directories and decided to give it a try as follows: list_c = os.listdir("c:") #first code written in the way I usually would. dirs = [] for x in list_c:

Re: [Tutor] list dll functions?

2010-09-15 Thread ALAN GAULD
hose you can see the parameters etc. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Original Message > From: Alex Hall > To: Alan Gauld > Sent: Wednesday, 15 September, 2010 15:57:43 > Subject: Re: [Tutor] list dll functions? > &

Re: [Tutor] list dll functions?

2010-09-15 Thread Alan Gauld
"Alex Hall" wrote Out of curiosity: I know I can call dll functions from python using the win32 lib, but is there any way to simply "examine" a loaded dll to see all of the functions and attributes it exposes for use? There are various tools around to do that and hopefully some documentation

Re: [Tutor] list dll functions ?

2010-09-15 Thread patrice laporte
Dependdencyy walker is a good tool, but as you have seen it doesn't give you function's signature. If you explore a MS dll, you should to have a look at MSDN and read about the function description. A bit out of subject : There is no way to find the function's signature only from exploring the bin

Re: [Tutor] list dll functions?

2010-09-14 Thread Alex Hall
On 9/14/10, R. Alan Monroe wrote: >> the win32 lib, but is there any way to simply "examine" a loaded dll >> to see all of the functions and attributes it exposes for use? I would > > http://www.dependencywalker.com/ A great program, thanks! Best of all, for me anyway, it works well (so far) with

Re: [Tutor] list dll functions?

2010-09-14 Thread R. Alan Monroe
> the win32 lib, but is there any way to simply "examine" a loaded dll > to see all of the functions and attributes it exposes for use? I would http://www.dependencywalker.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscriptio

[Tutor] list dll functions?

2010-09-14 Thread Alex Hall
Hi all, Out of curiosity: I know I can call dll functions from python using the win32 lib, but is there any way to simply "examine" a loaded dll to see all of the functions and attributes it exposes for use? I would do no good with a hex editor since I have no idea what all the numbers mean, so I a

Re: [Tutor] list index out of range

2010-09-14 Thread Francesco Loffredo
My humble guess: (sure, the full traceback would help A LOT!) On 09/09/2010 23.52, Todd Ballard wrote: y=[daily_solar_radiation["MJ"][0]] for i in xrange(0,275): y=[daily_solar_radiation["MJ"]][i]+y[i-1] # <--THIS y[i-1] is out of bounds when i=0 !!! Hope that helps Francesco Nessun vir

Re: [Tutor] list index out of range

2010-09-12 Thread Steven D'Aprano
On Fri, 10 Sep 2010 07:52:20 am Todd Ballard wrote: > I am attempting to have a cummalative total of the y values and > receive a "list index out of range" error message How unfortunate. Do you have an actual question to ask, or are you just sharing? If you are having problems fixing the error,

[Tutor] list index out of range

2010-09-12 Thread Todd Ballard
I am attempting to have a cummalative total of the y values and receive a "list index out of range" error message import numpy import matplotlib.pyplot as plt import filereader from filereader import * My_Path="C:\\Python26\\assignment2\\datadownload.txt" My_Data_Type=numpy.dtype([("year","

Re: [Tutor] List comprehension for dicts?

2010-08-20 Thread Steven D'Aprano
On Sat, 21 Aug 2010 01:47:12 am bob gailer wrote: > > Well yes, but I pointed out that you *can* bail out early of > > for-loops, but not list comprehensions. The whole point is with a > > list comp, you're forced to iterate over the entire sequence, even > > if you know that you're done and would

Re: [Tutor] List comprehension for dicts?

2010-08-20 Thread Nitin Das
result = [i%2 for i in itertools.takewhile(lamda x:i< 10, seq)] is a good approach but it is taking little more time than the for loop over iterator. def takewhile(predicate, iterable): # takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4 for x in iterable: if predicate(x):

Re: [Tutor] List comprehension for dicts?

2010-08-20 Thread bob gailer
On 8/20/2010 5:44 AM, Steven D'Aprano wrote: On Fri, 20 Aug 2010 06:10:59 pm Alan Gauld wrote: "Steven D'Aprano" wrote the purpose). No matter how fast you can perform a loop, it's always faster to avoid it altogether, so this: seq = xrange(1000) result = [] for i in seq: if i>= 10:

Re: [Tutor] List comprehension for dicts?

2010-08-20 Thread Steven D'Aprano
On Fri, 20 Aug 2010 06:10:59 pm Alan Gauld wrote: > "Steven D'Aprano" wrote > > > the purpose). No matter how fast you can perform a loop, it's > > always faster to avoid it altogether, so this: > > > > seq = xrange(1000) > > result = [] > > for i in seq: > >if i >= 10: break > >result

Re: [Tutor] List comprehension for dicts?

2010-08-20 Thread Alan Gauld
"Steven D'Aprano" wrote the purpose). No matter how fast you can perform a loop, it's always faster to avoid it altogether, so this: seq = xrange(1000) result = [] for i in seq: if i >= 10: break result.append(i%2) will be much faster than this: seq = xrange(1000) result = [i%

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Steven D'Aprano
On Fri, 20 Aug 2010 09:51:08 am Pete wrote: [...] > Ah, so list comprehensions are a purely syntactic construct? No, I don't think that's what Emile was trying to say. It's not like list comps are macros that are expanded into the explicit for-loop like that. All he is saying is that both the f

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Pete
On 2010-08-19, at 5:25 PM, Emile van Sebille wrote: > On 8/19/2010 7:51 AM Pete said... >> Hi, >> >> I've been reading up on list comprehensions lately, all userful and powerful >> stuff - trying to wrap my brain around it :) >> >> As the examples all seem to relate to lists, I was wondering if

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Emile van Sebille
On 8/19/2010 7:51 AM Pete said... Hi, I've been reading up on list comprehensions lately, all userful and powerful stuff - trying to wrap my brain around it :) As the examples all seem to relate to lists, I was wondering if there is an elegant similar way to apply a function to all keys in a

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Dave Angel
(You top-posted, so now I have to delete the older part) Vince Spicer wrote: Hey you can use list comprehension here age_dict = { 'pete': 42, 'ann': 25, 'carl': 30, 'amanda': 64 } you can create a dict from a list of tuples and you can access the dict as a list of tuples by accessing its items

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Steven D'Aprano
On Fri, 20 Aug 2010 01:40:54 am Wayne Werner wrote: > > age_dict = dict([(key.upper(), value) for key,value in > > age_dict.items()]) > > This is a bad place to use a list comprehension. This will create a > list of values first and then create a dict from that list, so now > you have a list float

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Shashwat Anand
On Thu, Aug 19, 2010 at 8:21 PM, Pete wrote: > Hi, > > I've been reading up on list comprehensions lately, all userful and > powerful stuff - trying to wrap my brain around it :) > > As the examples all seem to relate to lists, I was wondering if there is an > elegant similar way to apply a funct

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Wayne Werner
On Thu, Aug 19, 2010 at 10:02 AM, Vince Spicer wrote: > Hey you can use list comprehension here > > > age_dict = { 'pete': 42, 'ann': 25, 'carl': 30, 'amanda': 64 } > > you can create a dict from a list of tuples and you can access the dict as > a > list of tuples by accessing its items > > Examp

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Peter Otten
Pete wrote: > Hi, > > I've been reading up on list comprehensions lately, all userful and > powerful stuff - trying to wrap my brain around it :) > > As the examples all seem to relate to lists, I was wondering if there is > an elegant similar way to apply a function to all keys in a dictionary?

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Vince Spicer
Hey you can use list comprehension here age_dict = { 'pete': 42, 'ann': 25, 'carl': 30, 'amanda': 64 } you can create a dict from a list of tuples and you can access the dict as a list of tuples by accessing its items Example: age_dict = dict([(key.upper(), value) for key,value in age_dict.item

[Tutor] List comprehension for dicts?

2010-08-19 Thread Pete
Hi, I've been reading up on list comprehensions lately, all userful and powerful stuff - trying to wrap my brain around it :) As the examples all seem to relate to lists, I was wondering if there is an elegant similar way to apply a function to all keys in a dictionary? (without looping over i

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-29 Thread Matthew Wood
On Fri, May 28, 2010 at 6:55 PM, Steven D'Aprano wrote: > On Fri, 28 May 2010 12:00:46 pm Matthew Wood wrote: > > > I THOUGHT the guaranteed same-ordering of dict.keys and dict.values > > started in python 2.6. That was a simple mistake. > > > > It turns out, that's not the case. But in general,

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Luke Paireepinart
> I'm new to python, so i don't know if this is important, or what it means at > all.  I looked in setup.py, and it didn't tell me anything.  What does it > mean by "the necessary bits" were not found? Not really sure, but in the future please create a new e-mail to tutor@python.org rather than

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Karl Jansson
I was trying to build python, and this printed to the terminal: Python build finished, but the necessary bits to build these modules were not found: _gdbm ossaudiodevreadline spwd To find the necessary bits, look in se

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Steven D'Aprano
On Fri, 28 May 2010 12:00:46 pm Matthew Wood wrote: > I THOUGHT the guaranteed same-ordering of dict.keys and dict.values > started in python 2.6. That was a simple mistake. > > It turns out, that's not the case. But in general, access to dicts > and sets is unordered, so you can't/don't/shouldn

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Peter Otten
David Perlman wrote: > Oh, except one problem: the csv.DictWriter lets you tell it what order > you want the columns output in. With your version, they just show up > in whatever order Python wants them. That's not hard to fix: >>> fieldnames = "abca" >>> cols = [data[fn] for fn in fieldnames]

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread David Perlman
Oh, except one problem: the csv.DictWriter lets you tell it what order you want the columns output in. With your version, they just show up in whatever order Python wants them. On May 28, 2010, at 2:33 AM, Peter Otten wrote: I think it's simpler and therefore more appropriate to use a norm

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread David Perlman
Aha, now this is the clever solution that I didn't find "outside the box". :) On May 28, 2010, at 2:33 AM, Peter Otten wrote: I think it's simpler and therefore more appropriate to use a normal csv.writer here: import csv import sys data = {'a': [1, 2, 3], 'c': [7, 8, 9], 'b': [4, 5, 6]} w

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Sander Sweers
2010/5/28 spir ☣ : > his is a different feature from preserving *input* order of of keys, or of > key:value pairs. In Python 2.7 and 3.1 [1] we now have the OrderedDict which does preserve input order. Greets Sander [1] http://www.python.org/dev/peps/pep-0372/ __

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread spir ☣
On Thu, 27 May 2010 20:00:46 -0600 Matthew Wood wrote: > I THOUGHT the guaranteed same-ordering of dict.keys and dict.values started > in python 2.6. That was a simple mistake. > > It turns out, that's not the case. But in general, access to dicts and sets > is unordered, so you can't/don't/sh

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Peter Otten
David Perlman wrote: > Using the csv.DictReader and csv.DictWriter lets you read and write > lists of dictionaries from files containing tabular data. I have a > system that naturally generates tabular data in the form of a > dictionary of lists: the dictionary key is the name of the column, and

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
Wow. Something horrible happened here. http://xkcd.com/386/ I THOUGHT the guaranteed same-ordering of dict.keys and dict.values started in python 2.6. That was a simple mistake. It turns out, that's not the case. But in general, access to dicts and sets is unordered, so you can't/don't/shoul

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Steven D'Aprano
On Fri, 28 May 2010 09:44:36 am Matthew Wood wrote: > That said, the version with an extra line will work on python < 2.6, > so I'd probably just leave it that way. Why? That's like saying: "I could write y = x+2 in Python, but y = 1+x+1 will work too, so I'll write that instead, just in case.

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Steven D'Aprano
On Fri, 28 May 2010 09:19:20 am Matthew Wood wrote: > I BELIEVE there's some new cool features in 2.6 or maybe 3.0 where > non-simultaneous access to my_dict.keys() and my_dict.values() will > keep them "paired up", but I don't know the details. This is not a new feature, but a very old feature.

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
Well, that makes a lot of sense. I probably should have looked it up. :-) That said, the version with an extra line will work on python < 2.6, so I'd probably just leave it that way. But thanks the docs pointer. Always useful. That said, if I KNEW that my software was only to be implemented

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Mark Lawrence
I confess that I don't like top posting :) Please see below. On 28/05/2010 00:19, Matthew Wood wrote: #!/usr/bin/env python Here's my best attempt. I'm not sure if it's "simpler" than yours, but for me it seems a bit cleaner. Then again, I LOVE the zip operator, and the '*' operator too. :

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
#!/usr/bin/env python Here's my best attempt.  I'm not sure if it's "simpler" than yours, but for me it seems a bit cleaner.  Then again, I LOVE the zip operator, and the '*' operator too.  :-)  Whenever I see a "transpose this" type problem, I think zip. y = {'a': [1, 2, 3], 'c': [7, 8, 9], 'b

[Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread David Perlman
Using the csv.DictReader and csv.DictWriter lets you read and write lists of dictionaries from files containing tabular data. I have a system that naturally generates tabular data in the form of a dictionary of lists: the dictionary key is the name of the column, and then the value is a li

Re: [Tutor] List comprehension + lambdas - strange behaviour

2010-05-07 Thread Steven D'Aprano
On Fri, 7 May 2010 05:11:38 pm spir ☣ wrote: > On Thu, 6 May 2010 22:15:34 +0100 > > "Alan Gauld" wrote: > > As others have pointed out you are returning a reference not a > > value. Others have said that, but it's not true. Python does not have "references". The Python implementation under the

Re: [Tutor] List comprehension + lambdas - strange behaviour

2010-05-07 Thread spir ☣
On Thu, 6 May 2010 22:15:34 +0100 "Alan Gauld" wrote: > As others have pointed out you are returning a reference not a value. Yes. (I have said that, too.) But still there is a mystery for me. Better explained byt the following: x = 0 ; print id(x) # an address def f() : print x # 0

Re: [Tutor] List comprehension + lambdas - strange behaviour

2010-05-06 Thread Alan Gauld
I found this strange behaviour of lambdas, closures and list comprehensions: funs = [lambda: x for x in range(5)] [f() for f in funs] [4, 4, 4, 4, 4] Of course I was expecting the list [0, 1, 2, 3, 4] as the result. The 'x' was bound to the final value of 'range(5)' expression for

Re: [Tutor] List comprehension + lambdas - strange behaviour

2010-05-06 Thread spir ☣
On Thu, 06 May 2010 16:53:07 -0300 Ricardo Aráoz wrote: > So you see, your functions just return the value of x. That's because > the lambda have no parameter, so x refers to the global name x. In other words, the "upvalue" (the variable captured in the closure) is referenced. Meaning if you la

Re: [Tutor] List comprehension + lambdas - strange behaviour

2010-05-06 Thread Ricardo Aráoz
Artur Siekielski wrote: > Hello. > I found this strange behaviour of lambdas, closures and list > comprehensions: > > funs = [lambda: x for x in range(5)] [f() for f in funs] > [4, 4, 4, 4, 4] > > Of course I was expecting the list [0, 1, 2, 3, 4] as the result. The > 'x'

[Tutor] List index usage: is there a more pythonesque way?

2010-04-19 Thread C M Caine
Spir sent this solely to me by accident, I think. -- Forwarded message -- From: spir ☣ Date: 2010/4/19 Subject: Re: [Tutor] List index usage: is there a more pythonesque way? To: cmca...@googlemail.com On Mon, 19 Apr 2010 12:59:40 +0100 C M Caine wrote: > That's t

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-19 Thread Wayne Werner
On Mon, Apr 19, 2010 at 9:23 AM, Alan Gauld wrote: > > "C M Caine" wrote > >> That's the first I've read of iterating through dictionaries, I'd >> >> assumed it was impossible because they're unordered. >> > > Iteration doesn't require order, only to get each item once. > Even in very old Python

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-19 Thread Alan Gauld
"C M Caine" wrote That's the first I've read of iterating through dictionaries, I'd assumed it was impossible because they're unordered. Iteration doesn't require order, only to get each item once. Even in very old Python versions you could iterate a dictionary via the keys() method. More

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-19 Thread C M Caine
That's the first I've read of iterating through dictionaries, I'd assumed it was impossible because they're unordered. Your explanation for defining your own iterables is much easier to understand than the one I read before as well. Thanks again. 2010/4/19 spir ☣ : > On Mon, 19 Apr 2010 00:37:11

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-19 Thread spir ☣
On Mon, 19 Apr 2010 00:37:11 +0100 C M Caine wrote: > That's two new things I've learnt. I didn't realise that for loops > could be used like that (with more than one... key?). Consider considering things differently: a for loop always iterates over items of a collection you indicate: l = [1,2

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-19 Thread ALAN GAULD
> That's two new things I've learnt. I didn't realise that for loops > could be used like that (with more than one... key?). Technically its still one key but enumerate returns a tuple of index and value and we use tuple unpacking to assign the values to the loop variables. That is we could writ

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-18 Thread C M Caine
> Something is wrong in the following if statement, as both paths execute the > same code. > >>             if spaceDict['1st'+key] == 0: >>                 spaceDict['nth'+key] = i >>             else: >>                 spaceDict['nth'+key] = i >>         for form in forms: >>             adjuste

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-18 Thread C M Caine
That's two new things I've learnt. I didn't realise that for loops could be used like that (with more than one... key?). Thanks, I'm changing my code even now! On 19 April 2010 00:09, Alan Gauld wrote: > > "C M Caine" wrote > >>       for i in range(len(timetable)): >>           numDict[timetab

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-18 Thread bob gailer
On 4/18/2010 6:53 PM, C M Caine wrote: # Example data for forms and timetable: forms = ["P7", "P8", "P9", "P10", "P11", "S7", "S8", "S9", "S10", "S11", "IMA", "CAT", "FOR", "RLS", "EMPTY"] timetable = ['CAT', 'P10', 'P8', 'EMPTY', 'EMPTY', 'EMPTY', 'S10', 'S8', 'IMA', 'EMPTY', 'S7', 'S10', 'P9',

Re: [Tutor] List index usage: is there a more pythonesque way?

2010-04-18 Thread Alan Gauld
"C M Caine" wrote for i in range(len(timetable)): numDict[timetable[i]] += 1 if spaceDict['1st'+timetable[i]] == 0: spaceDict['nth'+timetable[i]] = i for index, item in enumerate(timetable): numDict[item] += 1 if spaceDict[

[Tutor] List index usage: is there a more pythonesque way?

2010-04-18 Thread C M Caine
# Example data for forms and timetable: forms = ["P7", "P8", "P9", "P10", "P11", "S7", "S8", "S9", "S10", "S11", "IMA", "CAT", "FOR", "RLS", "EMPTY"] timetable = ['CAT', 'P10', 'P8', 'EMPTY', 'EMPTY', 'EMPTY', 'S10', 'S8', 'IMA', 'EMPTY', 'S7', 'S10', 'P9', 'EMPTY', 'EMPTY', 'EMPTY', 'S7', 'EMPTY'

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Alan Gauld
"Steven D'Aprano" wrote List comps can include *any* comparison: [x+1 for x in data if (3*x+2)**2 > 100*x or x < -5] Sure, but the wording suggested (maybe wrongly) that the OP was a real beginner and so the concept of an expression was likely to be foreign. Sticking with equalty or inequa

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Steven D'Aprano
On Thu, 4 Mar 2010 05:18:40 am Alan Gauld wrote: > "Steven D'Aprano" wrote > > > Comparisons with None almost always should be one of: > > > > item is None > > item is not None > > Yes, but the reason I changed it (I originally had "is not") is that > != is a more general test for illustrating the

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Alan Gauld
"Steven D'Aprano" wrote Comparisons with None almost always should be one of: item is None item is not None Yes, but the reason I changed it (I originally had "is not") is that != is a more general test for illustrating the use of 'if' within a LC which seemed to be the real issue within the

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Steven D'Aprano
On Wed, 3 Mar 2010 07:46:39 pm Alan Gauld wrote: > mylist = [irtem for item in aList where item != None] Comparisons with None almost always should be one of: item is None item is not None The reason is that "item is None" is ONLY ever true if the item actually is the singleton object None (ac

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread C.T. Matsumoto
Dave Angel wrote: Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo Are there any

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Jojo Mwebaze
Thanks to everyone, nice ideas! cheers On Wed, Mar 3, 2010 at 10:02 AM, Christian Witts wrote: > Jojo Mwebaze wrote: > >> Hi There, >> >> i would like to implement the following in lists >> >> assuming >> >> x = 3 >> y = 4 >> z = None >> >> i want to create a dynamic list such that >> >> mylist

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Dave Angel
Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo Are there any constraints on x an

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Christian Witts
Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo --

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread C.T. Matsumoto
Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo --

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Alan Gauld
"Jojo Mwebaze" wrote i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Assuming you actually mean that you don;t want to include any item

[Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Jojo Mwebaze
Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo ___ Tutor maillis

Re: [Tutor] list to numpy record array

2010-02-23 Thread Vincent Davis
@Skipper Thanks I will post over on the scipy list *Vincent Davis 720-301-3003 * vinc...@vincentdavis.net my blog | LinkedIn On Tue, Feb 23, 2010 at 10:55 AM, Skipper Seabold wrote: > On Mon, Feb 22, 2010 at 11:50 PM, Vincen

Re: [Tutor] list to numpy record array

2010-02-23 Thread Skipper Seabold
On Mon, Feb 22, 2010 at 11:50 PM, Vincent Davis wrote: > > I must be missing something simple. I have a list of lists data = "[['  0', ' >  0', '234.0', '24.0', ' 25'], ['  1', '  0', '22428.0', '2378.1', ' > 25'],.." and what to make a record array from it but it gets screwed up > or I don

Re: [Tutor] list to numpy record array

2010-02-23 Thread Vincent Davis
@Kent All I know about RecordArrays is from reading this page: http://www.scipy.org/RecordArrays but it looks like you have done the right thing and created a RecordArray. What is wrong with this result? The number are completely different, or I have no idea how to read it. Here are the first row

Re: [Tutor] list to numpy record array

2010-02-23 Thread Kent Johnson
On Mon, Feb 22, 2010 at 11:50 PM, Vincent Davis wrote: > > I must be missing something simple. I have a list of lists data = "[['  0', ' >  0', '234.0', '24.0', ' 25'], ['  1', '  0', '22428.0', '2378.1', ' > 25'],.." and what to make a record array from it but it gets screwed up > or I don

[Tutor] list to numpy record array

2010-02-22 Thread Vincent Davis
I must be missing something simple. I have a list of lists data = "[[' 0', ' 0', '234.0', '24.0', ' 25'], [' 1', ' 0', '22428.0', '2378.1', ' 25'],.." and what to make a record array from it but it gets screwed up or I don't get it, maybe both. Notice that at this stage the items are string

Re: [Tutor] List append method: St Petersburg Game

2010-02-20 Thread AG
bob gailer wrote: On 2/20/2010 7:43 AM, AG wrote: Please let me know how I can clarify my question 1 - You are giving way too much information. We do not need to know the rules of the game or all the code. Our time to read email is limited. The less you tell us that is not relevant the be

Re: [Tutor] List append method: St Petersburg Game

2010-02-20 Thread bob gailer
On 2/20/2010 7:43 AM, AG wrote: Hi Pythonistas I am having difficulty with applying the list.append(x) method to produce a list that will contain outputs which will become coordinates for a later call to Matplotlib. Perhaps someone here can help me figure this out? Please let me know how

[Tutor] List append method: St Petersburg Game

2010-02-20 Thread AG
Hi Pythonistas I am having difficulty with applying the list.append(x) method to produce a list that will contain outputs which will become coordinates for a later call to Matplotlib. Perhaps someone here can help me figure this out? The basic program is below: # St Petersburg Game: v. 2:

Re: [Tutor] Tutor list as pair progamming plush toy

2010-02-13 Thread Steven D'Aprano
On Sat, 13 Feb 2010 02:33:04 am Mac Ryan wrote: > whenever I get stuck, I begin to write a message to the > list, and in the process of explaining what is the intended behaviour > and outcome of my code, I systematically find the bug by myself. [...] > Does anybody else experience the same? Yes!

Re: [Tutor] Tutor list as pair progamming plush toy

2010-02-12 Thread Alan Gauld
"Mac Ryan" wrote I know - this is slightly OT for the list - but I thought to share as maybe this is a "hidden benefit" the list is bringing to a few people without the tutors even knowing it. Actually I think it is bang on topic. One of the most common benefits of any online community is

Re: [Tutor] Tutor list as pair progamming plush toy

2010-02-12 Thread David Hutto
--- On Fri, 2/12/10, Hansen, Mike wrote: From: Hansen, Mike Subject: Re: [Tutor] Tutor list as pair progamming plush toy To: tutor@python.org Date: Friday, February 12, 2010, 11:55 AM > -Original Message- > From: tutor-bounces+mike.hansen=atmel@python.org > [mai

<    1   2   3   4   5   6   7   8   >