[Tutor] Getting range of a list

Hs Hs ilhs_hs at yahoo.com
Wed Feb 6 00:59:39 CET 2013


Thanks Dave. 

Sorry for html formatting. Honestly I don't know how to shut html formatting off in Yahoo. I don't have options for send in ('Tools|Options|''send''missing').
Will investigate. 
thanks
Hs



________________________________
 From: Dave Angel <davea at davea.name>
To: tutor at python.org 
Sent: Tuesday, February 5, 2013 5:20 PM
Subject: Re: [Tutor] Getting range of a list
 
On 02/05/2013 04:48 PM, Hs Hs wrote:
> Thanks Steve.
>
> But one question, when I print, I get extra empty lines. How to get rid of them!  Thanks again.
>>>> f = open('test')
>>>> head = '---'
>>>> for line in f:

line = line.rstrip()     #get rid of the trailing newline (and any other 
whitespace there)

> if line.startswith('>'):
> head = line[1:].strip()
> else:
> print head+'\t'+line

The print generates a newline by default.  So you either have to do the 
strip() I suggested above, or use a trailing comma on the print.  I 
recommend the former.

>
> X1A
>                          <------
> X1G
>                         <-----
> X2A
>
> X2G
>
> X3A
>
> X3G
>
> X4A
>
> X4A
>
> Thanks
> Hs.
>
>
>

You're still posting using html mail.  And your indentation is still 
getting messed up.  Also, you top-posted.


-- 
DaveA
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130205/fc4ed1be/attachment.html>


More information about the Tutor mailing list