Re: [Tutor] Loop in pre-defined blocks

2016-06-10 Thread Jignesh Sutar
20 3 25 3 26 3 27 3 28 3 29 3 30 3 31 3 32 3 33 3 34 3 35 On Sat, 11 Jun 2016 at 00:02 Alan Gauld via Tutor wrote: > 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 si

[Tutor] Loop blocks

2016-06-10 Thread Jignesh Sutar
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 Thanks in advance. Jig

[Tutor] Loop in pre-defined blocks

2016-06-10 Thread Jignesh Sutar
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 Thanks in advance. Jig

Re: [Tutor] str.strip strange result...?

2016-01-15 Thread Jignesh Sutar
Gotcha and thank you for the reminder to read the documentation. Very clear, indeed. Many thanks! Cheers Jignesh On Fri, 15 Jan 2016 at 17:32, Mark Lawrence wrote: > On 15/01/2016 16:25, Jignesh Sutar wrote: > > #python2.7 > > > >>>> s="V01_1" > >&

[Tutor] str.strip strange result...?

2016-01-15 Thread Jignesh Sutar
#python2.7 >>> s="V01_1" >>> s.strip("_1") 'V0' Wouldn't you expect the result to be "V01" ? Cheers Jignesh ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

[Tutor] Test to check if values of dictionary are all equal (which happen to be dictionaries)

2014-11-09 Thread Jignesh Sutar
I needed to test if the values of all entries in a dictionary were equal but since the values themselves were dictionaries I couldn't simply take a set of the values and test if this equated to one. So I ended up taking all combination of the keys and testing pairs of sub dictionaries. I just want

Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Jignesh Sutar
On 03/17/2014 11:22 AM, Jignesh Sutar wrote: > >> Is it possible to get two nested for statements followed by a nested >> if/else statement all into a single list comprehension ie. the equivalent >> of the below: >> >> >> for i in xrange(1,20): >> fo

[Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Jignesh Sutar
Is it possible to get two nested for statements followed by a nested if/else statement all into a single list comprehension ie. the equivalent of the below: for i in xrange(1,20): for j in xrange(1,10): if j<6: j=int("8"+str(j)) else: j=int("9"+str(j))

[Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Jignesh Sutar
Is it possible to get two nested for statements followed by a nested if/else statement all into a single list comprehension ie. the equivalent of the below: for i in xrange(1,20): for j in xrange(1,10): if j<6: j=int("8"+str(j)) else: j=int("9"+str(j))

Re: [Tutor] How to determine which function code is being called from

2014-03-07 Thread Jignesh Sutar
t only when running from funcB def funcB(runfromB): funcA(runfromB=runfromB) funcB(runfromB=True) On 6 March 2014 20:37, Jerry Hill wrote: > On Thu, Mar 6, 2014 at 12:00 PM, Jignesh Sutar wrote: > > Hi I'm trying to exclude a certain line of code if the function is > ca

[Tutor] How to determine which function code is being called from

2014-03-06 Thread Jignesh Sutar
Hi I'm trying to exclude a certain line of code if the function is called by another function, see illustration below: def funcA(): print "running from funcA" # print only if running from funcA print "running from funcA or funcB" #print when running from either function print "running

Re: [Tutor] formatting datetime.timedelta to "HH:MM:SS"

2013-12-11 Thread Jignesh Sutar
ng. Yes, exactly, I was hoping to achieve this without all the modulus calculations. Cheers, Jignesh On 11 December 2013 21:18, spir wrote: > On 12/11/2013 06:40 PM, Jignesh Sutar wrote: > >> c = b-a >> print "%s days, %.2dh: %.2dm: %.2ds" % >> (c.days,c.seco

Re: [Tutor] formatting datetime.timedelta to "HH:MM:SS"

2013-12-11 Thread Jignesh Sutar
áoz wrote: > El 11/12/13 10:37, Mark Lawrence escribió: > > On 11/12/2013 13:12, Jignesh Sutar wrote: >> >>> print str(exe_time).split('.')[0] >>> Sorry, I guess my question was why I can't use something similar to >>> below on exe_time (of

Re: [Tutor] formatting datetime.timedelta to "HH:MM:SS"

2013-12-11 Thread Jignesh Sutar
Thanks Mark, print('%02d:%02d:%04d' % (now.hour, now.minute, now.year)) That works for; now = datetime.now() but not for; exe_time = endTime-startTime Thanks, Jignesh On 11 December 2013 13:37, Mark Lawrence wrote: > On 11/12/2013 13:12, Jignesh Sutar wrote: > >>

Re: [Tutor] formatting datetime.timedelta to "HH:MM:SS"

2013-12-11 Thread Jignesh Sutar
rint now.minute print now.year On 11 December 2013 12:43, David Robinow wrote: > On Wed, Dec 11, 2013 at 5:55 AM, Jignesh Sutar wrote: > > Hi, > > > > I've googled around extensively to try figure this out assuming it > should be > > straight forward (and it pro

[Tutor] formatting datetime.timedelta to "HH:MM:SS"

2013-12-11 Thread Jignesh Sutar
Hi, I've googled around extensively to try figure this out assuming it should be straight forward (and it probably is) but I'm clearly missing something. I'm trying to get the total run time of the program but have the final time being displayed in a particular format. I.e. without the seconds in

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-10 Thread Jignesh Sutar
Thanks Steve, Alan. Sound advice. Very much a novice so trying to pick up good habits. Will definitely take on board your comments! Thanks again. Jignesh On 10 December 2013 00:46, Alan Gauld wrote: > On 09/12/13 23:46, Steven D'Aprano wrote: > > Python has two different quote characters ' and