#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. """Random function identical to random.choice(), but pop() that item >>> ex = ["Hello", "World"] >>> choice_pop(ex) 'Hello' >>> ex ['World'] """ __all__ = ['choice_pop'] __author__ = "Cody A. Taylor ( codemister99@yahoo.com )" __version__ = "2.0" import _random def choice_pop(seq): """Randomly pops a single item out of a sequence """ return seq.pop(int(_random.Random().random() * len(seq)))