"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
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
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
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
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
"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
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
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
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
>>>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
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
11 matches
Mail list logo