コード例 #1
0
def main():
    try:

        with open('assets/type_1_refactor_naming_elements/original.txt',
                  'r',
                  encoding='utf8') as original:
            original_contents = original.readlines()
            original_contents = [
                ''.join(content.strip().split('|'))
                for content in original_contents
            ]

        with open('assets/type_1_refactor_naming_elements/naming_list.txt',
                  'r',
                  encoding='utf8') as source:
            contents = source.readlines()
            contents = [content.strip() for content in contents]

        tokenized_contents = [
            list(word_tokenize(content)) for content in contents
        ]
        original_tokenized_contents = [
            list(word_tokenize(content)) for content in original_contents
        ]

        with open('assets/type_1_refactor_naming_elements/cosine_values.txt',
                  'w',
                  encoding='utf8') as result:
            for sentence in (tokenized_contents):
                for original_sentence in (original_tokenized_contents):
                    vector1 = (count(sentence))
                    vector2 = (count(original_sentence))
                    cosine = get_cosine(vector1, vector2)
                    if cosine >= 0.3:
                        result.write('"' + (''.join(sentence)) + '"' +
                                     ' COMPARED TO ' + '"' +
                                     (''.join(original_sentence)) + '"' +
                                     ' = ' + str(cosine))
                        result.write('\n')

        with open(
                'assets/type_1_refactor_naming_elements/cosine_values_only_value.txt',
                'w',
                encoding='utf8') as result:
            for sentence in (tokenized_contents):
                for original_sentence in (original_tokenized_contents):
                    vector1 = (count(sentence))
                    vector2 = (count(original_sentence))
                    cosine = get_cosine(vector1, vector2)
                    if cosine >= 0.3:
                        result.write(str(cosine))
                        result.write('\n')

    except Exception as e:
        print(e)
コード例 #2
0
def format_winners(winners_data, winners_list, first_season, last_season):
    '''
	Uses a winner list to generate a pie chart acceptable data set.
	'''

    for season in range(first_season, last_season + 1):

        temp = []
        season = str(season)

        # make unique winners key amount of wins
        seasonal_wins = dict(count(winners_data[season]['constructor']))

        # append seasonal winners
        seasonal_winners = []
        for winner, wins in seasonal_wins.items():
            seasonal_winners.append(winner)
            temp.append({'label': winner, 'value': wins})

        # append non seasonal winners with value = 0
        for winner in winners_list:
            if winner not in seasonal_winners:
                temp.append({'label': winner, 'value': 0})

        # sort the temp list alphabetically
        sorted_list = sorted(temp, key=lambda k: k['label'])
        winners_data[season]['constructor'] = sorted_list
コード例 #3
0
    def hand(self):
        player_roll = self.roll
        most_common = count(self.roll).most_common(
            5)  #Checks for dices that are the same
        possible_score = []

        if set(player_roll) == 1 and self.check_if_score("Yatzy") == "":
            possible_score.append("Yatzy")
        else:
            if player_roll == [
                    2, 3, 4, 5, 6
            ] and self.check_if_score("Large Straight") == "":
                hand_score = "Large Straight"
                possible_score.append(hand_score)
            if player_roll == [
                    1, 2, 3, 4, 5
            ] and self.check_if_score("Small Straight") == "":
                hand_score = "Small Straight"
                possible_score.append(hand_score)
            if most_common[0][1] == 3 and most_common[1][
                    1] == 2 and self.check_if_score("Full House") == "":
                hand_score = "Full House"
                possible_score.append(hand_score)
            if most_common[0][1] == 4 and self.check_if_score(
                    "Four Of A Kind") == "":
                hand_score = "Four Of A Kind"
                possible_score.append(hand_score)
            if most_common[0][1] == 3 and self.check_if_score(
                    "Three Of A Kind") == "":
                hand_score = "Three Of A Kind"
                possible_score.append(hand_score)
            if most_common[0][1] == 2 and most_common[1][
                    1] == 2 and self.check_if_score("Two Pairs") == "":
                hand_score = "Two Pairs"
                possible_score.append(hand_score)
            if most_common[0][1] == 2 and self.check_if_score("Pair") == "":
                hand_score = "Pair"
                possible_score.append(hand_score)
            if 6 in player_roll and self.check_if_score("6") == "":
                hand_score = "6"
                possible_score.append(hand_score)
            if 5 in player_roll and self.check_if_score("5") == "":
                hand_score = "5"
                possible_score.append(hand_score)
            if 4 in player_roll and self.check_if_score("4") == "":
                hand_score = "4"
                possible_score.append(hand_score)
            if 3 in player_roll and self.check_if_score("3") == "":
                hand_score = "3"
                possible_score.append(hand_score)
            if 2 in player_roll and self.check_if_score("2") == "":
                hand_score = "2"
                possible_score.append(hand_score)
            if 1 in player_roll and self.check_if_score("1") == "":
                hand_score = "1"
                possible_score.append(hand_score)
            if self.check_if_score("Chance") == "":
                possible_score.append("Chance")
        return possible_score
コード例 #4
0
 def new_order(self, event=None):
     self.subtotal = self.tax = self.total = 0
     for item in self.items.values():
         item.button.config(state=tk.NORMAL)
     self.box.delete(0, tk.END)
     self.current_order = count()
     self.current_codes = []
     self.update_totals()
コード例 #5
0
def score(s):
    occurrences = count(s)
    odd = 0
    score = 0
    for o in occurrences:
        if (not odd):
            if (occurrences[o] % 2):
                odd = 1
        score += (occurrences[o] // 2) * 2
    return score + odd
コード例 #6
0
ファイル: ClassText.py プロジェクト: rgeos/chat
	def getTextCount(self):
		"""
		Regular expression that will look for English words
		It returns a Count object with the word frequency
		:return:    object
		"""
		pattern = '(?:\w+|[' + re.escape(punctuation) + ']+)'
		# pattern = '\w+'
		regex = re.compile(pattern)
		words = regex.findall(self.getText().lower())

		return count(words).items()
コード例 #7
0
def rotate(cipher, ch):
    alphabet = "abcdefghijklmnopqrstuvwxyz".upper()
    plain = ""
    num = alphabet.find(ch)
    if num:
        for char in cipher:
            idx = alphabet.find(char) - num
            plain += alphabet[idx]
        print(count(plain))
        return plain
    else:
        return False
コード例 #8
0
def beauty_strings(s):
    res = 0
    out = s.translate(string.maketrans("", ""), string.punctuation)
    c = count(out.replace(" ", ""))
    a = c.most_common(26)
    keys = []
    values = reversed(range(1, 27))
    for i in a:
        keys.append(i[0])
    dct = dict(zip(keys, values))
    for c in s:
        res += dct.get(c, 0)
    return res
コード例 #9
0
 def tf_idf(self):
     for word in self.word_bank:
         print(word)
         temp = self.word_bank[word]
         t = count(temp)
         te = t.keys()
         tv = t.values()
         w = []
         for name in range(len(te)):
             tr = tv[name] * math.log10(self.total_len / len(te))
             # print (te[name], tr)
             w.append([te[name], tr])
         self.word_bank[word]=w
コード例 #10
0
ファイル: POS2.py プロジェクト: christirox/MIS-Project
 def __init__(self, parent):
     self.parent = parent
     self.money = 0
     self.items = {
         "candy bar":
         Item(
             "candy bar", 165,
             tk.Button(root,
                       text="candy bar",
                       command=lambda: self.scan("cand bar"))),
         "soda":
         Item(
             "soda", 115,
             tk.Button(root, text="soda",
                       command=lambda: self.scan("soda"))),
         "chips":
         Item(
             "chips", 285,
             tk.Button(root,
                       text="chips",
                       command=lambda: self.scan("chips"))),
         "granola bar":
         Item(
             "granola bar", 145,
             tk.Button(root,
                       text="granola bar",
                       command=lambda: self.scan("granola bar"))),
         "almond milk":
         Item(
             "almond milk", 535,
             tk.Button(root,
                       text="almond milk",
                       command=lambda: self.scan("almond milk")))
     }
     self.server_label = tk.Label(root, text="Cashier: Christina")
     self.server_label.grid(row=0, column=0, sticky='w')
     self.time_label = tk.Label(root, text='')
     self.time_label.grid(row=0, column=1, sticky='E')
     for idx, item in enumerate(self.items.values(), start=1):
         item.button.grid(row=idx, column=0, sticky='w')
     self.frame = tk.Frame(root)
     self.frame.grid(row=1, column=1, rowspan=6)
     self.scrollbar = tk.Scrollbar(self.frame, orient=tk.VERTICAL)
     self.box = tk.Listbox(self.frame,
                           yscrollcommand=self.scrollbar.set,
                           width=25)
     self.scrollbar.config(command=self.box.yview)
     self.box.grid(row=0, column=1, sticky='NS')
     self.current_order = count()
     self.tick()
コード例 #11
0
ファイル: views.py プロジェクト: autosaver/Base_site
def text_process(request):
    value = request.POST.get("string")
    string = "Original String capitalized : " + value.capitalize()
    string += "<br> Number of characters in this string are : " + str(
        len(value))
    string += "<br> Number of vowels in this string are : " + str(
        value.count('a') + value.count('e') + value.count('i') +
        value.count('o') + value.count('u'))
    counts = count(value)
    result = {
        'result': string,
        'charcount': counts,
    }
    return render(request, 'textutils_result.html', result)
コード例 #12
0
def cantidad_cursos(horario):
    puntaje = 0
    cursos = []
    for dia in horario:
        for hora in horario[dia]:
            for salon in horario[dia][hora]:
                cursos.append(horario[dia][hora][salon].numero)
    cursos = count(cursos) #Se usa el metodo Count el cual retorna un diccionario con los cursos que tenga el horario y la frecuencia en que aparecen los mismos
    cursos_faltantes = total_cursos - len(cursos.keys())
    if(cursos_faltantes > 0): puntaje += 5000*(cursos_faltantes) #Se penalizan los cursos faltantes
    bloques_cursos = cursos.values()
    for bloque in bloques_cursos:
        bloques_adicionales = abs(horas_semanales/2 - bloque)
        if(bloques_adicionales > 0): puntaje += 500*(bloques_adicionales) #Se penalizan los bloques de cursos faltantes o excesivos
    return puntaje
コード例 #13
0
ファイル: views.py プロジェクト: marvinliu19/hackUST2016
def build_hashtag_freq(tweets):
    hashtag_counts = {}
    for tweet in tweets: #each tweet will be a Python dictionary
        hashtags = extract_hashtags(tweet['text'].encode('ascii', 'ignore'))
        for hashtag in hashtags:
            if hashtag in hashtag_counts:
                hashtag_counts[hashtag] += 1
            else:
                hashtag_counts[hashtag] = 1

    top_hashtags = {'hashtags': []}

    hashtag_counts = count(hashtag_counts)
    for k, v in hashtag_counts.most_common(7):
        top_hashtags['hashtags'].append([k, v])
    return top_hashtags
コード例 #14
0
ファイル: Yahtzee.py プロジェクト: bbusenius/Projects
def score(hand):
    """
    Compute the maximal score for a Yahtzee hand according to the
    upper section of the Yahtzee score card.

    hand: full yahtzee hand

    Returns an integer score 
    """
    retval = 0
    counter = count(hand).most_common()
    if len(hand) > 0:
        for item in counter:
            if item[0] * item[1] > retval:
                retval = item[0] * item[1]
    return retval
コード例 #15
0
def score(hand):
    """
    Compute the maximal score for a Yahtzee hand according to the
    upper section of the Yahtzee score card.

    hand: full yahtzee hand

    Returns an integer score 
    """
    retval = 0
    counter = count(hand).most_common()
    if len(hand) > 0:
        for item in counter:
            if item[0] * item[1] > retval:
                retval = item[0] * item[1]
    return retval
コード例 #16
0
 def __init__(self, parent):
     self.parent = parent
     parent.title('Point of Sale')
     self.font = ('Courier New', 12)
     self.till = 0
     self.TAX = 1.08
     self.items = {'lemonade':Item('Lemonade', 50,
                                   tk.Button(root,
                                   text='Lemonade',
                                   command=lambda: self.scan('lemonade'),
                                   font=self.font)),
                   'grapefruit_juice':Item('Grapefruit Juice', 75,
                                           tk.Button(root,
                                           text='Grapefruit Juice',
                                           command=lambda: self.scan('grapefruit_juice'),
                                           font=self.font)),
                    'cookie':Item('Cookie', 100,
                                  tk.Button(root,
                                  text='Cookie',
                                  command=lambda: self.scan('cookie'),
                                  font=self.font))}
     self.MAX_NAME_WIDTH = max(map(len, (item.name for item in self.items.values()))) + 3
     self.MAX_PRICE_WIDTH = 10
     self.server_label = tk.Label(root, text='Cashier: Bob', font=self.font)
     self.server_label.grid(row=0, column=0, sticky='W')
     self.time_label = tk.Label(root, text='', font=self.font)
     self.time_label.grid(row=0, column=1, sticky='E')
     for idx,item in enumerate(self.items.values(), start=1):
         item.button.grid(row=idx, column=0, sticky='W')
     self.frame = tk.Frame(root)
     self.frame.grid(row=1, column=1, rowspan=3)
     self.scrollbar = tk.Scrollbar(self.frame, orient=tk.VERTICAL)
     self.box = tk.Listbox(self.frame,
                           yscrollcommand=self.scrollbar.set,
                           width=self.MAX_NAME_WIDTH + self.MAX_PRICE_WIDTH,
                           font=self.font)
     self.scrollbar.config(command=self.box.yview)
     self.box.grid(row=0, column=1, sticky='NS')
     self.scrollbar.grid(row=0, column=2, sticky='NS')
     self.box.bind("<Double-Button-1>", self.modify_item)
     self.total_label = tk.Label(root, text='', font=self.font)
     self.total_label.grid(row=4, column=1, sticky='E')
     self.current_order = count()
     self.current_codes = []
     self.update_totals()
     self.tick()
コード例 #17
0
def are_adj(num):
    adj = []
    if num[0] == num[1]:
        adj.append(num[0])
    if num[1] == num[2]:
        adj.append(num[1])
    if num[2] == num[3]:
        adj.append(num[2])
    if num[3] == num[4]:
        adj.append(num[3])
    if num[4] == num[5]:
        adj.append(num[4])
    test = count(adj).values()
    if 1 in test:
        return True
    else:
        return False
コード例 #18
0
ファイル: filters.py プロジェクト: MatteoLacki/rta
def filter_K_foldable(annotated, annotated_stats, K):
    """Filter peptides divisible into K cv-folds.

    Returns sparser copies of the original DF and its statistics.
    Derprecated.

    Args:
        annotated (pd.DataFrame):       Annotated peptides.
        annotated_stats (pd.DataFrame): Statistics on peptide groups.
        K (int):                        Number of folds.
    """
    run_counts = count(annotated_stats.runs)
    infrequent_runs = set(el for el, cnt in run_counts.items() if cnt < K)
    annotated_cv = annotated[~annotated.runs.isin(infrequent_runs)]
    annotated_stats_cv = annotated_stats[~annotated_stats.runs.
                                         isin(infrequent_runs)]
    return annotated_cv, annotated_stats_cv, run_counts
コード例 #19
0
def gramGraph(tokens, n, name, top=30):
    countGram = count(listGrams(tokens, n))
    test = countGram.most_common(top)

    labels = []
    values = []
    indexes = range(len(test))
    for i in indexes:
        labels.append(', '.join(test[i][0]))
        values.append(test[i][1])

    fig = plt.gcf()
    fig.set_size_inches(.7 * top, 10)

    plt.bar(indexes, values, 1)
    plt.xticks(indexes, labels, rotation=70, ha='right')
    plt.title(name, fontsize=20)

    return fig
コード例 #20
0
def solution(N, stages):
    answer = []
    failure = dict()
    userStage = count(stages)
    totalUser = len(stages)

    for i in range(1, N + 1):
        stayUsers = userStage[i]
        if stayUsers == 0:
            failure[i] = 0
        else:
            failure[i] = stayUsers / totalUser
        totalUser -= stayUsers

    sorted_failure = sorted(failure.items(),
                            key=operator.itemgetter(1),
                            reverse=True)

    for k, v in sorted_failure:
        answer.append(k)

    return answer
コード例 #21
0
def mostFrequent(text, k):
    wordsArray = text.split(" ")  #O(n)
    histogramOfWords = count(wordsArray)  #O(n)

    print(histogramOfWords)

    lenHistogramOfWords = len(histogramOfWords)
    results = []

    while len(results) < k and lenHistogramOfWords > 0:
        word = None
        currentMax = float('-inf')

        for key in histogramOfWords:
            tempMax = currentMax
            currentMax = max(currentMax, histogramOfWords[key])
            if currentMax != tempMax or word == None:
                word = key

        results.append(word)
        del histogramOfWords[word]
        lenHistogramOfWords -= 1

    return results
コード例 #22
0
        root = ET.fromstring(t_read)
        doc_no = root.find('DOCNO').text
        title = root.find('TITLE').text
        text = root.find('TEXT').text
        result = tokenizer(title + text)
        for word in result:
            if word in word_bank:
                word_bank[word].append(doc_no)
            else:
                word_bank[word] = []
                word_bank[word].append(doc_no)
file = 0
for word in word_bank:
    temp = word_bank[word]
    t = count(temp)
    # print(t.keys(),t.values())
    file += 1
    te = t.keys()
    tv = t.values()
    w = []
    # print(te)
    for name in range(len(te)):

        tr = tv[name] * math.log10(4 / len(te))
        print(te[name], tr)
        w.append([te[name], tr])
        # print (te[name],tv[name]*math.log10(4/len(te)))

    print('word completed')
    print("-----------------------")
コード例 #23
0
ファイル: hw3.py プロジェクト: QuasiChameleon/sampleCode
def reducefn(author, terms): # i.e. key, value
  from collections import Counter as count
  return count(terms)
コード例 #24
0
# Path to cipher file
file1 = "./found2"

# Set key length
key_len = 6

# Read cipher file
f = open(file1)
found = f.readline()
found = found.replace(" ", "")  # remove spaces

# Split cipher text into n (key_length) different mono alphapbetic ciphers
split_list = split_cipher(found, key_len)
for cipher in split_list:
    print(count(cipher))

#                5    10   15   20   25
#alphabet = "abcdefghijklmnopqrstuvwxyz"
print("Frequency plain text:")
rot = []
rot.append(rotate(split_list[0], 'F'))
rot.append(rotate(split_list[1], 'R'))
rot.append(rotate(split_list[2], 'E'))
rot.append(rotate(split_list[3], 'K'))
rot.append(rotate(split_list[4], 'E'))
rot.append(rotate(split_list[5], 'Y'))

join_rot = join_cipher(rot, key_len)

print_with_len(join_rot, key_len)
コード例 #25
0
ファイル: cricbase.py プロジェクト: emranblue/Cricket
 def insert_new_player(self, x, y):
     n = count(y)
     self.cur.execute(
         "insert into {}(player_name,run,six,four) values(?,?,?,?)".format(
             self.game_name), (x, sum(y), n[6], n[4]))
     self.db.commit()
コード例 #26
0
ファイル: pro35.py プロジェクト: VINISHAV/python1
from collections import count
str = "vini is a little girl"
counter = count(str)
print count['a']
コード例 #27
0
#!/usr/bin/python3
'''
john works at  clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each soc, determine how many pairs of socks with matching colors there are.
For Example, there are n = 7 socks with colors ar = [1,2,1,2,1,3,2]. There is one pair of color 1 and one of color 2.
and there are three odd socks left, one of each color. The number of pairs is 2.

Example: - Sample Input = 9
                          10 20 20 10 10 10 30 50 10 20
           Sample Output = 3
'''
from collections import Counter as count
n = int(input())
socks = count(input().split())
print(sum(map(lambda x: x // 2, socks.values())))
コード例 #28
0
	print("Something wicked happened when trying to read from the database", file=stderr)
	print(e, file=stderr)
	exit(5)
finally:
	db.close()
	connection.close()


###################################################
### 				DATA OUTPUT					###
###################################################

#				  OUTPUT ON STDOUT				  #

from collections import Counter as count
formattedResults = count(dataToAnalyze)
total = len(dataToAnalyze)
print("\n".join([key+"\t"+str(formattedResults[key])+"\t"+str(formattedResults[key]*100.0/total)+"%" for key in sorted(formattedResults)]))


#				  PIE CHART OUTPUT				  #

try:
	from matplotlib import pyplot as plt
except ImportError as e:
	print("You don't appear to have matplotlib installed. Try `sudo apt install python3-matplotlib` or `sudo -H pip3 install matplotlib` and then run this program again.", file=stderr)
	exit(3)

### set up inputs to matplotlib from the data ###
labels = tuple(sorted(formattedResults)) #pie slice labels
sizes = [formattedResults[label] for label in labels] #just the counts for each label (in the same order!)
コード例 #29
0
ファイル: cricbase.py プロジェクト: emranblue/Cricket
 def out_info(self, x, y, total_out):
     n = count(y)
     print('{} is out run({}) four({}) six({})'.format(
         x, sum(y), n[4], n[6]))
     total_out += 1
     return total_out
コード例 #30
0
def process_inputs_2(df):
    df1 = df.copy()
    df2 = df.copy()
    df3 = df.copy()
    df4 = df.copy()
    df5 = df.copy()
    from collections import Counter as count
    bases = []
    for j in range(len(df1)):
        counts = dict(count(df1.iloc[j]['sequence']))
        bases.append((counts['A'] / df1.iloc[j]['seq_length'],
                      counts['G'] / df1.iloc[j]['seq_length'],
                      counts['C'] / df1.iloc[j]['seq_length'],
                      counts['U'] / df1.iloc[j]['seq_length']))

    bases = pd.DataFrame(
        bases, columns=['A_percent', 'G_percent', 'C_percent', 'U_percent'])
    del df1
    print("Done : ['A_percent', 'G_percent', 'C_percent', 'U_percent']")

    pairs = []
    all_partners = []
    for j in range(len(df2)):
        partners = [-1 for i in range(130)]
        pairs_dict = {}
        queue = []
        for i in range(0, len(df2.iloc[j]['structure'])):
            if df2.iloc[j]['structure'][i] == '(':
                queue.append(i)
            if df2.iloc[j]['structure'][i] == ')':
                first = queue.pop()
                try:
                    pairs_dict[(df2.iloc[j]['sequence'][first],
                                df2.iloc[j]['sequence'][i])] += 1
                except:
                    pairs_dict[(df2.iloc[j]['sequence'][first],
                                df2.iloc[j]['sequence'][i])] = 1

                partners[first] = i
                partners[i] = first

        all_partners.append(partners)

        pairs_num = 0
        pairs_unique = [('U', 'G'), ('C', 'G'), ('U', 'A'), ('G', 'C'),
                        ('A', 'U'), ('G', 'U')]
        for item in pairs_dict:
            pairs_num += pairs_dict[item]
        add_tuple = list()
        for item in pairs_unique:
            try:
                add_tuple.append(pairs_dict[item] / pairs_num)
            except:
                add_tuple.append(0)
        pairs.append(add_tuple)

    pairs = pd.DataFrame(pairs,
                         columns=['U-G', 'C-G', 'U-A', 'G-C', 'A-U', 'G-U'])
    del df2
    print("Done : ['U-G', 'C-G', 'U-A', 'G-C', 'A-U', 'G-U']")

    pairs_rate = []
    for j in range(len(df3)):
        res = dict(count(df3.iloc[j]['structure']))
        pairs_rate.append(res['('] / (df3.iloc[j]['seq_length'] / 2))

    pairs_rate = pd.DataFrame(pairs_rate, columns=['pairs_rate'])
    del df3

    loops = []
    for j in range(len(df4)):
        counts = dict(count(df4.iloc[j]['predicted_loop_type']))
        available = ['E', 'S', 'H', 'B', 'X', 'I', 'M']
        row = []
        for item in available:
            try:
                row.append(counts[item] / df4.iloc[j]['seq_length'])
            except:
                row.append(0)
        loops.append(row)

    loops = pd.DataFrame(loops, columns=available)
    del df4
    print("Done : ['E', 'S', 'H', 'B', 'X', 'I', 'M']")

    return pd.concat([df5, bases, pairs, loops, pairs_rate], axis=1)
コード例 #31
0
    def add_score(self, comb):
        comb = comb.title()
        most_common = count(self.roll).most_common(5)

        if comb not in self.hand():
            if self.player == 1:
                if self.score[comb] == "":
                    self.score[comb] = 0
            else:
                if self.score2[comb] == "":
                    self.score2[comb] = 0
        else:
            if comb == "Yatzy":
                if self.player == 1:
                    self.score[comb] = 50
                else:
                    self.score2[comb] = 50
            elif comb == "Large Straight":
                if self.player == 1:
                    self.score[comb] = 40
                else:
                    self.score2[comb] = 40
            elif comb == "Small Straight":
                if self.player == 1:
                    self.score[comb] = 30
                else:
                    self.score2[comb] = 30
            elif comb == "Full House":
                points = most_common[0][0] * most_common[0][1]
                points2 = most_common[1][0] * most_common[1][1]
                if self.player == 1:
                    self.score[comb] = points + points2
                else:
                    self.score2[comb] = points + points2
            elif comb == "Four Of A Kind":
                points = most_common[0][0] * most_common[0][1]
                if self.player == 1:
                    self.score[comb] = points
                else:
                    self.score2[comb] = points
            elif comb == "Three Of A Kind":
                points = most_common[0][0] * most_common[0][1]
                if self.player == 1:
                    self.score[comb] = points
                else:
                    self.score2[comb] = points
            elif comb == "Two Pairs":
                points = most_common[0][0] * most_common[0][1]
                points2 = most_common[1][0] * most_common[1][1]
                if self.player == 1:
                    self.score[comb] = points + points2
                else:
                    self.score2[comb] = points + points2
            elif comb == "Pair":
                points = most_common[0][0] * most_common[0][1]
                if self.player == 1:
                    self.score[comb] = points
                else:
                    self.score2[comb] = points
            elif comb == "6":
                points = [x for x in self.roll if x == 6]
                if self.player == 1:
                    self.score[comb] = sum(points)
                else:
                    self.score2[comb] = sum(points)
            elif comb == "5":
                points = [x for x in self.roll if x == 5]
                if self.player == 1:
                    self.score[comb] = sum(points)
                else:
                    self.score2[comb] = sum(points)
            elif comb == "4":
                points = [x for x in self.roll if x == 4]
                if self.player == 1:
                    self.score[comb] = sum(points)
                else:
                    self.score2[comb] = sum(points)
            elif comb == "3":
                points = [x for x in self.roll if x == 3]
                if self.player == 1:
                    self.score[comb] = sum(points)
                else:
                    self.score2[comb] = sum(points)
            elif comb == "2":
                points = [x for x in self.roll if x == 2]
                if self.player == 1:
                    self.score[comb] = sum(points)
                else:
                    self.score2[comb] = sum(points)
            elif comb == "1":
                points = [x for x in self.roll if x == 1]
                if self.player == 1:
                    self.score[comb] = sum(points)
                else:
                    self.score2[comb] = sum(points)
            elif comb == "Chance" and self.check_if_score("Chance") == "":
                if self.player == 1:
                    self.score[comb] = sum(self.roll)
                else:
                    self.score2[comb] = sum(self.roll)
コード例 #32
0
def listContains(l1, l2):
    list1 = count(l1)
    list2 = count(l2)

    return list1 & list2 == list1  # bitwise &
コード例 #33
0
 def parse_line(self, line):
     d = {}
     c = count(d, line)
     return d 
コード例 #34
0
    return output


#%%
tokens = tokenList(comments)
#%%
#docs = ['why hello there', 'omg hello pony', 'she went there? omg']

vec = CountVectorizer()
X = vec.fit_transform(tokens[1])
df = pd.DataFrame(X.toarray(), columns=vec.get_feature_names())
print(X)

#%%
# We have a list of a list of ordered tokens that we need to find the nGrams of
countMonogram = count(listGrams(tokens, 1))
countBigram = count(listGrams(tokens, 2))
countTrigram = count(listGrams(tokens, 3))
countTetragram = count(listGrams(tokens, 4))

#%%
countMonogram.most_common(30)
#%%
countBigram.most_common(30)
#%%
countTrigram.most_common(30)
#%%
countTetragram.most_common(30)
#%%

#%%
コード例 #35
0
ファイル: cricbase.py プロジェクト: emranblue/Cricket
 def score_card_update(self, x, y):
     n = count(x)
     self.cur.execute(
         "update {} set run=?,six=?,four=? where player_name=?".format(
             self.game_name), (sum(x), n[6], n[4], y))
     self.db.commit()