Ejemplo n.º 1
0
def getListOfFirstWords(notes):
    dd = {}
    for nn in notes:
        firstWord = nltk.pos_tag([nltk.word_tokenize(nn.contents)[0]])[0]
        if firstWord[0] in dd:
            dd[firstWord[0]][1] += 1
        else:
            dd[firstWord[0]] = [firstWord[1], 1]
    rr = []    
    for key, pair in dd.items():
        rr.append((key, pair[1]))
    rr.sort(lambda x,y:cmp(x[1],y[1]))
    return rr
Ejemplo n.º 2
0
def getListOfFirstWords(notes):
    dd = {}
    for nn in notes:
        firstWord = nltk.pos_tag([nltk.word_tokenize(nn.contents)[0]])[0]
        if firstWord[0] in dd:
            dd[firstWord[0]][1] += 1
        else:
            dd[firstWord[0]] = [firstWord[1], 1]
    rr = []
    for key, pair in dd.items():
        rr.append((key, pair[1]))
    rr.sort(lambda x, y: cmp(x[1], y[1]))
    return rr
Ejemplo n.º 3
0
 def init_properties(self):
     if hasattr(self,"chest"):
         self.items = []
         if not self.chest:
             names = Item.names[:]
             random.sort(names)
             names = names[:4]
         else:
             names = self.chest.split(",")
         for name in names:
             item = Item()
             item.name = name
             self.items.append(item)
Ejemplo n.º 4
0
    def test():
        # 1.降序
        list_1 = [4, 2, 3, 1]
        list_1.sort(reverse=True)
        print("降序:", list_1)

        # 2.升序
        list_1.sort()  # 默认升序
        print("升序:", list_1)

        # 3.按元素的第二个元素排序
        # 获取列表的第二个元素
        def takeSecond(elem):
            return elem[1]

        random = [(2, 2), (3, 4), (4, 1), (1, 3)]
        random.sort(key=takeSecond)  # 指定第二个元素排序,默认升序
        print('指定元素第二个元素排序:', random)  # 输出类别
Ejemplo n.º 5
0
        -59, 81, 59, -24, 24, -81, 43, 61, 52, 38, -88, -95, 87, -57, -37, -65,
        -47, -3, 21, -77, 98, 25, 1, -36, 39, 78, 47, -35, -40, -69, -81, 11,
        -47, 21, 25, -53, -31
    ]
    random = [random.randint(0, 100) for i in range(0, 100)]

    small = SortingRobot(small)
    print("small")
    small.sort()
    print(small._list)

    medium = SortingRobot(medium)
    print("\nmedium")
    medium.sort()
    print(medium._list)

    large = SortingRobot(large)
    print("\nlarge")
    large.sort()
    print(large._list)

    # varied = SortingRobot(varied)
    # print("\nvaried")
    # varied.sort()
    # print(varied._list)

    random = SortingRobot(random)
    print("\nrandom")
    random.sort()
    print(random._list)
Ejemplo n.º 6
0
#sort() 函数用于对原列表进行排序,如果指定参数,则使用比较函数指定的比较函数。
bbList = ['123', 'Google', 'Runoob', 'Taobao', 'Facebook']

bbList.sort()
print("List : ", bbList)

#以下实例降序输出列表
# 列表
vowels = ['e', 'a', 'u', 'o', 'i']
# 降序
vowels.sort(reverse=True)

# 输出结果
print('降序输出:', vowels)


#以下实例演示了通过指定列表中的元素排序来输出列表:
# 获取列表的第二个元素
def takeSecond(elem):
    return elem[1]


# 列表
random = [(2, 2), (3, 4), (4, 1), (1, 3)]

# 指定第二个元素排序
random.sort(key=takeSecond)

# 输出类别 #排序列表:[(4, 1), (2, 2), (1, 3), (3, 4)]
print('排序列表:', random)
Ejemplo n.º 7
0
 def CmdPickCard(self):
     random.sort(self.cards)
     return self.cards.pop()