當前位置: 首頁>>代碼示例>>Python>>正文


Python Collections.shuffle方法代碼示例

本文整理匯總了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)
開發者ID:alex85k,項目名稱:qat_script,代碼行數:61,代碼來源:download_and_parse.py

示例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()
開發者ID:hobson,項目名稱:ggpy,代碼行數:10,代碼來源:MappingGdlScrambler.py

示例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)
開發者ID:hobson,項目名稱:ggpy,代碼行數:13,代碼來源:MappingGdlScrambler.py


注:本文中的java.util.Collections.shuffle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。