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 Alan Gauld
Francesco Loffredo f...@libero.it 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

[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 of dict question

2010-10-08 Thread Alan Gauld
Roelof Wobben rwob...@hotmail.com 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

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 : tournooi = [{'thuis': 'A','uit': B,'thuisscore': 20, 'uitscore

Re: [Tutor] list of dict question

2010-10-08 Thread Francesco Loffredo
Il 08/10/2010 10.02, Alan Gauld ha scritto: Roelof Wobben rwob...@hotmail.com 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

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

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-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 list

Re: [Tutor] list comprehension, efficiency?

2010-09-28 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

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 comprehensions

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? If so, why?

[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 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

Re: [Tutor] list dll functions?

2010-09-15 Thread Alan Gauld
Alex Hall mehg...@gmail.com 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

Re: [Tutor] list dll functions?

2010-09-15 Thread ALAN GAULD
the parameters etc. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Original Message From: Alex Hall mehg...@gmail.com To: Alan Gauld alan.ga...@btinternet.com Sent: Wednesday, 15 September, 2010 15:57:43 Subject: Re: [Tutor] list dll functions? On 9/15

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 virus

[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 am

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 subscription

Re: [Tutor] list dll functions?

2010-09-14 Thread Alex Hall
On 9/14/10, R. Alan Monroe amon...@columbus.rr.com 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

[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

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,

Re: [Tutor] List comprehension for dicts?

2010-08-20 Thread Alan Gauld
Steven D'Aprano st...@pearwood.info 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 =

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 st...@pearwood.info 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

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'Apranost...@pearwood.info 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

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: x5, [1,4,6,4,1]) -- 1 4 for x in iterable: if predicate(x):

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 like

[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

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 Wayne Werner
On Thu, Aug 19, 2010 at 10:02 AM, Vince Spicer vi...@vinces.ca 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 Shashwat Anand
On Thu, Aug 19, 2010 at 8:21 PM, Pete pkoe...@xs4all.nl 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

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 floating

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

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 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 there is an

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

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 st...@pearwood.infowrote: 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

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-28 Thread spir ☣
On Thu, 27 May 2010 20:00:46 -0600 Matthew Wood woodm1...@gmail.com 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

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

2010-05-28 Thread Sander Sweers
2010/5/28 spir ☣ denis.s...@gmail.com: 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 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]}

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

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

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

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

[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

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

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
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 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. It

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

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

2010-05-07 Thread spir ☣
On Thu, 6 May 2010 22:15:34 +0100 Alan Gauld alan.ga...@btinternet.com 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

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 alan.ga...@btinternet.com 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

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' was bound to the

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

2010-05-06 Thread spir ☣
On Thu, 06 May 2010 16:53:07 -0300 Ricardo Aráoz ricar...@gmail.com 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.

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 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 write

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 cmca...@googlemail.com 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

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 ☣ denis.s...@gmail.com: On Mon,

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

2010-04-19 Thread Alan Gauld
C M Caine cmca...@googlemail.com 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

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 alan.ga...@btinternet.comwrote: C M Caine cmca...@googlemail.com 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

[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 ☣ denis.s...@gmail.com 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 cmca

[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', 'EMPTY', 'RLS', 'FOR',

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

2010-04-18 Thread Alan Gauld
C M Caine cmca...@googlemail.com 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

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', 'EMPTY', 'EMPTY', 'EMPTY',

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 alan.ga...@btinternet.com wrote: C M Caine cmca...@googlemail.com wrote       for i in

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:            

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

2010-03-03 Thread Alan Gauld
Jojo Mwebaze jojo.mweb...@gmail.com 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

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

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 cwi...@compuscan.co.zawrote: 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

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

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 st...@pearwood.info 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

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

2010-03-03 Thread Alan Gauld
Steven D'Aprano st...@pearwood.info 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

Re: [Tutor] list to numpy record array

2010-02-23 Thread Kent Johnson
On Mon, Feb 22, 2010 at 11:50 PM, Vincent Davis vinc...@vincentdavis.net 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

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

[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

[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] 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

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: snip 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

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!

[Tutor] Tutor list as pair progamming plush toy

2010-02-12 Thread Mac Ryan
Have you ever got that piece of advice about - when you have stuck on a bug you seem unable to track - getting a plush toy to whom you explain your code? (This is of course a workaround if you do not have a fellow developer to help you out). Well... I found out this advice kind of works for me,

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

2010-02-12 Thread Serdar Tumgoren
In similar vein, I find that a concept suddenly makes more sense to me when I try to explain it to someone else (or I realize that I don't fully understand and need to do some more research). But with regard to the plush toy you mention, I just ran into that anecdote in Coders at Work. Can't

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

2010-02-12 Thread Hansen, Mike
-Original Message- From: tutor-bounces+mike.hansen=atmel@python.org [mailto:tutor-bounces+mike.hansen=atmel@python.org] On Behalf Of Mac Ryan Sent: Friday, February 12, 2010 8:33 AM To: tutor@python.org Subject: [Tutor] Tutor list as pair progamming plush toy Have

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

2010-02-12 Thread Wayne Werner
I've discovered that same thing. Usually I end out not sending my message because in the process of composing my email I end out I, too, find the errors. -Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

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

2010-02-12 Thread David Hutto
--- On Fri, 2/12/10, Hansen, Mike mike.han...@atmel.com wrote: From: Hansen, Mike mike.han...@atmel.com 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

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

2010-02-12 Thread Alan Gauld
Mac Ryan quasipe...@gmail.com 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

Re: [Tutor] List Comprehension question

2010-02-08 Thread Luke Paireepinart
On Mon, Feb 8, 2010 at 4:15 PM, intern...@shaneferguson.com wrote: I've been trying to work my way through some 'beginner projects' I found around the web, one of them involves generating some random numbers. I decided to use a list of lists, and I'm wondering if this is a valid

Re: [Tutor] list comprehensions

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 1:21 AM, wesley chun wes...@gmail.com wrote: [generator expressions] are lazy because you iterate over the values one at a time instead of creating the entire list. they are slightly slower but save memory. I don't think you can make a blanket statement comparing speed

[Tutor] list comprehensions

2009-10-08 Thread Christer Edwards
I've been studying python now for a few weeks and I've recently come into list comprehensions. Some of the examples that I've found make sense, and I find them readable and concise. In particular I'm referring to the python docs on the topic

Re: [Tutor] list comprehensions

2009-10-08 Thread Gregor Lingl
Christer Edwards schrieb: I've been studying python now for a few weeks and I've recently come into list comprehensions. Some of the examples that I've found make sense, and I find them readable and concise. In particular I'm referring to the python docs on the topic

Re: [Tutor] list comprehensions

2009-10-08 Thread Oxymoron
Hello, On Wed, Oct 7, 2009 at 6:57 AM, Christer Edwards christer.edwa...@gmail.com wrote: do something to x for each x in list, with an optional qualifier. To be more precise: http://docs.python.org/tutorial/datastructures.html#list-comprehensions Each list comprehension consists of an

Re: [Tutor] list comprehensions

2009-10-08 Thread wesley chun
I've been studying python now for a few weeks and I've recently come into list comprehensions. [...] Those make sense to me. The way I understand them is: do something to x for each x in list, with an optional qualifier. that's pretty much correct. On the other hand I've seen a few

Re: [Tutor] list sort problem solved

2009-09-20 Thread Rayon
evosw...@hotmail.com Cc: tutor@python.org Subject: Re: [Tutor] list sort problem Rayon wrote: ok so here it is I think this one should be very clear: I have some data in a list, the data in question: 0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 521 0.095'],['None

Re: [Tutor] list sort problem solved

2009-09-20 Thread Dave Angel
PM To: Rayon evosw...@hotmail.com Cc: tutor@python.org Subject: Re: [Tutor] list sort problem Rayon wrote: ok so here it is I think this one should be very clear: I have some data in a list, the data in question: 0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 521

[Tutor] list sort problem

2009-09-19 Thread Rayon
ok so here it is I think this one should be very clear: I have some data in a list, the data in question: 0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 521 0.095'],['None'] 0.0083,0.0192,0.0109,39023821,['MCI 39023821 0.0109'],['ATT 39 0.012'],['IDT 39

Re: [Tutor] list sort problem

2009-09-19 Thread Dave Angel
Rayon wrote: ok so here it is I think this one should be very clear: I have some data in a list, the data in question: 0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 521 0.095'],['None'] 0.0083,0.0192,0.0109,39023821,['MCI 39023821 0.0109'],['ATT 39 0.012'],['IDT

<    1   2   3   4   5   6   7   >