本文整理汇总了Python中java.util.Collections.shuffle方法的典型用法代码示例。如果您正苦于以下问题:Python Collections.shuffle方法的具体用法?Python Collections.shuffle怎么用?Python Collections.shuffle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.shuffle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: append_to_errors
# 需要导入模块: from java.util import Collections [as 别名]
# 或者: from java.util.Collections import shuffle [as 别名]
def append_to_errors(self, errorsList, check):
"""Clean errors list from duplicate errors and ids that must be
ignored
"""
if errorsList[0][0] == "":
#osmId == "", this tool doesn't give id of OSM objects
check.errors = [Error(check, e) for e in errorsList]
else:
if check.ignoreIds != []:
#remove OSM objects that the user wants to ignore
check.errors = [Error(check, e) for e in errorsList if e[0] not in check.ignoreIds]
#remove duplicate ids
#check.errors = dict((e.osmId, e) for e in check.errors).values()
else:
#copy all errors and remove duplicate ids
#check.errors = dict((e[0], Error(e)) for e in errorsList).values()
check.errors = [Error(check, e) for e in errorsList]
#Remove from the list of errors those that have been reviewed yet
#while clicking the "Next" button
check.errors = [e for e in check.errors if e.osmId not in check.reviewedIds]
#print "\n- errors of selected check in current zone:", [e.osmId for e in check.errors]
#Randomize the errors so that different users don't start
#correcting the same errors
Collections.shuffle(check.errors)
#Filter errors in favourite zone
if self.app.favouriteZoneStatus and self.app.favZone.zType != "rectangle":
#not rectangular favourite area, use jts
from com.vividsolutions.jts.geom import Coordinate, GeometryFactory
polygon = self.app.favZone.wktGeom
errorsInPolygon = []
for error in check.errors:
(lat, lon) = error.coords
point = GeometryFactory().createPoint(Coordinate(lon, lat))
if polygon.contains(point):
if error not in errorsInPolygon:
errorsInPolygon.append(error)
check.errors = errorsInPolygon
#Apply limits from preferences
#max number of errors
limits = []
if self.app.maxErrorsNumber != "":
limits.append(self.app.maxErrorsNumber)
try:
if self.tool.prefs["limit"] != "":
limits.append(int(self.tool.prefs["limit"]))
except:
pass
if limits != []:
check.errors = check.errors[:min(limits)]
#Reset index of current error
check.currentErrorIndex = -1
check.toDo = len(check.errors)
示例2: getRandomWord
# 需要导入模块: from java.util import Collections [as 别名]
# 或者: from java.util.Collections import shuffle [as 别名]
def getRandomWord(self):
""" generated source for method getRandomWord """
if self.scrambledTokens.isEmpty():
for word in WordList.words:
self.scrambledTokens.add(word + self.scrambledPrefix)
Collections.shuffle(self.scrambledTokens, self.random)
self.scrambledPrefix += 1
return self.scrambledTokens.pop()
示例3: __init__
# 需要导入模块: from java.util import Collections [as 别名]
# 或者: from java.util.Collections import shuffle [as 别名]
def __init__(self, theRandom):
""" generated source for method __init__ """
super(MappingGdlScrambler, self).__init__()
self.random = theRandom
self.scrambleMapping = HashMap()
self.unscrambleMapping = HashMap()
self.scrambledPrefix = 0
self.scrambledTokens = Stack()
for word in WordList.words:
self.scrambledTokens.add(word)
Collections.shuffle(self.scrambledTokens, self.random)