Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'subject:code': 0.07; 'subject:python': 0.10; 'output': 0.10; 'am,': 0.12; 'multiples': 0.16; 'received:192.168.1.104': 0.16; 'val': 0.16; 'val,': 0.16; 'wanted.': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.18; 'this?': 0.19; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:gmail.com': 0.28; "wasn't": 0.28; "skip:' 10": 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'quite': 0.32; 'values': 0.32; 'header:User-Agent:1': 0.33; 'rather': 0.33; 'that,': 0.33; 'probably': 0.34; 'loop': 0.34; 'something': 0.35; 'cc:2**1': 0.36; 'but': 0.37; 'received:192': 0.37; 'doing': 0.38; 'getting': 0.38; 'received:192.168': 0.40; 'more': 0.61; 'header :Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'generator,': 0.84 Date: Mon, 21 Nov 2011 09:34:14 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: d@davea.name Subject: Re: Format the ouput in my python code References: <3f23c6ac-0554-4cb7-bf7c-b98c29721796@z22g2000prd.googlegroups.com> <4ECA5FD1.5090308@davea.name> In-Reply-To: <4ECA5FD1.5090308@davea.name> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:Zg5dsya76XItSmcWclnPZQA/phP3cHIhuDq/jpEBDfq ie+2Ft+OQSwZE2AO3AvDm0vyqUuAQWNU4qguxedFvIv+nta7Hf oezFQwyWFJNIgVkUkJSRhz57dwKeDWLAghng/6jCT3PLgeOjLD hJSWDvRGuvqr6VXTWnZrb39i+gu36MW5vi1CRiOKhA18mCL++X hcvuu0j1aqLrCQ75MmiJoTnWtOQm8rOQ9H8x3er6hQoYGQ9L9J AfUNIJ39RqErL7FUOQXqtmqDy5qHML4qDY5CO7DWKManrS5o3t 3uZkrAC22Hbkk0gVAyi8tSdhtJZsZP0TA0v4H++HhGRsD6UkQ= = Cc: sl33k , python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321886085 news.xs4all.nl 6944 [2001:888:2000:d::a6]:36056 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16011 On 11/21/2011 09:27 AM, Dave Angel wrote: > On 11/21/2011 07:13 AM, sl33k wrote: >> I am printing the numbers from 1 to 100. In that, I want to display >> multiples of 3,5 and of both as mulof3, mul0f5 and mulof3and5 >> respectively. >> >> I am getting the output I want but I would like to format the output >> to print only 10 number per line. How do I go about doing this? >> >> for i in range(1, 101): >> if i % 3 == 0: >> if i % 5 == 0: >> print 'mulof3and5', >> else: >> print 'mulof3', >> elif i % 5 == 0: >> print 'mulof5', >> else: >> print i >> > Change that loop into a generator, having it return values rather than > printing them. Then call that generator in a for-loop, something like: > > for index, val in enumerate(mygen): > print val, > if not index%10: print > > Oops. That was untested, and it probably wasn't quite what you wanted. More likely something like (untested): for index, val in enumerate(mygen): print val, if not ((index+1)%10): print -- DaveA