This seems like a pretty common pattern:
for row in reader: c1=row[0] if ids.has_key(c1): id1=ids.get(c1) else: currid+=1 id1=currid ids[c1]=currid
I want to know if there is a better way to achieve this. As for one line, if the statements go, I could do so much:
id1=ids.get(c1) if ids.has_key(c1) else currid+1
But then I got stuck with currency increment and gluing if the else case was fulfilled and inserted c-> id1 into the dictionary if the if condition passed.
source share