This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients Julian, ezio.melotti, john.feuerstein, mark.dickinson, rhettinger
Date 2011-09-09.14:04:24
SpamBayes Score 9.860779e-12
Marked as misclassified No
Message-id <1315577066.25.0.522485226844.issue12941@psf.upfronthosting.co.za>
In-reply-to
Content
>> Not all the sequences have a .pop() method.
> Not all sequences support indexing or item assignment either:

All the sequences support indexing and len(), but not assignment (e.g. tuples and strings are sequences, but they are immutable).  So talking about sequences there is incorrect (see also http://docs.python.org/py3k/glossary.html#term-sequence ).

> So seq[random] should test for random behaviour, not that indexing of
> seq itself works correctly. Similarly, seq.pop(random) should test for
> random behaviour and not for a working seq.pop()?

The test should check the behavior of the function, and in this case it includes both getting a random element and removing it.  The test doesn't have to check that seq.pop() is working fine (there are other tests for that) but that it's actually called and that it pops the right element from the input sequence (and not e.g. from a copy of the sequence that might have been created at some point).
In general it's always better to have a test more than one less.

Regarding the function itself, I'm not sure about its usefulness.  While I've used random.choice several times, I never felt the need of popping the elements.  One use case I might think of is picking all the elements of a sequence until there are no more left, without risking to pick the same element twice.  The same result can be achieved by shuffling the sequence and iterate over the elements though (that doesn't actually leave you with an empty sequence, but that's probably just a unimportant side-effect).
History
Date User Action Args
2011-09-09 14:04:26ezio.melottisetrecipients: + ezio.melotti, rhettinger, mark.dickinson, Julian, john.feuerstein
2011-09-09 14:04:26ezio.melottisetmessageid: <1315577066.25.0.522485226844.issue12941@psf.upfronthosting.co.za>
2011-09-09 14:04:25ezio.melottilinkissue12941 messages
2011-09-09 14:04:24ezio.melotticreate