[Tutor] removing sq. of items.

Bala subramanian bala.biophysics at gmail.com
Wed May 23 12:07:13 CEST 2012


Hi,
I infact want write each of the item in the sliced list to a file.

On Wed, May 23, 2012 at 11:59 AM, Sarma Tangirala <tvssarma.omega9 at gmail.com
> wrote:

>
>
> On 23 May 2012 15:21, Bala subramanian <bala.biophysics at gmail.com> wrote:
>
>> Friends,
>> While iterating through each list item and printing/writing it, why does
>> the sq. brackets get printed/written to the file. Just a small eg.code is
>> given below.
>>
>> >>>N=100
>> >>> myl=range(1,100+1)
>> >>> new=[myl[i:i+15] for i in range(0, len(myl),15)]
>> >>> for x in new: print x
>>
>>
> When you slice 'myl[i:i+15]' you are creating a new list and adding that
> to 'new'. So essentially you are nesting new lists within a
> list comprehension.
>
> Hope that helps!
>
>
>> Thanks,
>> Bala
>>
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> An monkey typed up this email. Please excuse him if he made a stupid error!
>



-- 
C. Balasubramanian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120523/326b8f21/attachment.html>


More information about the Tutor mailing list