Re: [Tutor] dict() versus {}

2009-01-21 Thread Mark Tolonen
This: >>> dict(one=1,two=2,three=3) {'three': 3, 'two': 2, 'one': 1} Is a shortcut for the longer: >>> dict((('one',1),('two',2),('three',3))) {'three': 3, 'two': 2, 'one': 1} and given how this works: >>> def function(**kwargs): ... print kwargs ... >>> function(one=1,two=2,three=3) {'thre

Re: [Tutor] Volunteer opportunities

2009-01-21 Thread jadrifter
On Wed, 2009-01-21 at 23:31 -0500, bob gailer wrote: > Depends on your knowledge of Python and (if any) CMS Pipelines. > > Testing > Design critique (devil's advocate) > Cleaning up and fine-tuning the parser > Coding built-in stages > Documentation > Financial support > > Let me know what spark

Re: [Tutor] dict() versus {}

2009-01-21 Thread wormwood_3
dict( [arg]) Return a new dictionary initialized from an optional positional argument or from a set of keyword arguments. If no arguments are given, return a new empty dictionary. If the positional argument arg is a mapping object, return a dictionary mapping the same keys to the same values as

Re: [Tutor] Volunteer opportunities

2009-01-21 Thread bob gailer
jadrifter wrote: On Wed, 2009-01-21 at 22:53 -0500, bob gailer wrote: Eric Dorsey wrote: Does anyone know of any good volunteer opportunities for projects that learning Python coders can work on? Or possibly nonprofits or the like that need smaller-type applicatio

Re: [Tutor] dict() versus {}

2009-01-21 Thread bob gailer
wormwood_3 wrote: Hmm, looked through the latest docs, in the sections on dictionary types, don't see examples that point to this case well. Can you link to what you had in mind? 2.1 Built-in Functions ... dict( [mapping-or-sequence]) ... these all return a dictionary equal to {"on

Re: [Tutor] dict() versus {}

2009-01-21 Thread wormwood_3
Hmm, looked through the latest docs, in the sections on dictionary types, don't see examples that point to this case well. Can you link to what you had in mind? ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - ht

Re: [Tutor] dict() versus {}

2009-01-21 Thread bob gailer
wormwood_3 wrote: When creating a list of dictionaries through a loop, I ran into a strange issue. I'll let the code talk: >>> l = 'i am a special new list'.split() >>> t = [] >>> for thing in l: ... t.append({thing: 1}) ... >>> t [{'i': 1}, {'am': 1}, {'a': 1}, {'special': 1}, {'

[Tutor] dict() versus {}

2009-01-21 Thread wormwood_3
When creating a list of dictionaries through a loop, I ran into a strange issue. I'll let the code talk: >>> l = 'i am a special new list'.split() >>> t = [] >>> for thing in l: ... t.append({thing: 1}) ... >>> t [{'i': 1}, {'am': 1}, {'a': 1}, {'special': 1}, {'new': 1}, {'list': 1}] This

Re: [Tutor] Volunteer opportunities

2009-01-21 Thread bob gailer
Eric Dorsey wrote: Does anyone know of any good volunteer opportunities for projects that learning Python coders can work on? Or possibly nonprofits or the like that need smaller-type applications worked on? I have an open source project that could use some help. See http://en.wikipedia.org

[Tutor] Volunteer opportunities

2009-01-21 Thread Eric Dorsey
(My apologies if a blank message comes up first with this heading -- The first time I meant to type this I managed to tab accidently to Send and hit it before even filling out the message.. :/ ) Does anyone know of any good volunteer opportunities for projects that learning Python coders can work

[Tutor] Volunteer Opportunities?

2009-01-21 Thread Eric Dorsey
-- eric dorsey | www.perfecteyedesign.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] bruteforce match word in text file

2009-01-21 Thread bob gailer
David wrote: Thanks Bob, I changed the wordlist.txt to next block is meat and the program; #!/usr/bin/python password = 'loser' wordlist = '/home/david/Challenge-You/wordlist.txt' try: words = open(wordlist, 'r').readlines() except IOError, e: print "Sorry no words" for word in words:

Re: [Tutor] bruteforce match word in text file

2009-01-21 Thread David
#!/usr/bin/python import re password = 'loser' wordlist = '/home/david/Challenge-You/wordlist.txt' try: words = open(wordlist, 'r').readlines() except IOError, e: print "Sorry no words" for word in words: word = word.replace("\n","") if password in word: print "The passwo

Re: [Tutor] bruteforce match word in text file

2009-01-21 Thread David
bob gailer wrote: David wrote: bob gailer wrote: David wrote: I have to ask for a pointer, not sure what I am doing wrong. The first thing you are doing "wrong" is failing to tell us what is in the wordlist file and what results you get when you run the program. Please re-post with that i

Re: [Tutor] The better Python approach

2009-01-21 Thread Alan Gauld
"Robert Berman" wrote Wow! That is all worth knowing. I am fascinated by the single sum over a double loop. > or more simply as a single sum over a double loop: > bigtotal = sum(int(x) for line in myfile for x in line.split()) > which you may or may not see as an improvement... And tha

Re: [Tutor] bruteforce match word in text file

2009-01-21 Thread bob gailer
David wrote: bob gailer wrote: David wrote: I have to ask for a pointer, not sure what I am doing wrong. The first thing you are doing "wrong" is failing to tell us what is in the wordlist file and what results you get when you run the program. Please re-post with that information. #!/us

Re: [Tutor] bruteforce match word in text file

2009-01-21 Thread David
bob gailer wrote: David wrote: I have to ask for a pointer, not sure what I am doing wrong. The first thing you are doing "wrong" is failing to tell us what is in the wordlist file and what results you get when you run the program. Please re-post with that information. #!/usr/bin/python p

Re: [Tutor] bruteforce match word in text file

2009-01-21 Thread bob gailer
David wrote: I have to ask for a pointer, not sure what I am doing wrong. The first thing you are doing "wrong" is failing to tell us what is in the wordlist file and what results you get when you run the program. Please re-post with that information. #!/usr/bin/python password = 'loser' w

[Tutor] bruteforce match word in text file

2009-01-21 Thread David
I have to ask for a pointer, not sure what I am doing wrong. thanks -david #!/usr/bin/python password = 'loser' wordlist = '/home/david/Challenge-You/wordlist.txt' try: words = open(wordlist, 'r').readlines() except IOError, e: print "Sorry no words" for word in words: word = word.rep

Re: [Tutor] The better Python approach

2009-01-21 Thread Robert Berman
Kent, Wow! That is all worth knowing. I am  fascinated by the  single sum over a double loop. Thanks, Robert Berman Kent Johnson wrote: On Wed, Jan 21, 2009 at 2:02 PM, Robert Berman wrote: myfile = openinput() for line in myfile: jlist = line.split() for x in

Re: [Tutor] The better Python approach

2009-01-21 Thread Kent Johnson
On Wed, Jan 21, 2009 at 2:02 PM, Robert Berman wrote: > myfile = openinput() > for line in myfile: > jlist = line.split() > for x in jlist: > bigtotal += int(x) Python has a sum() function that sums the elements of a numeric sequence, so the inner loop can be written as

Re: [Tutor] The better Python approach

2009-01-21 Thread Robert Berman
Alan, Thank you for the clarification. Using that as my guide, I revamped my solution to this small challenge and attempted to make the script as concise as possible. The challenge is at the Challenge-You web page, http://www.challenge-you.com/challenge?id=61 I am relatively certain I could h

Re: [Tutor] Tutor Digest, Vol 59, Issue 109

2009-01-21 Thread Paul McGuire
ters, you could use a regular expression: import re s = '1234 abc 5678 *** 1 233 xyz 476' nums = [int (i) for i in re.findall ("\d+", s)] print nums TJG ------ Message: 4 Date: Wed, 21 Jan 2009 08:50:29 -0500 From: Robert Berman Subject: Re: [T

Re: [Tutor] Finding the shortest word in a list of words

2009-01-21 Thread Andreas Kostyrka
Am Tue, 20 Jan 2009 09:33:40 -0600 schrieb "Paul McGuire" : No need for a defaultdict, all dicts have a setdefault method that works fine for this assign an empty dict/list as starting point problem: wordlendict = {} for w in words: wordlendict.setdefault(len(w), []).append(w) try: minle

Re: [Tutor] The better Python approach

2009-01-21 Thread Andreas Kostyrka
Am Wed, 21 Jan 2009 05:40:00 -0800 schrieb jadrifter : > >>>a = '1234 5678 1 233 476' > >>>a.split() > ['1234', '5678', '1', '233', '476'] [int(x) for x in a.split()] # [1234, 5678, 1, 233, 476] Andreas ___ Tutor maillist - Tutor@python.org http://mai

Re: [Tutor] The better Python approach

2009-01-21 Thread Alan Gauld
"Robert Berman" wrote Perhaps i should not have said the most Python correct. It looks as if it may well be the approach using the least amount of work the interpreter must complete. That's generally true. Python can always do things the long way but its generally more efficient both in pr

Re: [Tutor] The better Python approach

2009-01-21 Thread Vince Teachout
jadrifter wrote: a = '1234 5678 1 233 476' a.split() ['1234', '5678', '1', '233', '476'] Where the '>>>' are the command prompt from python. Don't type those. A space is the default split delimiter. If you wish to use a '-' or new line feed them as strings to the split method. Ok, that's

Re: [Tutor] The better Python approach

2009-01-21 Thread Robert Berman
Thanks to everyone who responded. Perhaps i should not have said the most Python correct. It looks as if it may well be the approach using the least amount of work the interpreter must complete. At that point of speculation I am well out of my league. I will be using the split method, and I t

Re: [Tutor] The better Python approach

2009-01-21 Thread Tim Golden
Robert Berman wrote: Given a string consisting of numbers separated by spaces such as '1234 5678 1 233 476'. I can see I have two obvious choices to extract or parse out the numbers. The first relying on iteration so that as I search for a blank, I build a substring of all characters found befo

Re: [Tutor] The better Python approach

2009-01-21 Thread jadrifter
>>>a = '1234 5678 1 233 476' >>>a.split() ['1234', '5678', '1', '233', '476'] Where the '>>>' are the command prompt from python. Don't type those. A space is the default split delimiter. If you wish to use a '-' or new line feed them as strings to the split method. John On Wed, 2009-01-21 at

[Tutor] The better Python approach

2009-01-21 Thread Robert Berman
Good Morning, Given a string consisting of numbers separated by spaces such as '1234 5678 1 233 476'. I can see I have two obvious choices to extract or parse out the numbers. The first relying on iteration so that as I search for a blank, I build a substring of all characters found before th