Re: [Tutor] still breaking chains

2015-04-13 Thread Jim Mooney
On Apr 12, 2015 4:00 PM, "Jim Mooney"  wrote:

> >
> > If join returns a string, why am I getting a syntax error when I try  to
> > slice it?
> >
> > >>> 'alfabeta'[2:5]
> > 'fab'
> > >>> ''.join(['a', 'l', 'f', 'a', 'b', 'e', 't', 'a')[2:5]
> > SyntaxError: invalid syntax
>
> If you're seeing a SyntaxError, don't look for explanations that are
> semantic.  Look for syntax.In this case, note that the list of characters
> had not been closed with a right bracket yet.
>
> Best of wishes!
>

Eeek! How did I miss that? Won't be the first time I confused mistyping
with misunderstanding ;')

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


Re: [Tutor] Please disable “digest” mode in order to participate

2015-04-13 Thread Jim Mooney
> That's an interesting feature. It's not sufficient though: the resulting
> messages lack the full header of each message, so any reply will not be
> properly marked as a response to the original.
>
> The only way to participate properly in a discussion on a mailing list
> is to respond to the actual messages that were sent. And that's only
> possible if you disable “digest” mode beforehand.
> https://mail.python.org/mailman/listinfo/tutor
>

Well, I've disabled digest and assume I should Reply to All and underpost.
How does that look?

-- 
Jim

"Stop, Harold! That bagel has radishes!"
"Thank God, Mary - you've saved me again!"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] still breaking chains

2015-04-13 Thread Jim Mooney
> Chaining long strings of operations together in a single statement goes
> directly against that principle, and hence is to be avoided.
>
> Ben Finney
>
>
A hard habit to break after using jQuery as a webmaster ;')
-- 
Jim

"Stop, Harold! That bagel has radishes!"
"Thank God, Mary - you've saved me again!"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please disable “digest” mode in order to participate

2015-04-13 Thread Ben Finney
Jim Mooney  writes:

> > The only way to participate properly in a discussion on a mailing
> > list is to respond to the actual messages that were sent. And that's
> > only possible if you disable “digest” mode beforehand.
>
> Well, I've disabled digest and assume I should Reply to All and underpost.
> How does that look?

Looks great, thank you.

The cherry on top is: Preserve the attribution line (the line that says
who wrote the material you're quoting) on quoted material you keep.

Especially when there are several nested levels, – like here – keeping
the attribution lines matching the quoted material helps to make sense
of it all.

-- 
 \   “The long-term solution to mountains of waste is not more |
  `\  landfill sites but fewer shopping centres.” —Clive Hamilton, |
_o__)_Affluenza_, 2005 |
Ben Finney

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


Re: [Tutor] Please disable “digest” mode in order to participate

2015-04-13 Thread Alan Gauld

On 13/04/15 00:51, Jim Mooney wrote:


The only way to participate properly in a discussion on a mailing list
is to respond to the actual messages that were sent. And that's only
possible if you disable “digest” mode beforehand.


Well, I've disabled digest and assume I should Reply to All and underpost.
How does that look?


Looks goods. BTW if you use digest to reduce clutter in the inbox you 
might find it worthwhile to create a folder for tutor mail and set up a 
rule to move all received mail from tutor to that folder. Then read that 
folder at your leisure.


Alternatively use the News feed from gmane.org

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Function not returning 05 as string

2015-04-13 Thread Ken G.

I am sure there is an simple explanation but when I input
5 (as integer), resulting in 05 (as string), I get zero as the end
result. When running the code:

START OF PROGRAM:
Enter the 1st number:  5

05

0
END OF PROGRAM:

START OF CODE:
import sys

def numberentry():
print
number01 = raw_input("Enter the 1st number:  ")
if number01 == "0":
sys.exit()
if  len(number01) == 1:
number01 = "0" + number01
print
print number01
return(number01)

number01 = 0
numberentry()
print
print number01
END OF CODE:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Dave Angel

On 04/13/2015 08:11 AM, Ken G. wrote:

I am sure there is an simple explanation but when I input
5 (as integer), resulting in 05 (as string), I get zero as the end
result. When running the code:

START OF PROGRAM:
Enter the 1st number:  5

05

0
END OF PROGRAM:

START OF CODE:
import sys

def numberentry():
 print
 number01 = raw_input("Enter the 1st number:  ")
 if number01 == "0":
 sys.exit()
 if  len(number01) == 1:
 number01 = "0" + number01
 print
 print number01
 return(number01)

number01 = 0


What is this line intended to do?


numberentry()


Where are you intending to store the return value?  Currently, you're 
just throwing it away.



print
print number01


This variable has no relation to the one in the function.  In fact, I'd 
recommend you use a different name, to make that clear.



END OF CODE:



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


[Tutor] Regular expression on python

2015-04-13 Thread jarod...@libero.it
Dear all.
I would like to extract from some file some data.
The line I'm interested is this:

Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward Only 
Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) Dropped: 308617 
(14.51%)



 with open("255.trim.log","r") as p:
for i in p:
lines= i.strip("\t")
if lines.startswith("Input"):
tp = lines.split("\t")
print re.findall("Input\d",str(tp))

So I started to find ":" from the row:
 with open("255.trim.log","r") as p:
for i in p:
lines= i.strip("\t")
if lines.startswith("Input"):
tp = lines.split("\t")
print re.findall(":",str(tp[0]))

And I'm able to find, but when I try to take the number using \d not work. 
Someone can explain why?
How can extract the numbers from this row.?
thanks so much=

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


Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Ken G.



On 04/13/2015 08:18 AM, Dave Angel wrote:

On 04/13/2015 08:11 AM, Ken G. wrote:

I am sure there is an simple explanation but when I input
5 (as integer), resulting in 05 (as string), I get zero as the end
result. When running the code:

START OF PROGRAM:
Enter the 1st number:  5

05

0
END OF PROGRAM:

START OF CODE:
import sys

def numberentry():
 print
 number01 = raw_input("Enter the 1st number:  ")
 if number01 == "0":
 sys.exit()
 if  len(number01) == 1:
 number01 = "0" + number01
 print
 print number01
 return(number01)

number01 = 0


What is this line intended to do?

NameError: name 'number01' is not defined




numberentry()


Where are you intending to store the return value?  Currently, you're 
just throwing it away.
I am not sending anything to the def routine but expected an answer in 
return.



print
print number01


This variable has no relation to the one in the function.  In fact, 
I'd recommend you use a different name, to make that clear.

Do not use return at end of routine? I am lost there.



END OF CODE:




Thanks for answering.

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


Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Peter Otten
Ken G. wrote:

> I am sure there is an simple explanation but when I input
> 5 (as integer), resulting in 05 (as string), I get zero as the end
> result. When running the code:
> 
> START OF PROGRAM:
> Enter the 1st number:  5
> 
> 05
> 
> 0
> END OF PROGRAM:
> 
> START OF CODE:
> import sys
> 
> def numberentry():
>  print
>  number01 = raw_input("Enter the 1st number:  ")
>  if number01 == "0":
>  sys.exit()
>  if  len(number01) == 1:
>  number01 = "0" + number01
>  print
>  print number01
>  return(number01)
> 
> number01 = 0
> numberentry()
> print
> print number01
> END OF CODE:

Let's simplify that and run it in the interactive interpreter:

>>> x = 0
>>> def f():
... x = 5
... print x
... 
>>> f()
5
>>> x
0

You are seeing two different values because there are two separate 
namespaces. The x = 0 lives in the "global" namespace of the module while 
the other x = 5 exists in the "local" namespace of the function, is only 
visible from a specific invocation of f() and only while that specific 
invocation of f() is executed.

If you want see the value of a global variable from within a function you 
must not rebind it:

>>> def g():
... print x
... 
>>> f()
5
>>> x = 42
>>> f()
5

If you want to update a global variable you should do that explicitly

>>> def h():
... return "foo"
... 
>>> x = h()
>>> x
'foo'

but there is also the option to declare it as global inside the function:

>>> def k():
... global x
... x = "bar"
... 
>>> k()
>>> x
'bar'

The global keyword is generally overused by newbies and tends to make your 
programs hard to maintain.

Try it a few times to ensure that you understand how it works -- and then 
forget about it and never use it again ;)

Back to your original code -- assuming that you want to update the global 
name 'number01' you could rewrite it like this:


def numberentry():
 digit = raw_input("Enter the 1st number:  ")
 if len(digit) != 1 or not digit.isdigit():
 raise ValueError("Not an allowed input: {!r}".format(digit))
 return digit.zfill(2)

number01 = numberentry()
if number01 != "00":
print number01


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


Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread David Palao
Hello,
In the code that you posted, as it is, you are:
1) defining a function (numberentry)
2) defining a global variable (number01) and setting it to 0
3) calling numberentry discarding the result
4) printing the value of the global variable number01

I would guess that you want to store the result of the function and
print it. Is that correct?

Best

2015-04-13 14:11 GMT+02:00 Ken G. :
> I am sure there is an simple explanation but when I input
> 5 (as integer), resulting in 05 (as string), I get zero as the end
> result. When running the code:
>
> START OF PROGRAM:
> Enter the 1st number:  5
>
> 05
>
> 0
> END OF PROGRAM:
>
> START OF CODE:
> import sys
>
> def numberentry():
> print
> number01 = raw_input("Enter the 1st number:  ")
> if number01 == "0":
> sys.exit()
> if  len(number01) == 1:
> number01 = "0" + number01
> print
> print number01
> return(number01)
>
> number01 = 0
> numberentry()
> print
> print number01
> END OF CODE:
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Steven D'Aprano
On Mon, Apr 13, 2015 at 08:11:46AM -0400, Ken G. wrote:
> I am sure there is an simple explanation but when I input
> 5 (as integer), resulting in 05 (as string), I get zero as the end
> result. When running the code:

> number01 = 0

Here you set the variable "number01" to the int 0.

> numberentry()

Here you call the function. It returns "05", but you don't do anything 
with it, so it just gets dropped on the floor and thrown away.

> print
> print number01

Here you print the variable number01, which is still the int 0, 
unchanged.

I think where you are mislead is that you are not aware, or have 
forgotten, that global variables and local variables are different. So a 
variable "x" outside of a function and a variable "x" inside a function 
are different variables. Think of functions being like Los Vegas: "what 
happens in Vegas, stays in Vegas" -- function local variables don't leak 
out and have effects outside of the function except via the "return" 
statement, and even then only if the caller assigns the result to 
another variable:

function()  # return result is thrown away
x = function()  # return result is assigned to x


The other way to have an effect outside of the function is to use global 
variables, and the global keyword. This is occasionally necessary, but I 
strongly recommend against it: it is poor programming practice and a bad 
habit to get into.


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


Re: [Tutor] Function not returning 05 as string [SOLVED]

2015-04-13 Thread Ken G.



On 04/13/2015 08:56 AM, Steven D'Aprano wrote:

On Mon, Apr 13, 2015 at 08:11:46AM -0400, Ken G. wrote:

I am sure there is an simple explanation but when I input
5 (as integer), resulting in 05 (as string), I get zero as the end
result. When running the code:
number01 = 0

Here you set the variable "number01" to the int 0.


numberentry()

Here you call the function. It returns "05", but you don't do anything
with it, so it just gets dropped on the floor and thrown away.


print
print number01

Here you print the variable number01, which is still the int 0,
unchanged.

I think where you are mislead is that you are not aware, or have
forgotten, that global variables and local variables are different. So a
variable "x" outside of a function and a variable "x" inside a function
are different variables. Think of functions being like Los Vegas: "what
happens in Vegas, stays in Vegas" -- function local variables don't leak
out and have effects outside of the function except via the "return"
statement, and even then only if the caller assigns the result to
another variable:

function()  # return result is thrown away
x = function()  # return result is assigned to x


The other way to have an effect outside of the function is to use global
variables, and the global keyword. This is occasionally necessary, but I
strongly recommend against it: it is poor programming practice and a bad
habit to get into.



Thanks for all the replies. I will keep at it. Again, thanks.

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


[Tutor] R: Tutor Digest, Vol 134, Issue 36

2015-04-13 Thread jarod...@libero.it
At the moment I use this way to resolve my question:
 re.findall(r'(\w+):\W(\d+)',str(tp[0]))

However please gave me you suggestion on how to improve my ability to use  
regular expression on python
Thanks so much!


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


Re: [Tutor] On learning Fortran and C++ for scientific computing

2015-04-13 Thread Vick
Hi,

 

Thanks

 

Vick

 

-Original Message-
From: Laura Creighton [mailto:l...@openend.se] 
Sent: Sunday, 12 April, 2015 15:30
To: Vick
Cc: 'Laura Creighton'; 'William Ray Wing'; webmas...@python.org;
tutor@python.org; l...@openend.se
Subject: Re: [Tutor] On learning Fortran and C++ for scientific computing

 

In a message of Sun, 12 Apr 2015 10:25:54 +0400, "Vick" writes:

>S 0 to 1e+31> 1/sqrt(.86 *(1+z)^4 + .282 * (1+z)^3 - .86

>*(1+z)^2   + .718)  if you try this integration you will get completely

>wrong numbers on computing devices that do not possess ultra-high 

>precision and accuracy.

 

Python is as accurate as you can get, every bit as accurate as C++ or
Fortran.

 

>I had to use mpmath with precision of 250 and integration method called 

>Tanh Sinh Quadrature with accuracy 120 to get the desired results. I 

>checked the answer with Mathematica and they concur. But the 

>calculation is done in about 3 seconds on my laptop with intel core i5 at
2.5 GHz with 4 GB RAM.

 

>So can Fortran crunch 250 digits numbers in an integration formula 

>under 3 seconds with the same computing parameters as above? Or is 

>Python better at it?

 

Some of us who were unhappy with the performance of python wrote pypy.

(I am one of the people, so very much biased here.)  PyPy uses a
just-in-time compiler to get its speed.  If you want to look at the speed of
pypy vs the speed of CPython (which is what we call the particular
implementation(s) of python you are using, because it is written in C) you
can take a look at these pages.   
http://speed.pypy.org/

 

Click on a benchmark, and see the code, and see how much faster we are than
CPython.  Mathematical formulae are what we are very, very good at.  Indeed
we are often better than some old Fortran library -- so we have users who
are busy rewriting their code in Python in order to use pypy for the
increased speed of mathematical computation.  If all you are doing is pure
math -- and not going out, for instance and trying to graph this thing at
the same time -- then we can probably give you speed which is equivalent to
C.  But this assumes that you can write this code where the heavy
calculating is done inside a loop, which is executed many times, because
that is what PyPy optimises. If all you have is straight in-line
executed-one-time-only code, there will be no speed win for you.

 

Also, the jit takes time to warm up.  It has to set up its own internal
bookkeeping before it can get to work on your code.  So if your code doesn't
take very long to run, it may run slower in pypy -- because the savings your
get are competely swallowed up in the setup costs.

 

However, it is easy to find out.  You can get pypy here:

  http://pypy.org/download.html

 

It's a perfectly compliant, working python.  The version compatible with

3.2.5 is not as speedy as the one compatible with 2.7.  So just run your
python code with this -- it should run completely unchanged -- and see how
fast it is.

 

If you are still unhappy with the performance, post your code to
 pypy-...@python.org and we can give you
suggestions on how to tune your python code for better performance under
pypy.  If you expose a place where pypy ought to be fast, but isn't, we will
fix pypy and get you a working faster binary.

 

But I think any more talk about pypy belongs on the pypy-dev mailing list.

 

Laura Creighton

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


[Tutor] Python and Django Web Engineering Class

2015-04-13 Thread Chris Calloway
Not for everybody, but this just popped up in my neck of the woods, 
organized by members of my Python user group, and I though there might 
be a few people here looking for something like this:


http://astrocodeschool.com/

It's one of those intensive multi-week code school formats that aren't 
inexpensive. But it's taught by the primary Python instructor at UNC. 
The school is also licensed by the State of North Carolina and sponsored 
by Caktus Group, the largest Django development firm.


--
Sincerely,

Chris Calloway, Applications Analyst
UNC Renaissance Computing Institute
100 Europa Drive, Suite 540, Chapel Hill, NC 27517
(919) 599-3530
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please disable “digest” mode in order to participate

2015-04-13 Thread Laura Creighton
In a message of Sun, 12 Apr 2015 16:51:04 -0700, Jim Mooney writes:

>Well, I've disabled digest and assume I should Reply to All and underpost.
>How does that look?
>
>-- 
>Jim

Looks great here.

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


Re: [Tutor] Regular expression on python

2015-04-13 Thread Alan Gauld

On 13/04/15 13:29, jarod...@libero.it wrote:


Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward Only 
Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) Dropped: 308617 
(14.51%)


Its not clear where the tabs are in this line.
But if they are after the numbers, like so:

Input Read Pairs: 2127436 \t
Both Surviving: 1795091 (84.38%) \t
Forward Only Surviving: 17315 (0.81%) \t
Reverse Only Surviving: 6413 (0.30%) \t
Dropped: 308617 (14.51%)

Then you may not need to use regular expressions.
Simply split by tab then split by :
And if the 'number' contains parens split again by space


  with open("255.trim.log","r") as p:
 for i in p:
 lines= i.strip("\t")


lines is a bad name here since its only a single line. In fact I'd lose 
the 'i' variable and just use


for line in p:


 if lines.startswith("Input"):
 tp = lines.split("\t")
 print re.findall("Input\d",str(tp))


Input is not followed by a number. You need a more powerful pattern.
Which is why I recommend trying to solve it as far as possible
without using regex.


So I started to find ":" from the row:
  with open("255.trim.log","r") as p:
 for i in p:
 lines= i.strip("\t")
 if lines.startswith("Input"):
 tp = lines.split("\t")
 print re.findall(":",str(tp[0]))


Does finding the colons really help much?
Or at least, does it help any more than splitting by colon would?


And I'm able to find, but when I try to take the number using \d not work.
Someone can explain why?


Because your pattern doesn't match the string.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Regular expression on python

2015-04-13 Thread Alan Gauld

On 13/04/15 19:42, Alan Gauld wrote:


 if lines.startswith("Input"):
 tp = lines.split("\t")
 print re.findall("Input\d",str(tp))


Input is not followed by a number. You need a more powerful pattern.
Which is why I recommend trying to solve it as far as possible
without using regex.


I also just realised that you call split there then take the str() of 
the result. That means you are searching the string representation

of a list, which doesn't seem to make much sense?


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Regular expression on python

2015-04-13 Thread Steven D'Aprano
On Mon, Apr 13, 2015 at 02:29:07PM +0200, jarod...@libero.it wrote:
> Dear all.
> I would like to extract from some file some data.
> The line I'm interested is this:
> 
> Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward 
> Only Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) 
> Dropped: 308617 (14.51%)


Some people, when confronted with a problem, think "I know, I'll 
use regular expressions." Now they have two problems.
-- Jamie Zawinski
‎
I swear that Perl has been a blight on an entire generation of 
programmers. All they know is regular expressions, so they turn every 
data processing problem into a regular expression. Or at least they 
*try* to. As you have learned, regular expressions are hard to read, 
hard to write, and hard to get correct.

Let's write some Python code instead.


def extract(line):
# Extract key:number values from the string.
line = line.strip()  # Remove leading and trailing whitespace.
words = line.split()
accumulator = []  # Collect parts of the string we care about.
for word in words:
if word.startswith('(') and word.endswith('%)'):
# We don't care about percentages in brackets.
continue
try:
n = int(word)
except ValueError:
accumulator.append(word)
else:
accumulator.append(n)
# Now accumulator will be a list of strings and ints:
# e.g. ['Input', 'Read', 'Pairs:', 1234, 'Both', 'Surviving:', 1000]
# Collect consecutive strings as the key, int to be the value.
results = {}
keyparts = []
for item in accumulator:
if isinstance(item, int):
key = ' '.join(keyparts)
keyparts = []
if key.endswith(':'):
key = key[:-1]
results[key] = item
else:
keyparts.append(item)
# When we have finished processing, the keyparts list should be empty.
if keyparts:
extra = ' '.join(keyparts)
print('Warning: found extra text at end of line "%s".' % extra)
return results



Now let me test it:

py> line = ('Input Read Pairs: 2127436 Both Surviving: 1795091'
... ' (84.38%) Forward Only Surviving: 17315 (0.81%)'
... ' Reverse Only Surviving: 6413 (0.30%) Dropped:'
... ' 308617 (14.51%)\n')
py>
py> print(line)
Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward 
Only Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) 
Dropped: 308617 (14.51%)

py> extract(line)
{'Dropped': 308617, 'Both Surviving': 1795091, 'Reverse Only Surviving': 
6413, 'Forward Only Surviving': 17315, 'Input Read Pairs': 2127436}


Remember that dicts are unordered. All the data is there, but in 
arbitrary order. Now that you have a nice function to extract the data, 
you can apply it to the lines of a data file in a simple loop:

with open("255.trim.log") as p:
for line in p:
if line.startswith("Input "):
d = extract(line)
print(d)  # or process it somehow



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