Have been programming at work, and rediscovering the joys of programming quirks. Specifically, Python quirks.
Well, you've probably seen that one before. I ended up writing a program which depended on that property to function properly. It was recursive, and passed round a list as a parameter, which needed to be altered by various instances of the function. Then just as I was about to fire it up, I realised that in one case I didn't need to alter just the end of the list, but change it completely. As a hack, I ended up writing this function:
I feel dirty.
On a completely unrelated note: not sure whether I want to go out to the pub tomorrow (oops! today now!) or just stay in. Anybody else going to be there?
def foo1(): x = ['data'] bar1( x ) print x def bar1( liszt ): liszt[0] = 'spock' >>> foo1() ['spock'] def foo2(): x = ['data'] bar2( x ) print x def bar2( liszt ): liszt = ['spock'] >>> foo2() ['data']
Well, you've probably seen that one before. I ended up writing a program which depended on that property to function properly. It was recursive, and passed round a list as a parameter, which needed to be altered by various instances of the function. Then just as I was about to fire it up, I realised that in one case I didn't need to alter just the end of the list, but change it completely. As a hack, I ended up writing this function:
def replacelist( list1, list2 ): """ Replace the data in list 1 with that of list 2, while maintaining the original list pointer """ while list1: del list1[0] for item in list2: list1.append( item )
I feel dirty.
On a completely unrelated note: not sure whether I want to go out to the pub tomorrow (oops! today now!) or just stay in. Anybody else going to be there?
Tags: