Re: [Tutor] Pyduino

2009-09-08 Thread Michael Connors
>
>
>
> You wouldn't want to run python on a 16 mhz processor, the interpreter
> would use up all your resources. The Arduino language is not too hard
> to learn.
>
>
>

I have followed some tutorials in the Arduino playground, for talking to the
arduino from Python. You can do things like tell your LED to turn on and off
based on a key press on your computers keyboard, and from there you can
probably figure out how to do plenty of other things.

The coding for the Arduino is still done in the native language, but the
client you use to speak to the connected arduino would be written in Python.

-- 
Michael Connors
Leiden
The Netherlands
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyduino

2009-09-08 Thread Luke Paireepinart
Yes, this is true, but he was asking to use Python *instead* of the Arduino
language.  I really don't think it's too hard to learn the language, it's
really straightforward.

On Tue, Sep 8, 2009 at 9:13 AM, Michael Connors  wrote:

>
>>
>> You wouldn't want to run python on a 16 mhz processor, the interpreter
>> would use up all your resources. The Arduino language is not too hard
>> to learn.
>>
>>
>>
>
> I have followed some tutorials in the Arduino playground, for talking to
> the arduino from Python. You can do things like tell your LED to turn on and
> off based on a key press on your computers keyboard, and from there you can
> probably figure out how to do plenty of other things.
>
> The coding for the Arduino is still done in the native language, but the
> client you use to speak to the connected arduino would be written in Python.
>
> --
> Michael Connors
> Leiden
> The Netherlands
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyduino

2009-09-08 Thread Wayne
On Tue, Sep 8, 2009 at 4:22 AM, Luke Paireepinart wrote:

> Yes, this is true, but he was asking to use Python *instead* of the Arduino
> language.  I really don't think it's too hard to learn the language, it's
> really straightforward.


I'll echo that sentiment. Just following the tutorials you can pretty much
figure out everything you need to know. It's basically a simplified version
of C++.

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks



I am looking at this and wondering:

Why does this use collections.defaultdict ?

In fact i guess since collections.defaultdict is new to me i am not  
even sure why it exists
and why someone would use this as opposed to using Python's built-in  
dictionary? and why was it

used in this instance?

cheers,

-kp--




On Sep 6, 2009, at 3:06 AM, bob gailer wrote:




I want to be able to look at a number/item and see which lists it is  
in so that i could maybe have a master list of all the data, a  
superset, and then an indication of which lists that data  was in,  
as some items will only be in one list, some will appear in two  
lists (x & y, or x & z or y & z) and a small handful will be in all  
three lists.


I think you mean "set" rather than "list"

To enable processing of an arbitrary number of sets, put them in a  
collection (list or dictionary). Use a list if it is sufficient to  
identify sets by number, else use a dictionary.


Use a dictionary to relate items to their set(s).

import collections
lookup = collections.defaultdict(list)
sets = {'x': set((1,2,3)), 'y': set((2,3))}
for key, value in sets.items():
for element in value:
 lookup[element].append(key)
print lookup


0 - x
1 - x
2 - x
3 - x
4 - x
5 - x, y
6 - x, y
7 - x, y
8 - x, y, z
9 - x, y, z
10 - y, x

etc.

Of course the whole point of this is that the sets will be more  
complicated than 0-9, 5-14, and 8-21 and additionally, the sets may  
not be a list of numbers but eventually a list of strings.


So the steps would be to create the superset
then test for membership for each list?

I kinda get it, the thing that warps my brain is the idea that there  
are more than 2 lists now to test against eventually my script  
needs to accommodate 4, 5, 6 sets.. but i would just like to see if  
i can get 3 sets to work first.

--
Bob Gailer
Chapel Hill NC
919-636-4239


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyduino

2009-09-08 Thread Douglas Philips

Check out:
http://us.pycon.org/2009/conference/schedule/event/73/
which has the video of the talk as well.
That was one of the many talks I didn't see in person, and is on my  
queue to watch. Hmmm, just got bumped a lot higher on the queue since  
I've also recently been bitten by the Arduino bug. :)


-Doug


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread bob gailer

kevin parks wrote:



I am looking at this and wondering:

Why does this use collections.defaultdict ?

In fact i guess since collections.defaultdict is new to me i am not 
even sure why it exists
and why someone would use this as opposed to using Python's built-in 
dictionary? and why was it

used in this instance?


It simplifies coding, as it takes care of initializing each new entry to 
a list.



On Sep 6, 2009, at 3:06 AM, bob gailer wrote:




I want to be able to look at a number/item and see which lists it is 
in so that i could maybe have a master list of all the data, a 
superset, and then an indication of which lists that data  was in, as 
some items will only be in one list, some will appear in two lists (x 
& y, or x & z or y & z) and a small handful will be in all three lists.


I think you mean "set" rather than "list"

To enable processing of an arbitrary number of sets, put them in a 
collection (list or dictionary). Use a list if it is sufficient to 
identify sets by number, else use a dictionary.


Use a dictionary to relate items to their set(s).

import collections
lookup = collections.defaultdict(list)
sets = {'x': set((1,2,3)), 'y': set((2,3))}
for key, value in sets.items():
  for element in value:
lookup[element].append(key)
print lookup



--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2009-09-08 Thread Christian Witts

shellc...@juno.com wrote:

I want to write a code that allows me to input a phrase and calculate the 
number of vowels twice. once with the for loop and second with the while loop.I 
can get the for loop to work but, not the while loop. this is my code and 
response.


#demo for loop, and while loop




phrase = raw_input("enter your phrase:")

VOWELS = "aeiou"

number = 0




for letter in phrase:
if letter.lower() in VOWELS:
number = number +1
else:
pass
print "Number of vowels =",number

raw_input("Press the enter key to continue.")

index = 0
while index < len(phrase):
if phrase[index] in VOWELS:

 index = index +1

 print "number of vowels" ,index



enter your phrase:tell me your name
Number of vowels = 0
Number of vowels = 1
Number of vowels = 1
Number of vowels = 1
Number of vowels = 1
Number of vowels = 1
Number of vowels = 2
Number of vowels = 2
Number of vowels = 2
Number of vowels = 3
Number of vowels = 4
Number of vowels = 4
Number of vowels = 4
Number of vowels = 4
Number of vowels = 5
Number of vowels = 5
Number of vowels = 6
Press the enter key to continue.




Best Weight Loss Program - Click Here!
http://thirdpartyoffers.juno.com/TGL2141/fc/BLSrjpTFoYcWEqYCcbHEaFPTq8jdS8V2cC4YnTjQIbcZlB9fvaKI0BwmgT2/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

  
Your while loop will continue indefinitely if the phrase is not 
completely vowels.  What you should do is remember to increment the 
value of index regardless of if the letter is a vowel of not:


VOWELS = 'aeiouAEIOU'
cnt = 0
index = 0
while index < len(phrase):
   if phrase[index] in VOWELS:
   cnt += 1
   print 'Number of Vowels = %s' %cnt
   index += 1

--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks

I also notice that if i do:


def foo():
lookup = collections.defaultdict(list)
x = range(10)
y = range(5, 15)
z = range(8, 22)
sets = {'x': set(x), 'y': set(y), 'z': set(z)}
for key, value in sets.items():
for element in value:
lookup[element].append(key)
for x in lookup:
print x, lookup[x]
print

in oder to print more clearly what I want to see, the sets (as usual  
for a mapping type) are not always in order. Note that from 5 to 7 for  
example 'y' is listed in front of 'x' and 8 & 9 have 'y', 'x', 'z' and  
not 'x', 'y', 'z' ... I am not clear on how to sort that as the  
dictionary 	method lookup.sort() either doesn't work or i have tried  
it in all the wrong places.



0 ['x']
1 ['x']
2 ['x']
3 ['x']
4 ['x']
5 ['y', 'x']
6 ['y', 'x']
7 ['y', 'x']
8 ['y', 'x', 'z']
9 ['y', 'x', 'z']
10 ['y', 'z']
11 ['y', 'z']
12 ['y', 'z']
13 ['y', 'z']
14 ['y', 'z']
15 ['z']
16 ['z']
17 ['z']
18 ['z']
19 ['z']
20 ['z']
21 ['z']

On Sep 8, 2009, at 10:52 PM, bob gailer wrote:


kevin parks wrote:



I am looking at this and wondering:

Why does this use collections.defaultdict ?

In fact i guess since collections.defaultdict is new to me i am not  
even sure why it exists
and why someone would use this as opposed to using Python's built- 
in dictionary? and why was it

used in this instance?


It simplifies coding, as it takes care of initializing each new  
entry to a list.



On Sep 6, 2009, at 3:06 AM, bob gailer wrote:




I want to be able to look at a number/item and see which lists it  
is in so that i could maybe have a master list of all the data, a  
superset, and then an indication of which lists that data  was in,  
as some items will only be in one list, some will appear in two  
lists (x & y, or x & z or y & z) and a small handful will be in  
all three lists.


I think you mean "set" rather than "list"

To enable processing of an arbitrary number of sets, put them in a  
collection (list or dictionary). Use a list if it is sufficient to  
identify sets by number, else use a dictionary.


Use a dictionary to relate items to their set(s).

import collections
lookup = collections.defaultdict(list)
sets = {'x': set((1,2,3)), 'y': set((2,3))}
for key, value in sets.items():
 for element in value:
   lookup[element].append(key)
print lookup



--
Bob Gailer
Chapel Hill NC
919-636-4239


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyduino

2009-09-08 Thread Douglas Philips

Check out:
http://us.pycon.org/2009/conference/schedule/event/73/
which has the video of the talk as well.
That was one of the many talks I didn't see in person, and is on my  
queue to watch. Hmmm, just got bumped a lot higher on the queue  
since I've also recently been bitten by the Arduino bug. :)


For another microcontroller python, there is PyMite:
http://us.pycon.org/2009/openspace/ForEmbeddedSystems/
http://code.google.com/p/python-on-a-chip/

--Doug

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2009-09-08 Thread shellc...@juno.com

I want to write a code that allows me to input a phrase and calculate the 
number of vowels twice. once with the for loop and second with the while loop.I 
can get the for loop to work but, not the while loop. this is my code and 
response.


#demo for loop, and while loop




phrase = raw_input("enter your phrase:")

VOWELS = "aeiou"

number = 0




for letter in phrase:
if letter.lower() in VOWELS:
number = number +1
else:
pass
print "Number of vowels =",number

raw_input("Press the enter key to continue.")

index = 0
while index < len(phrase):
if phrase[index] in VOWELS:

 index = index +1
 print "number of vowels" ,index



enter your phrase:tell me your name
Number of vowels = 0
Number of vowels = 1
Number of vowels = 1
Number of vowels = 1
Number of vowels = 1
Number of vowels = 1
Number of vowels = 2
Number of vowels = 2
Number of vowels = 2
Number of vowels = 3
Number of vowels = 4
Number of vowels = 4
Number of vowels = 4
Number of vowels = 4
Number of vowels = 5
Number of vowels = 5
Number of vowels = 6
Press the enter key to continue.




Best Weight Loss Program - Click Here!
http://thirdpartyoffers.juno.com/TGL2141/fc/BLSrjpTFoYcWEqYCcbHEaFPTq8jdS8V2cC4YnTjQIbcZlB9fvaKI0BwmgT2/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyduino

2009-09-08 Thread Kent Johnson
On Tue, Sep 8, 2009 at 10:11 AM, Douglas Philips wrote:
>> Check out:
>> http://us.pycon.org/2009/conference/schedule/event/73/
>> which has the video of the talk as well.
>> That was one of the many talks I didn't see in person, and is on my queue
>> to watch. Hmmm, just got bumped a lot higher on the queue since I've also
>> recently been bitten by the Arduino bug. :)
>
> For another microcontroller python, there is PyMite:
> http://us.pycon.org/2009/openspace/ForEmbeddedSystems/
> http://code.google.com/p/python-on-a-chip/

Which seems to be running on Arduino Mega:
http://groups.google.com/group/python-on-a-chip/web/step-by-step-on-running-pymite-on-arduino-mega

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2009-09-08 Thread shellc...@juno.com


I,m trying to get a phrase from a user and print it backwards using the for 
statement along with the range function, but all I get with range function is 
integers not alpha. example range(-1) does not work.






message = raw_input("enter a message: ")


# will produce a back ward message by elements 1 @ time

print message[::-1]



raw_input("\n\nPress the enter key to exit.\n")



enter a message: what time is it
ti si emit tahw


Press the enter key to exit.






Get Medical Insurance quotes and compare plans. Click now.
http://thirdpartyoffers.juno.com/TGL2141/fc/BLSrjpTInCRVJAUElsmT5bwVZjc6LtIZ7jXy33NsWVplFqavu7wZrW7Uk9a/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2009-09-08 Thread Lucas Prado Melo
On Tue, Sep 8, 2009 at 10:48 AM, shellc...@juno.com wrote:

>
> I want to write a code that allows me to input a phrase and calculate the
> number of vowels twice. once with the for loop and second with the while
> loop.I can get the for loop to work but, not the while loop. this is my code
> and response.
>
[snip]

> index = 0
> while index < len(phrase):
>if phrase[index] in VOWELS:
>
> index = index +1
> print "number of vowels" ,index
>
This is an infinite loop. When phrase[index] is not in VOWELS, nothing
changes and the test "index < len(phrase)" is still true.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks

Actually,

This seems like it works:

lookup[x].sort()


in like so:

def foo():
lookup = collections.defaultdict(list)
x = range(10)
y = range(5, 15)
z = range(8, 22)
sets = {'x': set(x), 'y': set(y), 'z': set(z)}
for key, value in sets.items():
for element in value:
lookup[element].append(key)
print
print lookup, "\n\n"
for x in lookup:
lookup[x].sort()
print x, lookup[x]
#print type(lookup)
print
#print sets

I realized that i was trying to apply the standard:

k = lookup.keys()
k.sort()

in the wrong way and in the wrong place (i accidentally cut it out in  
my message when i removed the scaffolding)


I might try the tuple things to for educational purposes. I am  
somewhat nervous about using something other than
a built in type as i am not familiar with collections and it isn't  
well covered in beginner books or the docs.




On Sep 9, 2009, at 12:44 AM, Kent Johnson wrote:


On Tue, Sep 8, 2009 at 10:07 AM, kevin parks wrote:

I also notice that if i do:


def foo():
   lookup = collections.defaultdict(list)
   x = range(10)
   y = range(5, 15)
   z = range(8, 22)
   sets = {'x': set(x), 'y': set(y), 'z': set(z)}
   for key, value in sets.items():
   for element in value:
   lookup[element].append(key)
   for x in lookup:
   print x, lookup[x]
   print

in oder to print more clearly what I want to see, the sets (as  
usual for a
mapping type) are not always in order. Note that from 5 to 7 for  
example 'y'
is listed in front of 'x' and 8 & 9 have 'y', 'x', 'z' and not 'x',  
'y', 'z'


Dictionaries and sets are not ordered. The order of items in
sets.items() is an implementation detail, not something you can depend
on.


... I am not clear on how to sort that as the dictionary  method
lookup.sort() either doesn't work or i have tried it in all the wrong
places.


lookup can't be sorted directly as it is a (default)dict. Anyway it is
lookup[x] that you want to sort. Try
 print x, sorted(lookup[x])

or
for x in lookup:
 lookup[x].sort() # list.sort() sorts the list in place and does not
return a value.
 print x, lookup[x]

Another alternative would be to use a list of tuples instead of a dict
for sets, then the lookup values would be created in the desired
order, e.g.
sets = [ (x', set(x)), ('y', set(y)), ('z', set(z)) ]
for key, value in sets:
 # etc

Kent


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks


I guess what i honestly want to asks, but am hesitant to since it  
makes me look like a dork is:


What would this look like if i want to use a straight up built-in  
dictionary type and not the collections.defaultdict.



import collections

def foo():
lookup = collections.defaultdict(list)
x = range(10)
y = range(5, 15)
z = range(8, 22)
sets = {'x': set(x), 'y': set(y), 'z': set(z)}
for key, value in sets.items():
for element in value:
lookup[element].append(key)
print "\n", lookup, "\n\n"
for x in lookup:
lookup[x].sort()
print x, lookup[x]
print "\n"


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2009-09-08 Thread Lucas Prado Melo
On Tue, Sep 8, 2009 at 2:09 PM, shellc...@juno.com wrote:

> I,m trying to get a phrase from a user and print it backwards using the for
> statement along with the range function, but all I get with range function
> is integers not alpha. example range(-1) does not work.
>
> What about range(0, -n, -1) ?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread Kent Johnson
On Tue, Sep 8, 2009 at 10:07 AM, kevin parks wrote:
> I also notice that if i do:
>
>
> def foo():
>        lookup = collections.defaultdict(list)
>        x = range(10)
>        y = range(5, 15)
>        z = range(8, 22)
>        sets = {'x': set(x), 'y': set(y), 'z': set(z)}
>        for key, value in sets.items():
>                for element in value:
>                        lookup[element].append(key)
>        for x in lookup:
>                print x, lookup[x]
>        print
>
> in oder to print more clearly what I want to see, the sets (as usual for a
> mapping type) are not always in order. Note that from 5 to 7 for example 'y'
> is listed in front of 'x' and 8 & 9 have 'y', 'x', 'z' and not 'x', 'y', 'z'

Dictionaries and sets are not ordered. The order of items in
sets.items() is an implementation detail, not something you can depend
on.

> ... I am not clear on how to sort that as the dictionary      method
> lookup.sort() either doesn't work or i have tried it in all the wrong
> places.

lookup can't be sorted directly as it is a (default)dict. Anyway it is
lookup[x] that you want to sort. Try
  print x, sorted(lookup[x])

or
for x in lookup:
  lookup[x].sort() # list.sort() sorts the list in place and does not
return a value.
  print x, lookup[x]

Another alternative would be to use a list of tuples instead of a dict
for sets, then the lookup values would be created in the desired
order, e.g.
sets = [ (x', set(x)), ('y', set(y)), ('z', set(z)) ]
for key, value in sets:
  # etc

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2009-09-08 Thread Alan Gauld
 wrote in message 

Please specify a meaningful subject line, it makes reading messages 
in a threaded mailtool or newsreader much easier.



#demo for loop, and while loop

phrase = raw_input("enter your phrase:")
VOWELS = "aeiou"
number = 0

for letter in phrase:
   if letter.lower() in VOWELS:
   number = number +1
   else:
   pass


You don't need the else if its only a pass statement.


   print "Number of vowels =",number

raw_input("Press the enter key to continue.")
index = 0
while index < len(phrase):
   if phrase[index] in VOWELS:
index = index +1
print "number of vowels" ,index


The index is the position in the string not the count of vowels.
But you are trying to use the same variable for both. Thats a bad idea.

Because you only increment the position if thre is a vowel you 
get stuck if any letter is not a vowel. You need a new count variable

and keep index just for iterating in the loop..

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread Alan Gauld


"kevin parks"  wrote 

What would this look like if i want to use a straight up built-in  
dictionary type and not the collections.defaultdict.




Not too different:


import collections

def foo():
lookup = collections.defaultdict(list)
x = range(10)
y = range(5, 15)
z = range(8, 22)
sets = {'x': set(x), 'y': set(y), 'z': set(z)}
for key, value in sets.items():
for element in value:

 lookup[element] = lookup.get(element, []).append(key)

print "\n", lookup, "\n\n"
for x in lookup:
 lookup[x].sort()
 print x, lookup[x]
print "\n"


At least I think thats all you need here.

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyduino

2009-09-08 Thread Alan Gauld

"Wayne"  wrote

Yes, this is true, but he was asking to use Python *instead* of the 
Arduino
language.  I really don't think it's too hard to learn the language, 
it's

really straightforward.


I'll echo that sentiment. Just following the tutorials you can pretty 
much
figure out everything you need to know. It's basically a simplified 
version

of C++.


caveat, if you don't know C or C++ there is a huge mountain of things to
learn in migrating from Python. If you already know any C-like langfuage
then the Arduino language is straightforward but from Python alone
you suddenly have braces and semi colons and type definitions and
a welter of other details to learn and understand.

I've only browsed the docs so am no expert but it looks like a pretty
close clone of C with some C++ bits added. But thats a big jump
from Python.

But arguably to get the most out of a tool like Arduino you probably
do need a language like C vthat is conceptuially closer to the machine
than to the user

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread Douglas Philips

On or about 2009 Sep 8, at 1:51 PM, Alan Gauld indited:

"kevin parks"  wrote
What would this look like if i want to use a straight up built-in   
dictionary type and not the collections.defaultdict.


Not too different:


import collections
def foo():
lookup = collections.defaultdict(list)

# Doug: lookup = dict()

x = range(10)
y = range(5, 15)
z = range(8, 22)
sets = {'x': set(x), 'y': set(y), 'z': set(z)}
for key, value in sets.items():
   for element in value:

lookup[element] = lookup.get(element, []).append(key)
# Doug: That doesn't do what you think it does, it won't insert the  
new list into the dictionary.
# Doug: I think what you want is lookup.setdefault(element,  
[]).append(key)

print "\n", lookup, "\n\n"
for x in lookup:
lookup[x].sort()
print x, lookup[x]
print "\n"


At least I think thats all you need here.



>>> help(dict.setdefault)
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D

-Doug


-Doug
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pygtk

2009-09-08 Thread Ajith Gopinath
I will appreciate , if somebody guides me to a proper doc. on pygtk for
2.5/2.6. I am currently unable to find a good doc for the same :o(

Thanks and regards
~|| a j i t ||
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] use case for graphs and generators?

2009-09-08 Thread Serdar Tumgoren
Hi everyone,
I was hoping someone could advise on whether I'm tackling a specific
problem in the correct manner.

Specifically, I'm trying to use a "clean" set of historical data to
fix omissions/errors among a stream of newer data. To do so, I've
devised a series of backend SQL statements which need to be triggered
in various orders depending on the state of my object's attributes.

If my Person object, for example, only has a name and a state, then I
need to execute a SQL statement relying on those attributes to pull
additional information about the Persion. And if that search yields a
unique id for my Person object, then I can fire another SQL statement
that uses the unique ID to pull more attributes from my historical
data. Or, if my Person object happened to be instantiated with a
unique ID, then I can just skip the name/state search (and various
others) and go straight to the ID search.

After each query, I clearly need to inspect the status of the
attributes: once they've all been corrected, I can stop executing
corrective queries and move on to the next Person object.

To implement the above, I was starting to research generators and
graph data structures (e.g.
http://www.python.org/doc/essays/graphs.html).

So my question -- is that indeed the correct approach for what I've
described as the use case? I've never tackled graphs or generators
before, and I figure I have plenty of reading to do before I could
devise a solution relying on both. I'd be grateful if anyone could
weigh in on my approach, or perhaps advise on alternatives.

Regards,
Serdar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pygtk

2009-09-08 Thread Patrick Sabin

The official docs

http://www.pygtk.org/pygtk2tutorial/index.html
http://library.gnome.org/devel/pygtk/stable/

worked for me.

- Patrick

Ajith Gopinath schrieb:
I will appreciate , if somebody guides me to a proper doc. on pygtk 
for 2.5/2.6. I am currently unable to find a good doc for the same :o(


Thanks and regards
~|| a j i t ||


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread Alan Gauld


"Douglas Philips"  wrote 


   for element in value:

lookup[element] = lookup.get(element, []).append(key)
# Doug: That doesn't do what you think it does, it won't insert the  
new list into the dictionary.


Ah, yes I forgot append was one of those annoying python methods 
that doesn't return self...


You need to do it in three lines... One to get the list, 
one to append and one to assign the value...


# Doug: I think what you want is lookup.setdefault(element,  
[]).append(key)


or use setdfault (which I forgot all about! :-)

Thanks for picking that one up Doug.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread Lie Ryan

Alan Gauld wrote:


"kevin parks"  wrote
What would this look like if i want to use a straight up built-in  
dictionary type and not the collections.defaultdict.




Not too different:


Alternatively:


import collections

def foo():
lookup = collections.defaultdict(list)
x = range(10)
y = range(5, 15)
z = range(8, 22)
sets = {'x': set(x), 'y': set(y), 'z': set(z)}
for key, value in sets.items():
for element in value:

   try:
   lookup[element] = lookup[element].append(key)
   except KeyError:
   lookup[element] = [key]

print "\n", lookup, "\n\n"
for x in lookup:
 lookup[x].sort()
 print x, lookup[x]
print "\n"


which I /personally/ found easier to follow than using dict.get()'s or 
defaultdict (YMMV)


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pygtk

2009-09-08 Thread Ajith Gopinath
Thanks Patrik, this is what i am searching for.
|| a j i t ||


On Wed, Sep 9, 2009 at 1:27 AM, Patrick Sabin wrote:

> The official docs
>
> http://www.pygtk.org/pygtk2tutorial/index.html
> http://library.gnome.org/devel/pygtk/stable/
>
> worked for me.
>
> - Patrick
>
> Ajith Gopinath schrieb:
>
>> I will appreciate , if somebody guides me to a proper doc. on pygtk for
>> 2.5/2.6. I am currently unable to find a good doc for the same :o(
>>
>> Thanks and regards
>> ~|| a j i t ||
>> 
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2009-09-08 Thread Christian Witts

Lucas Prado Melo wrote:
On Tue, Sep 8, 2009 at 2:09 PM, shellc...@juno.com 
 > wrote:


I,m trying to get a phrase from a user and print it backwards
using the for statement along with the range function, but all I
get with range function is integers not alpha. example range(-1)
does not work.

What about range(0, -n, -1) ?



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  
That would need to have a starting value of -1 and an end value of 
-(len(phrase)+1).  Of else you can start at length - 1, end at zero and 
a step value of -1.


--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2009-09-08 Thread Alan Gauld


"Christian Witts"  wrote 



What about range(0, -n, -1) ?

That would need to have a starting value of -1 and an end value of 
-(len(phrase)+1).  Of else you can start at length - 1, end at zero and 
a step value of -1.


Another option, using "normal" range values but negative indexing is 


for i in range(1,len(word)+1):
 print word[-i],

Alan G

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] working with multiple sets

2009-09-08 Thread Alan Gauld


"Lie Ryan"  wrote 


for key, value in sets.items():
for element in value:

   try:
   lookup[element] = lookup[element].append(key)


This has the same flaw as mine. it nneeds to be

  lookup[element].append(key)

ie no assignment, othewise you just get None stored...

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor