Generating a random subsequence

Tom Bryan tbryan at python.net
Tue Jan 8 23:30:42 EST 2002


Alex Martelli wrote:

> can become:
>           templist = list(seq)
>           random.shuffle(templist)
>           for item in templist[:length]:
>               returnSeq += item
> 
> The += augmented operator dispatches appropriately to in-place or
> not-in-place mutation depending on LHO's mutable/immutable nature.

Is that just true of +=? 

That is, if returnSeq is a list then, I can say
returnSeq = returnSeq + item
OR
returnSeq.append( item )
OR
returnSeq += item

You're saying that the last one is roughly equivalent to the second one and 
not the first?  Or are they all three equivalent?

the-last-time-I-used-python-there-wasn't-a-+=-ly,  
---Tom



More information about the Python-list mailing list