[Tutor] Loop in pre-defined blocks

Alan Gauld alan.gauld at yahoo.co.uk
Fri Jun 10 18:57:58 EDT 2016


On 10/06/16 23:43, Jignesh Sutar wrote:
> Is there a better way to code the below than to specify blocks as I have.
> Ideally I'd like to specify blocks simply as *blocks=(12,20,35)*
> 
> blocks=[(1,12), (13,20), (25,35)]
> for i,j in enumerate(blocks):
>     for x in xrange(blocks[i][0],blocks[i][1]+1):
>         print i+1, x


Can you explain in English what you are trying to do.
Working through your algorithm in my head is too much
like hard work. At the very least show us the output.

Better still explain what it means - what the data
represents and how the outputs relate to the inputs.

-- 
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




More information about the Tutor mailing list