blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
545k
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
545k
708d5102fb648b48abd4dd3886f5bb923cf2b856
varunmalik123/Python-Data-Analysis
/write_columns.py
930
4.53125
5
def write_columns(data,fname): """ The purpose of this function is to take a list of numbers and perform two calculations on it. The function will generate a csv file with three columns containing the original data and the result from the first to calculations respectively :param data(list with elements being e...
53d9f7348bca15335ed9d211d335c772919f1664
varunmalik123/Python-Data-Analysis
/interval.py
1,267
4.09375
4
class Interval(object): def __init__(self, a, b): """ The purpose of this class is to add two Interval objects that represent a one-dimensional open interval on the real line :param a(int): integer :param b(int): integer """ assert a < b assert isinst...
bda197dc12d4e2a1dec864b735ad70aaa25d97e4
varunmalik123/Python-Data-Analysis
/is_string_a_valid_int.py
285
4
4
def is_string_integer(char): """ Checks if char is a base 10 integer and returns a Boolean value. :param char: Input string. Can only contain one character :type char: str """ boolean = char.isdigit() assert isinstance(char,str) assert len(char) == 1 return boolean
03acd34a0d1f07bfcefff7604bfeded573356666
varunmalik123/Python-Data-Analysis
/write_chunks_of_five.py
501
3.984375
4
def write_chunks_of_five(words, fname): """ The purpose of this function is to take a list of words and output them into a text file with 5 words per line :param words(lst): Input string containing list of words :param fname(str): Name of output file """ assert isinstance(words, list) assert isinstance(fna...
6487c8219beb66690a4a4b841cad55299166ff58
JasonTuyen/RandomFE3H
/RandomFE3H.py
4,405
3.578125
4
""" create a GUI no DLC characters yet """ import csv import random import tkinter mainChar = ["Bylad", "Bylass"] lordChar = ["Cyril", "Edelgard", "Dimitri", "Claude"] route = [] def routePath(value): switcher={ "Church" : "church_route.csv", "Black Eagles": "be_r...
0a3296b4e7b3ea9e0eaf0d023b509b6062a0e063
thesmallstar/bio-assignment-sem7
/q4/p1/sp3/sp3.py
983
3.5
4
from typing import List from Bio import SeqIO inp_file = "../data/beta_amylase_cereus.fasta" def get_inp_seqs(input_file): fasta_sequences = SeqIO.parse(open(input_file), 'fasta') sequences = [] for fasta in fasta_sequences: sequences.append(str(fasta.seq)) return sequences def get_reverse_...
73d4e39850e9a3b5a234e5fc5bd41fabc61cbc4e
sealneaward/lesson-plan
/lessons/arrays-str-manipulation/manip/code/manipulation.py
837
3.609375
4
def str_replace(word, bad_str, good_str): # use the replace to fix the mistake return word bad_memo = 'I knew I was always going to be half-bear, half man. Being mixed race is so meta, I bet Neil would never understand. What would he know?' good_memo = str_replace(bad_memo, put_bad_str_here, put_good_...
65d78143dab89c7ecdd59dadf243616c2b94d36a
sunnydroid/notebooks
/Scikitlearn/titanic_survival_decision_tree_rand_forest.py
14,885
4.0625
4
# Datacamp tutorial here : https://campus.datacamp.com/courses/kaggle-python-tutorial-on-machine-learning/getting-started-with-python?ex=1 # Import the Pandas library import pandas as pd # Load the train and test datasets to create two DataFrames train_url = "http://s3.amazonaws.com/assets.datacamp.com/course/Kaggle/...
27e710fb9f20d2d9487bdac02009af6c02f6b620
chaochen95/image_spider
/dhash.py
2,244
3.546875
4
# -*- coding: UTF-8 -*- from PIL import Image import os, sys #1.缩小图片:收缩到9*8的大小,一遍它有72的像素点 #2.转化为灰度图:把缩放后的图片转化为256阶的灰度图。(具体算法见平均哈希算法步骤) #3.计算差异值:dHash算法工作在相邻像素之间,这样每行9个像素之间产生了8个不同的差异,一共8行,则产生了64个差异值 #4.获得指纹:如果左边的像素比右边的更亮,则记录为1,否则为0. def get_dhash(loc): rwidth = 9 rheight = 8 img = Image.open(loc) im...
5f6fb8aae1249d25774cf94ddea5c0fb8b9d41a2
Demon520-coder/PythonStudy
/study_08/Dog.py
597
4.40625
4
#创建类: #注意点:1.约定类的首字母大写;2.类的构造函数为:__init__;3.类中的每一个方法都必须传递self形参,因为python在创建实例时会自动传递self; #3.python类没有构造函数重载; class Dog(): def __init__(self,name,age): self.name=name self.age=age def sit(self): print("This dog has beeb sit") def show(self): msg="Dog's name is "+self.name...
66bf24206729bd528d25e17d6eab705c34661d43
Demon520-coder/PythonStudy
/study_10/User.py
955
3.71875
4
class User(): def __init__(self,user_name,pwd): self.user_name=user_name self.pwd=pwd def login(self,name,pwd): if name.lower()==(self.user_name.lower()) and pwd.lower()==(self.pwd.lower()): return self else: return None class AdminUser(User): def ...
252bbca8310794f46c6eb24afacc135492508421
Demon520-coder/PythonStudy
/study_01/homework.py
1,427
4.34375
4
#01.输出一段字符串: print('This is my first python program') #02.定义一个变量,并输出大写,小写,首字母大写形式 name='Mr jonh james' print(name.upper()) print(name.lower()) print(name.title()) #03.去除字符串首位空格、末尾空格、首位空格 address=' Beijin ' print('|'+address+'|') print('|'+address.lstrip()+'|') print('|'+address.rstrip()+'|') print('|'+address.strip()+'...
e954189031716dbd4df24971a3ff7410960a4b58
LikhithKumarCG/assignment2-and-3
/letsupgrade.py
1,909
3.90625
4
#!/usr/bin/env python # coding: utf-8 # In[ ]: #Assignment 2 # In[ ]: #question1: x=int(input ("enter marks")) if x>=80 and x<=100: print("A") elif x>=60 and x<80: print("B") elif x>=60 and x<70: print("C") elif x>=50 and x<60: print("D") else: print("fail") # In[ ]: #question2: from r...
facc9e0527af374adb2b90bdf18fd36e82e39cb1
Vorztek/Jos-
/Test/test.py
322
3.640625
4
import time start_time = time.time() liste = [] liste_paire = [] chiffre2 = int(input("Chiffre 2 : ")) for i in range(1, chiffre2 + 1): liste.append(i) for i in liste: if i % 2 == 0: liste_paire.append(i) elapsed_time = time.time() - start_time print(elapsed_time, len(liste_paire)...
a5cc74e3e224d812a7a08f7e52a35f3ef3cbdff4
Vorztek/Jos-
/math/math_exo/pfc.py
1,766
3.59375
4
#: Créer un programme qui jouer à Pierre feuille ciseaux, et donne le gagnant de chaque partie #Créer un CSV avec le résultat de chaque partie et l'évolution du nombre de fois où chaque élément a gagné. # La phrase devra être pour chaque résultat dans le CSV (par exemple pour 1000 parties) : #1000ème partie, Pierre co...
e2516b07a2f16d5b719b51e0b89d579b2b44076c
Vorztek/Jos-
/math/math_exo/diviseur.py
208
3.796875
4
# liste des diviseurs d'un nombre entier liste3 = [] def diviseur(entier): for i in range(1, entier): if entier % i == 0: liste3.append(i) return liste3 print(diviseur(1700))
d8df82383460b7c1730b7d2af1623a797fb35e5e
ra3738/Latext
/hasConsSpace.py
1,261
4.15625
4
#Checks if current index is a space, returns boolean def isThisASpace(str, index): if (str[index] == " "): return True else: return False #Checks if current index and next index are spaces, returns boolean #If at second last index, returns false def hasConsSpaces(str, index): if (index + 1 < len(str)): if (i...
49d1443ea3d6ec2f5040705b2d9fd6bc316c0a55
bkapadia01/python3_hardway
/ex_21.py
770
3.96875
4
def add(a,b): print(f"adding {a} + {b}") return a + b def subtract(a,b): print(f"subtract {a} - {b}") return a - b def multiply(a,b): print(f"multiply {a} * {b}") return a * b def divide(a,b): print(f"divide {a} / {b}") return a / b print ("lets do some math with just functions") x =...
7467bc55fbf2a39552a9408c9633c5b5cab43f04
bkapadia01/python3_hardway
/ex_40a.py
633
3.5625
4
#this is a dictonary mystuffs = {'apple': "I AM APPLE"} print(mystuffs['apple']) #import the modules/functions from other files import mystuff import myfruits #from the mystuff.py file with function apple() mystuff.apple() print(mystuff.tangerine) class MyStuffB(object): def __init__(self): self.tangrin...
3060d4c3f53a1a2a35e9c41f79cf6c5c8b08402f
JadedCoder712/Character-Distribution
/testing123.py
2,877
4.21875
4
""" distribution.py Author: Kyle Postans Credit: Kyle Postans, Mr. Dennison Assignment: Write and submit a Python program (distribution.py) that computes and displays the distribution of characters in a given sample of text. Output of your program should look like this: Please enter a string of text (the bigger th...
d813410eeabb8a7e7a6fe3ed2fbf4ec8ff20e8fa
RohitPr/PythonProjects
/23.U.S.States_List/main.py
939
3.703125
4
import pandas import turtle screen = turtle.Screen() image = "blank_states_img.gif" screen.addshape(image) turtle.shape(image) data = pandas.read_csv("50_states.csv") state_list = data.state.to_list() states_guessed = [] score = 0 game = True while game: user_input = screen.textinput(title="Gu...
0cc275639d9847d73865c59c944c271b99605bb7
RohitPr/PythonProjects
/07. Banker Roulette/7.Banker_Roulette.py
502
4.34375
4
""" You are going to write a program which will select a random name from a list of names. The person selected will have to pay for everybody's food bill. Important: You are not allowed to use the choice() function. """ import random names_string = 'Angela, Ben, Jenny, Michael, Chloe' names = names_string.s...
dac754f1b2b0df7bbdb494d0b618599b679fd81d
RohitPr/PythonProjects
/54.SQL_Lite_BookShelf/sqlite_CRUD.py
1,332
3.65625
4
# Create New Database from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///<name of database>.db" db = SQLAlchemy(app) # Create New Table class Book(db.Model): id = db.Column(db.Integer, primary_key=True) title ...
7f2713e479bc69690724b0bdb162f2921bd116eb
RohitPr/PythonProjects
/05. Love Calculator/5.Love_Calculator.py
1,266
3.9375
4
# write a program that tests the compatibility between two people. """ Take both people's names and check for the number of times the letters in the word TRUE occurs. Then check for the number of times the letters in the word LOVE occurs. Then combine these numbers to make a 2 digit number. """ print("Welcome...
082972c6f3ff4f44726ee13d010d460231f9b787
VolkovMaxim/max
/otadob2.py
174
3.78125
4
q = int(input()) w = int(input()) if q < w: for i in range(q, w + 1): print(i, end=' ') else: for i in range(q, w - 1, -1): print(i, end=' ')
cf41bab17bb8c8688c3514e7d6b5e1b5a6739682
MedAymenF/42AI-Python-bootcamp
/module02/ex05/TinyStatistician.py
1,009
3.546875
4
from math import sqrt class TinyStatistician: def mean(self, x): if x == []: return None mean = 0 for dim in x: mean += dim return (mean / len(x)) def median(self, x): if x == []: return None x.sort() return float(x[(...
31d5f290410a3c53f94dbc12e3d8b7779e4aad24
amudalalalith/PythonTraining
/MethodsDefinition.py
2,041
3.859375
4
#local variable and global variable global sum2 sum2 = 800 def total(a,b,c,d,e): global sum1 sum1 = a + b + c + d + e print (sum1, " from total") sum2 = 600 print (sum2, "sum 2") def average(name): print (sum1, " from average") avg = sum1 / 5 print ("average mark of {...
abd37585ca83f5bf2ac48ebd6eabaf5b02b8dc3e
amudalalalith/PythonTraining
/DataStructure_Set.py
603
4.09375
4
english = {"kumar","priya","Ravi","John","Rani"} hindi = {"vijay","John","khan","sharma","priya"} print (english - hindi) # only english print (hindi - english) # only hindi print (english & hindi) # pass in both print (english ^ hindi) # only one subject print (english | hindi) # total studets in the class...
1efc67c18b88fdfcbb5fc5d6838c55cc09780536
lpawluczuk/summar.pl
/Summarizer/my_exceptions.py
289
3.703125
4
class ArgumentParserException(Exception): """ ArgumentParserException to raise when context-dependent required argument is not present. """ def __init__(self, value): self.value = value def __str__(self): return "This argument is required: " + repr(self.value)
71e6a41c51d36e86242d449117092ab6338f9b51
CihanKeles/ACM114_Sec2
/Week6/turtle_exp_4.py
434
3.9375
4
from turtle import * space = Screen() ali = Turtle() START_X = -200 # Starting X coordinate START_Y = 0 # Starting Y coordinate NUM_LINES = 36 # Number of lines to draw LINE_LENGTH = 400 # Length of each line ANGLE = 170 # Angle to turn ali.hideturtle() ali.penup() ali.goto(S...
da177ce8879d81b558144db5e610aa12fe8602af
CihanKeles/ACM114_Sec2
/Week7/ceaser_chipher_1.py
644
3.9375
4
# we need 2 helper mappings, from letters to ints and the inverse L2I = dict(zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ",range(26))) I2L = dict(zip(range(26),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")) key = int(input("Enter key for encryption: ")) plaintext = input("Enter text you would like to cipher: ") # encipher ciphertext = ""...
9c28731fa28a99508ab91a41169ab8998fd9eb4d
CihanKeles/ACM114_Sec2
/Week7/prog_exp_7.py
414
3.6875
4
sentence = input("Enter a sentence: ").upper() #create two lists vowels = ['A','E',"I", "O", "U"] num = [0,0,0,0,0] #loop through every char for i in range(len(sentence)): #for every char, loop through vowels for v in range(len(vowels)): #if char matches vowels, increase num if sentence[i] == vow...
b504f63cabe4ac1ad9f493410378566fda23f66b
CihanKeles/ACM114_Sec2
/Week6/nested_for_exp.py
614
4.1875
4
num_students = int(input('How many students do you have? ')) num_test_scores = int(input('How many test scores per student? ')) for student in range(num_students): total = 0.0 print('Student number', student + 1) print('-----------------') for test_num in range(num_test_scores): print('Te...
799fcd9e6c1b9ad2b4f8bd37dcb14989a808bb59
CihanKeles/ACM114_Sec2
/Week14/ACM114_Quiz_Week13_solution.py
864
4.125
4
import random # The main function. def main(): # Initialize an empty dictionary. number_dict = dict() # Repeat 100 times. for i in range(100): # Generate a random number between 1 and 9. random_number = random.randint(1, 9) # Establish or increment the number in ...
fc2d4d71c8ad22c3d55554c69cc7985b75d33eca
Stasnnm/dz1
/Lesson2/2.py
174
4.09375
4
print('Please enter an integer number:') x = int(input()) print('The next number for the number', x, 'is', x + 1 ) print('The previous number for the number', x, 'is', x-1 )
5e975a59adacb8c80c37bfc17f582b405d26cc6b
lmrreddy/lekhana
/p1.py
98
3.984375
4
a=int(input("enter the value of a")) if a<0: print(a,"is negitive") else: print(a,"is positive")
ee4e5c9279877fc2b28b6f2801ddb06941cc4220
lmrreddy/lekhana
/p11.py
792
4.0625
4
import random print("lets play the game") def computer(): number=random.randint(1,3) if (computer == 0): computer = "Rock"; elif (computer == 1): computer = "Paper"; elif (computer == 2): computer = "Scissors"; player=int(input("enter 1 for rock,2 for paper,3 for scissors")) if player==computer: print("Tie!") e...
0294bf4f832930284cc7f81221a8b5d2c467718f
zzz136454872/leetcode
/complexNumberMultiply.py
521
3.59375
4
class Solution: def complexNumberMultiply(self, num1: str, num2: str) -> str: def s2n(s): s = s.split('+') s[0] = int(s[0]) s[1] = int(s[1][:-1]) return s num1 = s2n(num1) num2 = s2n(num2) return str(num1[0] * num2[0] - num1[1] * num...
4299fda14e6fc8b7b023bc21e5472ededa8edb2c
zzz136454872/leetcode
/flipgame.py
472
3.546875
4
from typing import List class Solution: def flipgame(self, fronts: List[int], backs: List[int]) -> int: ban = set() for i in range(len(fronts)): if fronts[i] == backs[i]: ban.add(fronts[i]) tmp = sorted(fronts + backs) for num in tmp: if nu...
1d036c0439651a90304f8f7e458d925a91cddd4b
zzz136454872/leetcode
/frequencySort.py
467
3.8125
4
from typing import List class Solution: def frequencySort(self, nums: List[int]) -> List[int]: mem = {} for num in nums: mem[num] = mem.get(num, 0) + 1 out = [] for item in sorted(list(mem.items()), key=lambda x: (x[1], -x[0])): out += [item[0]] * item[1] ...
af1a18415e72570a5317d96e3ea5f84ee2291038
zzz136454872/leetcode
/Twitter.py
1,908
3.90625
4
from typing import * class Twitter: def __init__(self): """ Initialize your data structure here. """ self.log=[] self.f={} def postTweet(self, userId: int, tweetId: int) -> None: """ Compose a new tweet. """ self.log.append((userId,twee...
821862544f383435c5df514b3984c1c0f5f21bb9
zzz136454872/leetcode
/isRobotBounded.py
568
3.546875
4
from typing import List class Solution: def isRobotBounded(self, instructions: str) -> bool: loc = [0, 0] p = 0 m = [(0, 1), (1, 0), (0, -1), (-1, 0)] for c in instructions: if c == "G": loc[0] += m[p][0] loc[1] += m[p][1] el...
6fd7a314051767e44d893bb25c05864125488046
zzz136454872/leetcode
/updateMatrix.py
1,813
3.59375
4
from typing import * class Solution: def update(self): while len(self.queue)>0: i=self.queue[0][0] j=self.queue[0][1] del(self.queue[0]) if i>0: if self.matrix[i-1][j]>self.matrix[i][j]+1: self.matrix[i-1][j]=self.matrix[i]...
a640b71806ce273fe1ef7f3a5754aba9d71af043
zzz136454872/leetcode
/validPath.py
737
3.671875
4
from typing import List class Solution: def validPath(self, n: int, edges: List[List[int]], source: int, destination: int) -> bool: mem = [i for i in range(n)] def find(a): if mem[a] == a: return a return find(mem[a]) def union(a...
d575136fd0d5d1da668fe9704eb73725abfafc17
zzz136454872/leetcode
/maxAbsoluteSum.py
528
3.515625
4
from typing import List class Solution: def maxAbsoluteSum(self, nums: List[int]) -> int: s1 = 0 s2 = 0 res = 0 for num in nums: s1 += num if s1 < 0: s1 = 0 else: res = max(s1, res) s2 += num ...
62dc36aca9d09bf21362102125fad5f93c4a4ef0
zzz136454872/leetcode
/postorder.py
522
3.578125
4
from typing import List class Node: def __init__(self, val=None, children=None): self.val = val self.children = children class Solution: def postorder(self, root: 'Node') -> List[int]: out = [] def po(root): if root is None: return i...
1054af00debdd67294e93dd3e76c26ed36d94766
zzz136454872/leetcode
/merge.py
1,317
3.546875
4
from typing import List # 56. 合并区间 class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: intervals.sort(key=lambda x: x[0]) i = 0 res = [intervals[0]] for i in range(1, len(intervals)): if intervals[i][0] > res[-1][1]: res.appe...
4c93ee03991d41dcca7edcbbd0d20539987aae09
zzz136454872/leetcode
/removeSubfolders.py
703
3.75
4
from typing import List class Solution: def removeSubfolders(self, folder: List[str]) -> List[str]: folder.sort() flags = [True for i in range(len(folder))] prev = 0 for i in range(1, len(folder)): if folder[i][:len(folder[prev])] == folder[prev] and \ ...
9974305b12572877fe904e0621e9f029bcc79f52
zzz136454872/leetcode
/findOcurrences.py
523
3.703125
4
from typing import List class Solution: def findOcurrences(self, text: str, first: str, second: str) -> List[str]: text = text.split() out = [] for i in range(2, len(text)): if text[i - 2] == first and text[i - 1] == second: out.append(text[i]) return ...
82c53a012f6f19324efd414413e0866c84d337a2
zzz136454872/leetcode
/areNumbersAscending.py
410
3.578125
4
from typing import List class Solution: def areNumbersAscending(self, s: str) -> bool: s = s.split() pre = -1 for token in s: if token[0].isdigit(): token = int(token) if token <= pre: return False pre = toke...
5fc584501d1962da2d406559362fd25344fb9aa0
zzz136454872/leetcode
/addDigits.py
359
3.90625
4
from typing import List class Solution: def addDigits(self, num: int) -> int: def wash(a): tmp = 0 while a > 0: tmp += a % 10 a = a // 10 return tmp while num >= 10: num = wash(num) return num num = 38 nu...
6d94b2ca4d43affb1a8e9e905375a4d408cb01c1
zzz136454872/leetcode
/sortArrayByParity.py
369
3.9375
4
from typing import List class Solution: def sortArrayByParity(self, nums: List[int]) -> List[int]: even = [] odd = [] for num in nums: if num % 2 == 0: even.append(num) else: odd.append(num) return even + odd nums = [3, 1,...
5908b93faa56f5fa277fb33330c3ecbe138746a6
zzz136454872/leetcode
/visiblePoints.py
1,244
3.59375
4
from math import acos, pi from typing import List class Solution: def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int: mem = [] always = 0 eps = 10**(-8) for p in points: dy = p[1] - location[1] dx ...
07100da452d2c0fb249d1255b426bc9951b71043
zzz136454872/leetcode
/isRectangleCover.py
1,615
3.703125
4
from typing import List class Solution: def isRectangleCover(self, rectangles: List[List[int]]) -> bool: def area(rec): return (rec[3] - rec[1]) * (rec[2] - rec[0]) nodes = {} totalArea = 0 for rec in rectangles: nodes[(rec[0], rec[1])] = nodes.get((rec[0]...
a127fc17af4860ec2ad7372f83e078188d2cf00f
zzz136454872/leetcode
/maxDistToClosest.py
814
3.5
4
from typing import List class Solution: def maxDistToClosest(self, seats: List[int]) -> int: mem = [] left = -1 right = -1 for i in range(len(seats)): if seats[i] == 1: left = i break for i in range(len(seats) - 1, -1, -1): ...
040eb5e95cdd2d4845ba9e7b13a4c2b50eea1d7d
zzz136454872/leetcode
/numEnclaves.py
1,907
3.703125
4
from typing import List class Solution: def numEnclaves(self, grid: List[List[int]]) -> int: m = len(grid) n = len(grid[0]) # for i in range(m): # for j in range(n): # print(grid[i][j],end=' ') # print() def check(x, y): if x < 0...
15e5dd2468637c68bf42f1d4ed7fceeecd54fe20
zzz136454872/leetcode
/longestArithSeqLength.py
761
3.65625
4
from typing import List class Solution: def longestArithSeqLength(self, nums: List[int]) -> int: mem = {} for num in nums: if num not in mem: mem[num] = {} for delta in range(-500, 501): if delta == 0: mem[num][0] = mem[...
aeb0eacbf02538bcf96457416a96fd0cad742284
zzz136454872/leetcode
/Skiplist.py
2,124
3.59375
4
from typing import * from random import randint class SkipListNode: def init(self,val,level,maxLevel): self.val=val self.count==1 self.level=level self.next=[None]*(maxLevel-level) class Skiplist: def __init__(self): self.maxLevel=13 self.head=SkipListNode(-1,0,...
abaf7cd1d03535cd2a9a4951f817814c8223b77f
zzz136454872/leetcode
/maximalNetworkRank.py
578
3.65625
4
from typing import List class Solution: def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int: adj = [set() for i in range(n)] for i in range(len(roads)): adj[roads[i][0]].add(i) adj[roads[i][1]].add(i) res = 0 for i in range(n): ...
dac804c33230879d67dd611d93deb94b2adc451b
zzz136454872/leetcode
/sumRootToLeaf.py
534
3.515625
4
from typing import Optional from pytree import TreeNode class Solution: def sumRootToLeaf(self, root: Optional[TreeNode]) -> int: value = 0 res = 0 def dfs(root, value): if not root: return value = 2 * value + root.val if not root.left...
8d7a5ef6c6b49e0516c926e8fb24b449f6138851
zzz136454872/leetcode
/createBinaryTree.py
1,036
3.71875
4
# Definition for a binary tree node. from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def createBinaryTree(self, descriptions: List[List[int]...
f10e5251417fee9b9801a327c0bbd7af4c1b4cdf
zzz136454872/leetcode
/reverseBetween.py
723
3.609375
4
from typing import * from pylist import * class Solution: def reverseBetween(self, head: ListNode, left: int, right: int) -> ListNode: p=ListNode(-1) new_head=p p.next=head for i in range(left-1): p=p.next q=p.next pre=p r=q.next for i in ...
d1acd0177f3091cf47d5520c6cca5e070a0ec329
zzz136454872/leetcode
/prefixCount.py
419
3.53125
4
from typing import List class Solution: def prefixCount(self, words: List[str], pref: str) -> int: res = 0 n = len(pref) for word in words: if word[:n] == pref: res += 1 return res words = ["pay", "attention", "practice", "attend"] pref = "at" words ...
67cb9f6d0741d7e7c8a745216b17d4274e2683f8
zzz136454872/leetcode
/countStudents.py
521
3.65625
4
from typing import List class Solution: def countStudents(self, students: List[int], sandwiches: List[int]) -> int: mem = [0] * 2 for s in students: mem[s] += 1 for sandwich in sandwiches: mem[sandwich] -= 1 if mem[sandwich] < 0: retur...
08b1cc9b48c094ef51afd613c3f9fff5a6fdeafb
zzz136454872/leetcode
/twoSum.py
1,244
3.578125
4
from typing import List # 不知道是哪个 class Solution1: def twoSum(self, nums: List[int], target: int) -> List[int]: nums = sorted([(nums[i], i) for i in range(len(nums))]) i = 0 j = len(nums) - 1 while i < j: a = nums[i][0] + nums[j][0] if a == target: ...
594422fb53b4ab7d8965e1680fc16a5f5cf731d3
zzz136454872/leetcode
/applyOperations.py
497
3.5625
4
from typing import List class Solution: def applyOperations(self, nums: List[int]) -> List[int]: for i in range(len(nums) - 1): if nums[i] == nums[i + 1]: nums[i] *= 2 nums[i + 1] = 0 n1 = [] n2 = 0 for num in nums: if num !...
6b5ce29f73617cc8350c06f69fa0592ce8b9ecc5
zzz136454872/leetcode
/pivotArray.py
502
3.890625
4
from typing import List class Solution: def pivotArray(self, nums: List[int], pivot: int) -> List[int]: n1 = [] n2 = [] n3 = [] for num in nums: if num < pivot: n1.append(num) elif num == pivot: n2.append(num) els...
59c391debc8151ba9a022f5a51fc3f6f5db444b7
zzz136454872/leetcode
/dominantIndex.py
484
3.609375
4
from typing import List class Solution: def dominantIndex(self, nums: List[int]) -> int: m1 = 0 l1 = -1 m2 = 0 for i in range(len(nums)): if nums[i] > m1: m1, m2 = nums[i], m1 l1 = i elif nums[i] > m2: m2 = nu...
01ca265d1250477e7af35d72421eb8eb10098b95
zzz136454872/leetcode
/RLEIterator.py
713
3.59375
4
from typing import * class Node: def __init__(self): self.count=10**15 self.next=None self.num=-1 class RLEIterator: def __init__(self, A: List[int]): self.head=None self.tail=None for i in range(0,len(A),2): p=Node() p.count=A[i] ...
ce2c5a9e3c044a5bc268ec73433f7f7e1920f059
zzz136454872/leetcode
/halvesAreAlike.py
443
3.6875
4
class Solution: def halvesAreAlike(self, s: str) -> bool: mem = ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U') n = len(s) l0 = 0 l1 = 0 for letter in s[:n // 2]: if letter in mem: l0 += 1 for letter in s[n // 2:]: if lette...
16fa60faec6d4bb6ccd8ec214073e96b13585715
zzz136454872/leetcode
/isSumEqual.py
689
3.59375
4
from typing import * class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: def l2n(a): return str(ord(a)-ord('a')) def trans(word): out='' for letter in word: out+=l2n(letter) return i...
ff7b8bba52c9a265f8fe21332ba2deb1ceab9219
zzz136454872/leetcode
/minOperationsMaxProfit.py
1,177
3.515625
4
from typing import List class Solution: def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int: maxTime = -1 maxValue = 0 time = 0 value = 0 waiting = 0 for customer in customers: ...
00b7ff93519b2713261934a5ae68056642df1bc3
zzz136454872/leetcode
/simplifyPath.py
589
3.6875
4
class Solution: def simplifyPath(self, path: str) -> str: tmp = [] path = path.split('/') for p in path: if p == '' or p == '.': continue if p == '..': if len(tmp) > 0: tmp.pop() continue ...
40fc59df6cb00f7915c99f625a78f09a1006cfa6
zzz136454872/leetcode
/mergeAlternately.py
454
3.78125
4
from typing import * class Solution: def mergeAlternately(self, word1: str, word2: str) -> str: out = '' while word1 or word2: if word1: out += word1[0] word1 = word1[1:] if word2: out += word2[0] word2 = wor...
ad5667e7ea6c51e19a2485da7d5881c032fa7a40
zzz136454872/leetcode
/checkXMatrix.py
583
3.734375
4
from typing import List class Solution: def checkXMatrix(self, grid: List[List[int]]) -> bool: m = len(grid) n = m - 1 for i in range(m): for j in range(m): if i == j or i + j == n: if grid[i][j] == 0: return False ...
72e23baf423e0af57c32144dd3d9ae0de0c59da4
zzz136454872/leetcode
/arithmeticTriplets.py
566
3.5
4
from typing import List class Solution: def arithmeticTriplets(self, nums: List[int], diff: int) -> int: n = len(nums) res = 0 for i in range(n - 2): for j in range(i + 1, n - 1): if nums[j] - nums[i] != diff: continue for k...
25ef04b0cb74450aa763848fde759de3e02141f1
zzz136454872/leetcode
/numSubarrayBoundedMax.py
767
3.5
4
from typing import List class Solution: def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int: last1 = -1 last2 = -1 res = 0 for i in range(len(nums)): if left <= nums[i] and nums[i] <= right: last...
c2d1494037df60ae68365e26d211e62eee2a51d0
zzz136454872/leetcode
/multiply.py
1,683
3.53125
4
from typing import * # 不知道是哪个 def add(a, b): out = [] carry = 0 for i in range(max(len(a), len(b))): tmp = carry if i < len(a): tmp += a[i] if i < len(b): tmp += b[i] carry = tmp // 10 tmp = tmp % 10 out.append(tmp) if carry =...
31893dc83a5faa4b953aca452de5594284e3787c
zzz136454872/leetcode
/detectCapitalUse.py
648
3.796875
4
class Solution: def detectCapitalUse(self, word: str) -> bool: allUp = False firstUp = False if len(word) < 2: return True if word[0].isupper(): firstUp = True if word[1].isupper(): if not firstUp: return False ...
83fa2d9002dd6053e536857eb70bfff3ed2f9f28
zzz136454872/leetcode
/expressiveWords.py
1,046
3.578125
4
from typing import List class Solution: def expressiveWords(self, s: str, words: List[str]) -> int: def count(a): out = [] prev = '' cnt = 0 for i in range(len(a)): if a[i] == prev: cnt += 1 else: ...
75577be611afed6992e1ce127f6d1eb536554eea
zzz136454872/leetcode
/accountsMerge.py
1,464
3.671875
4
from typing import * class Solution: def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]: logs={} class AC(): def __init__(self): self.name=None self.emails=set() for account in accounts: a=set() for emai...
0eee56410066916e7190dcff6c4e86f91cc703f0
zzz136454872/leetcode
/longestStrChain.py
866
3.578125
4
from typing import List def isFront(a, b): if len(a) != len(b) - 1: return False i = 0 for i in range(len(a)): if a[i] != b[i]: for j in range(i, len(a)): if a[j] != b[j + 1]: return False break return True class Solution...
040641be580c4db999f5488b2dc2dd9526e190eb
zzz136454872/leetcode
/findDuplicateSubtrees.py
909
3.515625
4
from typing import List, Optional from pytree import TreeNode class Solution: def findDuplicateSubtrees( self, root: Optional[TreeNode]) -> List[Optional[TreeNode]]: seen = set() inRes = set() res = [] def toString(root): if root is None: r...
532ce5c72b1eb272e42e96eba63217d47acb9772
matteo-conti-97/Sorting-alghoritms
/MidTermProject/project_test_plot/quickSelectRand.py
588
3.53125
4
from quickSort import partition def quickSelectRand(l, k): # k 1...n if k <= 0 or k > len(l): return None return recursiveQuickSelectRand(l, 0, len(l) - 1, k) def recursiveQuickSelectRand(l, left, right, k): if left > right: # controllo superfluo return if left == right and k - 1 ...
89d44c6bbfbd500084e101bd9f90ea0325bdd06d
matteo-conti-97/Sorting-alghoritms
/MidTermProject/project_test_plot/BubbleSort.py
333
4
4
def bubbleSort(list): swap=True while swap: swap=False for j in range(len(list) - 1): if list[j] > list[j + 1]: #list[j], list[j + 1] = l[j + 1], l[j] v=list[j] list[j]=list[j+1] list[j+1]=v swap=True ...
8417052067b909137226a068771052256e9c3990
kkrawczyk5/Module-10---Final-Game
/Cave Adventure FINAL VERSION.py
8,497
4
4
#Name: Kamil Krawczyk #University: National-Louis University #Contact: kkrawczyk@my.nl.edu #Course: CSS 225 Winter semester #Language: Python3 #Name of game: Cave Adventure #Version: Final version of game #Type of game: Text based import random def intro_screen(main): print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
f60a5bae19673fbe84e275de2a8d79cb23cce350
swarupmishal/mishal_swarup_spring2017
/Assignment 3/Q3_Part_1.py
1,796
3.921875
4
# coding: utf-8 # # Q3_PART ONE # - Use ‘cricket_matches’ data set. # - Calculate the average score for each team which host the game and win the game. # - Remember that if a team hosts a game and wins the game, their score can be innings_1 runs or innings_2 runs. You have to check if the host team won the game, chec...
e49ce799eeb1f4e10ecd66a6da68d160a1ae1cf8
nyczpete/senior-research
/application2.py
3,526
3.5625
4
# # Senior Research Project Part 2 # Tan Dung Luong # Suntae Park # from midi import * from music import * from gui import * import random from datetime import * # create midi input midiIn = MidiIn() # create display display = Display("MIDI App - Senior Research", 1500, 1000, 0, 0, Color.white) ...
b0b91399237afcfe69a0b2c78428f139f658950f
tanngo1605/ProblemSet1
/problem5/solution.py
583
4.1875
4
#This is a really cool example of using closures to store data. # We must look at the signature type of cons to retrieve its first and last elements. cons takes in a and b, and returns a new anonymous function, which itself takes in f, and calls f with a and b. So the input to car and cdr is that anonymous function, ...
0e163e4b1e801b3d93f999cc0f3d8599b8b5ae8c
ben-cooper/Mini-Projects
/Random/binary converter.py
4,285
4.25
4
''' Ben's Binary Converter Version Info: 1.1 beta This program is designed to encrypt and decrypt messages to and from binary with a GUI in tkinter. Copyright (c) Ben Cooper 2013 Designed in PyScipter for python 3.3.2 and written according to PEP8 ''' from tkinter import * from tkinter.ttk import * de...
e1b035598cc6bc6383e35874364e8089f3603a98
Umanggala/NLP-Chatbot-1
/test.py
713
3.96875
4
text = 'Cheap Restraunts in Marina Del Ray.' #Prepare your text. Remove "." (and other unnecessary marks). #Then split it into a list of words. text = text.replace('.','').split(' ') #Insert the cities you want to search for. cities = {"Los Angeles":["Los","Angeles"],"Santa Monica":["Santa","Monica"],"Marina Del Ray"...
7a8c1fcb35d0c2e452aa8d841c9d427472e6c2aa
johnashu/Object-Oriented-Programming
/living_things.py
3,581
3.9375
4
class LivingThing: def __init__(self, name, legs, age, health): self.name = name self.legs = legs self.age = age self.health = health self.hunger = 0 def DamageHealth(self, dmgAmount): self.health = self.health - dmgAmount if self.health == 0: ...
1b9b4ee6bf372a9ac44a33acee48996b4a595438
EduRibeiro00/hashcode-training
/2015/algs/hill_climbing.py
476
3.546875
4
from state import State def hill_climbing(init_state, num_its): state = init_state best_value = state.getValue() for _ in range(num_its): # create generator that yields all state neighbors neighbours = state.genAllNeighbors() for neighbour in neighbours: # new best neig...
108a5d1d620c9f35fd4313675bc35187c5679183
EduRibeiro00/hashcode-training
/practice/algs/hill_climbing.py
2,059
4.09375
4
from ..state import State def hill_climbing(init_state: State, num_its: int): """Regular hill climbing algorithm.""" state = init_state for _ in range(num_its): # create generator that yields all state neighbors old_state = state neighbours = state.get_all_neighbours(generator=True...
0f9544217d43d0c5ffeb6be1d93d2e33ef345bd0
tutunamayanlar2021/Python
/tuple.py
324
4.21875
4
tuple =(1,"iki",3) list=[1,2,"kader"] print(type(tuple)) print(type(list)) print(len(tuple)) list=["ali","veli"] #güncelleme # tuple=["sena","polo"] list[0]="ahmet" #degitirebiliyoruz #tuple[0]=2 #degiştirilemez print(tuple.count(1)) names=("nobody","who") +tuple #toplma işlemi yapılabiliyor print(list) print(names)
24c3d30472fa0fb9cfe9d8f018b4e39dfb3592da
tutunamayanlar2021/Python
/list_methods_Exsample.py
1,086
4.46875
4
names=["Ali","yağmur","hakan","Deniz"] years= [1998,2000,1998,1987] # "cenk"ismini listenin sonuna ekleyin names.append("Cenk") #"sena"ismini listenin basına ekleyin names.insert(0,"Sena") #'deniz'ismini listeden siliniz #names.remove("deniz") # index=names.index("Deniz") # print(index) # names.pop(index) # print(names...
5a830eb25ff9411d7390a9e115b36a7c20481e24
tutunamayanlar2021/Python
/referance.py
365
4.15625
4
#value types=>string,number # deger tuttugu için atamadan sonra yapılan degişiklik # sadece yapılanı degiştirir.adresler aynı degil. x=10 y=25 x=y y=30 #print(x,y) #referance =>list,class #Since the addresses are the same, they both change after assignment a=["apple","banana"] b=["apple",...
a779f395d0ce828ebf1cedd0a0c5208291c72333
tutunamayanlar2021/Python
/arguments.py
945
3.640625
4
# def changeName(n): # n="Kader" # name ="mustafa" # changeName(name) # print(name) # def change(n): # n[0]="istunbul" # sehirler=["ankara","izmir"] # # n =sehirler[:] #kopyalama # change(sehirler[:]) # print(sehirler) # def add(a,b,c=0):#c belirtilmediği zamna iki deger calısır # return sum((a,b,c))...
13831fa2b64902b323fdcdcce745590f02367845
writerlab/pbo_rpl3
/tugas_ranger_3/2_renaldy.py
2,374
3.609375
4
import os def loopsimbol(jenismenu): for x in range (20): print(jenismenu, end = '') print('') while True: print('--___--operasi file__--__') print('1. buat file') print('2. isi file') print('3. baca file') print('4. hapus file') print('5. tambahkan isi file'...
31970bb9e94dfd4447f8836bae253cecb6246d9d
writerlab/pbo_rpl3
/tugas_ranger_2/22_rev.py
1,138
3.75
4
while True: print ("----MENU----") print ("1.RAMEN BEEF") print ("2.RAMEN CHICKEN KATSU") print ("3.PAKET HEMAT 1") print ("4.PAKET HEMAT 2") print ("SELESAI") menu = int(input('PILIH NOMOR[1/2/3/4/5]')) if menu ==1: print ("----------HARGA----------") print...