[Tutor] removing sq. of items.

Walter Prins wprins at gmail.com
Wed May 23 13:31:46 CEST 2012


On 23 May 2012 11:07, Bala subramanian <bala.biophysics at gmail.com> wrote:
> Hi,
> I infact want write each of the item in the sliced list to a file.

You don't have any actual files in your program so I'm assuming by
file you mean "each item is printed to standard output"?

Anyway, you might try the following which is I think what you're
trying to achieve.:

N=100
myl=range(1,100+1)
new=[]
for i in range(0, len(myl),15):
  new.extend(myl[i:i+15])
for x in new: print x

Ultimately the new list contains the same elements as the old list so
by itself isn't very useful except to show that the split/slice and
merge operations don't lose items/data from the original list.

Walter


More information about the Tutor mailing list