Multiple assignment and the expression on the right side

2006-02-20 Thread Suresh Jeevanandam
Dear all, I read in Python in a Nutshell that when we have multiple assignments made on a single line, it is equivalent to have those many simple assignments and that the right side is evaluated once for each assignment. [The wordings are mine. I am not sure if this is what he

Augmented assignment

2006-02-20 Thread Suresh Jeevanandam
Hi, Is there any gain in performance because of augmented assignments. x += 1 vs x = x+1 Or are both of them the same. regards, Suresh -- http://mail.python.org/mailman/listinfo/python-list

Re: Augmented assignment

2006-02-20 Thread Suresh Jeevanandam
Thanks Alex. I was not aware of mtimeit. regards, Suresh Alex Martelli wrote: Suresh Jeevanandam [EMAIL PROTECTED] wrote: Hi, Is there any gain in performance because of augmented assignments. x += 1 vs x = x+1 Or are both of them the same. Just *MEASURE*, man! helen

Mutable numbers

2006-02-20 Thread Suresh Jeevanandam
# I am new to python. In python all numbers are immutable. This means there is one object ( a region in the memory ) created every time we do an numeric operation. I hope there should have been some good reasons why it was designed this way. But why not have mutable numbers also in the

Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Suresh Jeevanandam
Alex Martelli wrote: Suresh Jeevanandam [EMAIL PROTECTED] wrote: Dear all, I read in Python in a Nutshell that when we have multiple assignments made on a single line, it is equivalent to have those many simple assignments and that the right side is evaluated once for each

mapping functions and lambda

2006-02-15 Thread Suresh Jeevanandam
Given a string s = 'a=1,b=2' I want to create a dictionary {'a': '1', 'b': '2'} I did, dict(map(lambda k: k.split('='), s.split(','))) Is it possible to get rid of the lambda here, without having to define another function just for this. Is this the easiest/straight-forward way to do this?

Re: mapping functions and lambda

2006-02-15 Thread Suresh Jeevanandam
I got it: dict([k.split('=') for k in s.split(',')]) regards, Suresh Suresh Jeevanandam wrote: Given a string s = 'a=1,b=2' I want to create a dictionary {'a': '1', 'b': '2'} I did, dict(map(lambda k: k.split('='), s.split(','))) Is it possible to get rid of the lambda here, without

finding the intersection of a list of Sets

2006-01-31 Thread Suresh Jeevanandam
I have a list of sets in variable lsets . Now I want to find the intersection of all the sets. r = lsets[0] for s in r[0:]: r = r s Is there any other shorter way? Thanks in advance, Suresh -- http://mail.python.org/mailman/listinfo/python-list

Finding the relative path of a file from a dir

2006-01-20 Thread Suresh Jeevanandam
Hi, a = '/home/suresh/doc/html/a1/' b = '/home/suresh/doc/' I am looking for a standard function which will return the location of b relative to a i.e. '../..' I have gone through the os and os.path modules, but could not find any function of use. Should I write my own?

Re: parsing engineering symbols

2005-12-21 Thread Suresh Jeevanandam
Exactly what I wanted. It would be nice if the standard float function takes care of these. regards, Suresh how about: SI_prefixes = { 'Y':24, 'Z':21, 'E':18, 'P':15, 'T':12, 'G':9, 'M':6, 'k':3, 'h':2, 'd':-1, 'c':-2, 'm':-3, u'\xb5':-6, 'u':-6, 'n':-9, 'p':-12, 'f':-15,

parsing engineering symbols

2005-12-20 Thread Suresh Jeevanandam
Hi, I want to convert a string to float value. The string contains engineering symbols. For example, s = '12k' I want some function which would return 12000 function(s) = 12000.0 I searched the web, but could not

checking if a string contains a number

2005-12-20 Thread Suresh Jeevanandam
Hi, I have a string like, s1 = '12e3' s2 = 'junk' Now before converting these values to float, I want to check if they are valid numbers. s1.isdigit returns False. Is there any other function which would return True for s1 and False for s2.

numarray :: multiplying all the elements in 1d array

2005-12-20 Thread Suresh Jeevanandam
Hi all, Lets say I have an array: from numarray import * a = array([ 6, 7, 8, 9, 10, 11, 12]) I want to multiply out all the elements and get the result. r = 1.0 for i in a: r = r*i Is there any faster, efficient