Re: [Tutor] misunderstanding "any"

2012-03-06 Thread col speed
On 7 March 2012 11:50, Mark Lawrence wrote: > On 07/03/2012 04:36, col speed wrote: >> >> On 7 March 2012 10:45, Mark Lawrence  wrote: >>> >>> On 07/03/2012 03:24, col speed wrote: > >> I *think* I understand: >> Where it says: >> "For the list and tuple types, ``x in y`` is true if and only if th

Re: [Tutor] misunderstanding "any"

2012-03-06 Thread Mark Lawrence
On 07/03/2012 04:36, col speed wrote: On 7 March 2012 10:45, Mark Lawrence wrote: On 07/03/2012 03:24, col speed wrote: Hello again Hope you are all well. I'm trying to make a "match 3" game, where you have a square grid and have to put 3 matching shapes in a row. I need a function that tell

Re: [Tutor] misunderstanding "any"

2012-03-06 Thread col speed
On 7 March 2012 10:45, Mark Lawrence wrote: > On 07/03/2012 03:24, col speed wrote: >> >> Hello again >> Hope you are all well. >> >> I'm trying to make a "match 3" game, where you have a square grid and >> have to put 3 matching shapes in a row. >> I need a function that tells me if the game is p

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Jerry Hill
On Tue, Mar 6, 2012 at 6:21 PM, Alan Gauld wrote: > But it doesn't have the same dynamic depth that the Perl version has, you > need to know your maximum depth. The last level will always have the default > set to None. > > You could create a class subclassed from defaultdict that would do it > th

Re: [Tutor] misunderstanding "any"

2012-03-06 Thread Mark Lawrence
On 07/03/2012 03:24, col speed wrote: Hello again Hope you are all well. I'm trying to make a "match 3" game, where you have a square grid and have to put 3 matching shapes in a row. I need a function that tells me if the game is playable, ie. it is possible to match 3 shapes by only swapping 2

[Tutor] misunderstanding "any"

2012-03-06 Thread col speed
Hello again Hope you are all well. I'm trying to make a "match 3" game, where you have a square grid and have to put 3 matching shapes in a row. I need a function that tells me if the game is playable, ie. it is possible to match 3 shapes by only swapping 2 adjacent shapes. I have looked at the co

Re: [Tutor] inserting new lines in long strings while printing

2012-03-06 Thread Abhishek Pratap
thanks guys .. -Abhi On Tue, Mar 6, 2012 at 5:41 PM, Steven D'Aprano wrote: > On Tue, Mar 06, 2012 at 05:26:26PM -0800, Abhishek Pratap wrote: > > I have this one big string in python which I want to print to a file > > inserting a new line after each 100 characters. Is there a slick way to >

Re: [Tutor] inserting new lines in long strings while printing

2012-03-06 Thread Steven D'Aprano
On Tue, Mar 06, 2012 at 05:26:26PM -0800, Abhishek Pratap wrote: > I have this one big string in python which I want to print to a file > inserting a new line after each 100 characters. Is there a slick way to do > this without looping over the string. I am pretty sure there shud be > something it

Re: [Tutor] inserting new lines in long strings while printing

2012-03-06 Thread Mark Lawrence
On 07/03/2012 01:26, Abhishek Pratap wrote: I have this one big string in python which I want to print to a file inserting a new line after each 100 characters. Is there a slick way to do this without looping over the string. I am pretty sure there shud be something its just I am new to the lang

[Tutor] inserting new lines in long strings while printing

2012-03-06 Thread Abhishek Pratap
I have this one big string in python which I want to print to a file inserting a new line after each 100 characters. Is there a slick way to do this without looping over the string. I am pretty sure there shud be something its just I am new to the lang. Thanks! -Abhi

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread David Rock
* Thomas Maier [2012-03-07 00:38]: > Hi David, > Mixed data types in nested data structure are possible in Perl as well: > %hash = (); > $hash{'mylist'} = [1,2,3]; > $hash{'mystring'} = 'string'; > $hash{'mynum'} = 4; > $hash{'anotherhash'} = {}; > $hash{'anotherhash'}{'anotherstring'} = 'string2'

Re: [Tutor] IDLE problems

2012-03-06 Thread Alan Gauld
On 06/03/12 18:12, ALAN GAULD wrote: OK, so from Finder. In that case can you open a Terminal window and drag the python folder into the Terminal - that should navigate you to the same folder. Then try running IDLE by typing python ./idle.py At the terminal prompt. I meant to say that this w

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Alan Gauld
On 06/03/12 18:18, Martin A. Brown wrote: : $hash->{$a}->{$b}->{$c} = "value"; : if (exists $hash->{$a}->{$b}->{$c} ){ print "found value"} Autovivifying. That's what the perl-heads call that. Aha!, that brought it back, now I know what it does... >>> import collections >>> d =

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Thomas Maier
On Tue, Mar 6, 2012 at 8:19 PM, David Rock wrote: > * Abhishek Pratap [2012-03-06 09:50]: >> Hi Guys >> >> I am looking for a way to build dictionaries of dict in python. >> >> For example in perl I could do >> >> my $hash_ref = {}; >> $hash->{$a}->{$b}->{$c} = "value"; >> if (exists $hash->{$a}-

Re: [Tutor] count numbers only in the string

2012-03-06 Thread Joel Goldstick
On Tue, Mar 6, 2012 at 3:58 PM, Joel Goldstick wrote: > On Tue, Mar 6, 2012 at 3:49 PM, Joel Goldstick > wrote: >> On Tue, Mar 6, 2012 at 3:07 PM, kumar s wrote: >>> Hi : >>> >>> I have some strings with both alpha-numeric strings. I want to add all the >>> numbers in that string and leave cha

Re: [Tutor] count numbers only in the string

2012-03-06 Thread Joel Goldstick
On Tue, Mar 6, 2012 at 3:49 PM, Joel Goldstick wrote: > On Tue, Mar 6, 2012 at 3:07 PM, kumar s wrote: >> Hi : >> >> I have some strings with both alpha-numeric strings. I want to add all the >> numbers in that string and leave characters and special characters. >> 1A0G19 >> >> 5G0C25^C52 >> >>

Re: [Tutor] count numbers only in the string

2012-03-06 Thread Joel Goldstick
On Tue, Mar 6, 2012 at 3:07 PM, kumar s wrote: > Hi : > > I have some strings with both alpha-numeric strings. I want to add all the > numbers in that string and leave characters and special characters. > 1A0G19 > > 5G0C25^C52 > > 0G2T3T91 > 44^C70 > > How can I count only the numbers in the abov

Re: [Tutor] count numbers only in the string

2012-03-06 Thread Prasad, Ramit
> -Original Message- > From: tutor-bounces+ramit.prasad=jpmorgan@python.org [mailto:tutor- > bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of kumar s > Sent: Tuesday, March 06, 2012 2:08 PM > To: tutor@python.org > Subject: [Tutor] count numbers only in the string > > Hi : >

[Tutor] count numbers only in the string

2012-03-06 Thread kumar s
Hi : I have some strings with both alpha-numeric strings. I want to add all the numbers in that string and leave characters and special characters.  1A0G19 5G0C25^C52 0G2T3T91 44^C70 How can I count only the numbers in the above.  1 A 0 G 19       =    1+0+19 = 20 5 G 0 C 25 ^C 52  =   5+0+2

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Martin A. Brown
Hello there Abhi, : I am looking for a way to build dictionaries of dict in python. : : For example in perl I could do : : my $hash_ref = {}; : $hash->{$a}->{$b}->{$c} = "value"; : if (exists $hash->{$a}->{$b}->{$c} ){ print "found value"} Autovivifying. That's what the perl-heads call

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Alan Gauld
On 06/03/12 17:50, Abhishek Pratap wrote: I am looking for a way to build dictionaries of dict in python. Thats not a problem, you just nest them: d1 = {key: value,...} # a single level dictionary d2 = {key: d1, ...} # a dictionary of dictionaries... d3 = { key1: {key2: value, ...}, ...}

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Joel Goldstick
On Tue, Mar 6, 2012 at 12:50 PM, Abhishek Pratap wrote: > Hi Guys > > I am looking for a way to build dictionaries of dict in python. > > For example in perl I could do > > my $hash_ref = {}; > $hash->{$a}->{$b}->{$c} = "value"; > if (exists $hash->{$a}->{$b}->{$c} ){ print "found value"} > > Can

Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread David Rock
* Abhishek Pratap [2012-03-06 09:50]: > Hi Guys > > I am looking for a way to build dictionaries of dict in python. > > For example in perl I could do > > my $hash_ref = {}; > $hash->{$a}->{$b}->{$c} = "value"; > if (exists $hash->{$a}->{$b}->{$c} ){ print "found value"} > > Can I do something

Re: [Tutor] IDLE problems

2012-03-06 Thread ALAN GAULD
Please use ReplyAll to include the group. > formulation of the question. Ultimately the brute question is why > can't I get IDLE to work... > I did uninstall the version that came with mac. > In a terminal I get version 2.7.2(?) OK, That's good because I think that's the same as the default insta

[Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Abhishek Pratap
Hi Guys I am looking for a way to build dictionaries of dict in python. For example in perl I could do my $hash_ref = {}; $hash->{$a}->{$b}->{$c} = "value"; if (exists $hash->{$a}->{$b}->{$c} ){ print "found value"} Can I do something similar with dictionaries in Python. Thanks -Abhi

Re: [Tutor] New project idea!!

2012-03-06 Thread Prasad, Ramit
>So, last year I build a Sudoku solver in C which was an amazing experience >(though re inventing wheel is not a big deal at all), I learned a lot. >Now, I would like to do a similar project using python (which should be quite >acceptable to put on my resume).. Any Ideas please!! >(Note: I am no

Re: [Tutor] New project idea!!

2012-03-06 Thread Surya K
Subject: Re: [Tutor] New project idea!! From: las...@antalconsulting.com Date: Tue, 6 Mar 2012 09:24:12 -0800 CC: tutor@python.org To: sur...@live.com Hi, Since you are an electronics guy, how about a circuit simulator?You can start very simple with a power source and a light and show how th

[Tutor] New project idea!!

2012-03-06 Thread Surya K
Hi, I am an electronics guy, extremely interested in programming. So learned Python. Currently I know (C, Python, HTML); Learning Java, Python (still making myself flexible in OOP). So, last year I build a sudoku solver in C which was an amazing experience (though re inventing wheel is not a bi

Re: [Tutor] question about operator overloading

2012-03-06 Thread Joel Goldstick
On Tue, Mar 6, 2012 at 7:05 AM, Albert-Jan Roskam wrote: > From: Steven D'Aprano > To: tutor@python.org > Sent: Tuesday, March 6, 2012 1:58 AM > > Subject: Re: [Tutor] question about operator overloading > > Alan Gauld wrote: > >> On 05/03/12 21:25, Dave Angel wrote: >> >>> It's not clear what __

Re: [Tutor] question about operator overloading

2012-03-06 Thread Albert-Jan Roskam
From: Steven D'Aprano To: tutor@python.org Sent: Tuesday, March 6, 2012 1:58 AM Subject: Re: [Tutor] question about operator overloading Alan Gauld wrote: >> On 05/03/12 21:25, Dave Angel wrote: >> >>> It's not clear what __add__() should mean for physical files. >> >> My guess would be simila

Re: [Tutor] IDLE problems

2012-03-06 Thread Alan Gauld
On 06/03/12 09:51, Paul Douglas Grant wrote: issue running python on mac snow leopard 10.6.8. I was running a version of python that was preinstalled on my computer. At some point in reading the python website I saw that version 3.2.2 was available and recommended. After downloading and installi

[Tutor] IDLE problems

2012-03-06 Thread Paul Douglas Grant
Hello folks, I am new to programming and choosing python as my first language to learn, thus excuse the perhaps naiveté of this question and the way it is formulated. For the last few weeks I've been trying to solve an issue running python on mac snow leopard 10.6.8. I was running a version of pyt

Re: [Tutor] question about operator overloading

2012-03-06 Thread Alan Gauld
On 06/03/12 02:42, Dave Angel wrote: My guess would be similar to the cat operator in Unix: file3 = file1 + file2 So somehow assigning the object to file3 will write the data to a file by the name "file3" ? I know about __add__(), but didn't know we had __assign__() We don't need any speci

Re: [Tutor] question about operator overloading

2012-03-06 Thread Peter Otten
Dave Angel wrote: > On 03/05/2012 06:20 PM, Alan Gauld wrote: >> On 05/03/12 21:25, Dave Angel wrote: >> >>> It's not clear what __add__() should mean for physical files. >> >> My guess would be similar to the cat operator in Unix: >> >> $ cat file1, file2 > file3 >> >> is equivalent to >> >> file