blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
b17c89c64b5950547cb54d3be4c68ce0b0a1fc23
koilhyuk/Algorithm
/src/baekjoon/bronze/winningScore_1_17009.py
335
3.703125
4
fg = True a=0 b=0 score = 3 for i in range(6): c=int(input()) if fg: a+= c*score else: b += c*score score -= 1 if i == 2: fg = False score = 3 elif i == 5: if a>b: print('A') elif a<b: print('B') else: ...
4f6f16012d866ca2fd9480de8d4cd4eb3c4b3021
koilhyuk/Algorithm
/src/baekjoon/bronze/telemarkerter_1_16017.py
121
3.59375
4
a,b,c,d = int(input()),int(input()),int(input()),int(input()) print("ignore" if a >= 8 and d >=8 and b==c else "answer")
a4719608e1eb70a3da1f5a5bfb23a944d6b1fa90
koilhyuk/Algorithm
/src/baekjoon/bronze/ovenTime_1_2525.py
228
3.5
4
hr, mt = map(int, input().split()) cooking = int(input()) totalMin =mt + cooking if totalMin >=60: hr+=totalMin//60 mt = totalMin%60 if hr > 23: hr -=24 else: mt=totalMin print(str(hr)+" "+str(mt))
c904b236955c6ba88cf9d0533acf38f52898a722
koilhyuk/Algorithm
/src/baekjoon/bronze/haknum_1_2754.py
348
3.625
4
score = input() result =0 if score[:1] == "A": result+=4 elif score[:1] == "B": result+=3 elif score[:1] == "C": result+=2 elif score[:1] == "D": result+=1 else: result+=0.0 if score[1:] =="+": result+=0.3 elif score[1:] =="0": result+=0.0 elif score[1:] =="-": result-=0.3 else: ...
5f62ab76012a45f81fef0302a410061157346193
guptamehak1524/Artificial-Intelligence-Survey
/a1/a1.py
9,786
3.65625
4
# ASSIGNMENT 1 # MEHAK GUPTA # 301311972 # a1.py import random import time from search import * #QUESTION 1 eight_puzzle_temp = EightPuzzle((1,2,3,4,5,6,7,8,0)) def make_rand_8puzzle(): x = [1, 2, 3, 4, 5, 6, 7, 8, 0] new_state = random.sample(x, len(x)) while new_state: if eight_puzzle_temp.check_solvability(t...
30184636298ae65fa0afee89f47db361d586cebb
raytraina/30-days_hacker-rank
/day1_data-types.py
1,224
4.125
4
# Day 1: Data Types # Task: Complete the code in the editor below. The variables , , and are already declared and initialized for you. You must: # Declare variables: one of type int, one of type double, and one of type String. # Read lines of input from stdin (according to the sequence given in the Input For...
fdf1275f101e23982abcdb582ac893f5d8392c99
raytraina/30-days_hacker-rank
/day20_sorting.py
504
3.796875
4
# Day 20: Sorting # Task: Implement bubble sort. #!/bin/python import sys n = int(raw_input().strip()) a = map(int,raw_input().strip().split(' ')) numberOfSwaps = 0 for index in range(n): jindex = index + 1 while jindex < range(len(a)): if a[jindex] > a[jindex + 1]: a[jindex], a[jindex ...
77a04e9e35d153f3150263dae344fd7e4c46f91a
muskangupta423/guvi_pos_neg
/factorial.py
114
4.21875
4
n=int(input("Enter the number")) fact=1 for i in range(1,n+1): fact=fact*i print("factorial of a number is",fact)
48fcfecc69f5c8759b3f3e42d1d099ab29e4f41f
rtang09/number_math
/numbermath.py
2,117
3.765625
4
def piestimate(acuracy, digits): start = 0 for num in range(1, acuracy, 4): start += 1/num - 1/(num+2) start = start*4 return float(str(round(start, digits+1))[:digits+2]) def estimate_e(acuricy, digits): answer = ((acuricy+1)/acuricy)**acuricy return float(str(round(answer, digi...
2fafa018a22cc3a0811bfc3b90fe4fb787f215cf
destiny27boone/python-workspace2
/loopsDebug2/loopsDebug2.py
1,615
4.0625
4
''' Created on Mar 11, 2021 @author: ''' ''' This function uses a while loop to print out every number from 1 to 100. ''' def counting(): x = 0 while x <= 100: print(x) x = x + 1 print("DONE") return counting() ''' This function takes a list of fruits and prints out each fruit in the li...
878b936293a8fadfdf9fe32910b30bff261d9d14
destiny27boone/python-workspace2
/Mathematical operators/mathOutline.py
1,272
4.28125
4
''' This outline will help solidify concepts from the Mathematical Operators lesson. Fill in this outline as the instructor goes through the lesson. ''' #1) Make two string variables and use the + operator to combine them into #one new variable. #2) Make two int variables and use the + operator to combine them into...
eb51d2c8466279e642ef036696d082a974c584a4
wwwser11/prj2
/password_access.py
2,014
3.5625
4
from time import sleep from string import digits, ascii_lowercase f = open('easypasswords.txt', 'r') class User: def __init__(self, login, password): self.login = login self.password = password @property def password(self): print('getter') return self.__password @sta...
17e30dff18eed6da9e5f0466c2cbd76fc55a1f4e
Greenokorohmichelle/-python_user_data_validation
/userval.py
1,331
3.984375
4
from random import sample import string def capture_user_data(): # ask for the user details first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") email = input("Enter your email address: ") # generate password random_token = "".join(sample(string.ascii_lett...
3c8c7023f126da3118bfc417b09643041ca34bbb
jessie-JNing/Algorithms_Python
/Data_Structures/Tree_Graph/Tree_Value_Path.py
269
3.515625
4
#!/usr/bin/env python # encoding: utf-8 """ Given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum to a given value. The path does not need to start or end at the root or a leaf. @author: Jessie @email: jessie.JNing@gmail.com """
f988a405c7a5e25fd61c8955866ae623689737c9
jessie-JNing/Algorithms_Python
/Data_Structures/Bit_Manipulation/Swap_odd_even.py
549
4.125
4
#!/usr/bin/env python # encoding: utf-8 """ Swap odd and even bits in a integer with as few instructions as possible. (e.g. bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped ...) Hexadecimal 0xAA --> 10101010 --> keep even bits 0x55 --> 01010101 --> keep odd bits 0xAAAAAAAA for 32 bits...
ed6015cc3a19f4f677f73b3b3606b0bb28cb005e
jessie-JNing/Algorithms_Python
/Data_Structures/Hash_Table/Hash_Map.py
5,001
3.671875
4
#!/usr/bin/env python # encoding: utf-8 """ Data structure maps the key and correspoding value, implemented by array (linkedlist) and hash function. Hash function: remainder, fold method, mid-square method. Collision: two or more items come to the same slot. Collition solutions: open addressing (linear probing, qu...
09e7ba61c7bfdb2534ae2f4a798c682561b0c9d1
jessie-JNing/Algorithms_Python
/island_finding.py
984
3.734375
4
#!/usr/bin/env python # encoding: utf-8 """ @author: Jessie @email: jessie.JNing@gmail.com """ def update_map(map, island_list): new_map = [] for node in island_list: island = _update_map(map, node, []) new_map.extend(island) for i in range(len(map)): for j in range(len(map[0]))...
380f6c2ff00280464bc0adb767b58591c08874cb
jessie-JNing/Algorithms_Python
/Data_Structures/Linked_List/Linked_Palindrome.py
1,397
3.796875
4
#!/usr/bin/env python # encoding: utf-8 """ @author: Jessie @email: jessie.JNing@gmail.com """ class Node: def __init__(self,initdata): self.data = initdata self.next = None # use extra space def check_palindrome(head): if head is None: return False refer_list = [] current...
a7cf34045a8afa404d3e606c9829887876026e72
jessie-JNing/Algorithms_Python
/Data_Structures/Stack/Set_of_Stacks.py
1,966
3.71875
4
#!/usr/bin/env python # encoding: utf-8 """ @author: Jessie @email: jessie.JNing@gmail.com """ class Stack(object): def __init__(self): self.items = [] def isEmpty(self): return len(self.items) == 0 def push(self, item): self.items.append(item) def pop(self): if se...
62cc43ec9de24b4781f1a38b67715a3629374c54
jessie-JNing/Algorithms_Python
/Data_Structures/Tree_Graph/Graph_Traverse.py
2,690
3.765625
4
#!/usr/bin/env python # encoding: utf-8 """ @author: Jessie @email: jessie.JNing@gmail.com """ from Data_Structures.Stack.Stack import Stack from Data_Structures.Queue.Queue import Queue from Graph import Vertex from Graph import Graph def breadth_first_search(graph, root): if graph is None: return Non...
37b0da7ce28e0525480b2fa56f0df83689481aed
jessie-JNing/Algorithms_Python
/Data_Structures/Stack/Stack_Sort.py
3,568
3.859375
4
#!/usr/bin/env python # encoding: utf-8 """ @author: Jessie @email: jessie.JNing@gmail.com """ # need modify class Stack(object): def __init__(self): self.items = [] def isEmpty(self): return len(self.items) == 0 def push(self, item): self.items.append(item) def pop(self):...
afacf9d2346b98c343223062c62a1f785ca67b57
paola-rodrigues/Lista_Python_02
/questão_17.py
625
4
4
#Questão 17 ''' Faça um programa que calcule e mostre a area de um trapézio ''' base_maior = float(input("Digite a base maior do trapézio: ")) base_menor = float(input("Digite a base menor do trapézio: ")) altura = float(input("Digite a altura do trapézio: ")) if int(base_maior) > 0 and int(base_menor) > 0 : a...
1a12a686670a67cca1d278cff56e2445a4d0a8fd
paola-rodrigues/Lista_Python_02
/questão_15.py
767
3.765625
4
#Questão 15 ''' Escreva um programa que leia um inteiro entre 1 e 7 e imprima o dia da semana correspondente a este numero. Isto é, domingo se 1, segunda-feira se 2, e assim por diante ''' semana = int(input("Digite a numero inteiro entre 1 e 7: ")) if semana == 1: x = "domingo" elif semana == 2: ...
e1f954250aa8f7104436a5c3caf6d398a612107f
Mrmgnt/python-basic
/belajarPython/merubah_dari_data_ketipe_lain.py
2,042
3.921875
4
#belajar casting #merubah dari satu tipe ke tipe lain #tipe data = int. float str bool #INTEGER print("=====INTEGER=====") data_int = 9 print("data = ", data_int, ",type =",type(data_int)) data_float = float(data_int) data_str = str(data_int) data_bool = bool(data_int) print("data = ", data_float, ",type ...
6101437e0a1e9e9a81742fcd665908fc550920cf
emilycheera/coding-challenges
/find_complement.py
399
4.03125
4
def find_complement(num): # Convert num (int) to binary # Flip each digit in binary num # Convert binary num to int bin_num = bin(num)[2:] flipped_num = "" for digit in bin_num: if digit == "0": flipped_num += "1" else: flip...
e6783c577cc4871c0069755d2678bfa252e2653a
emilycheera/coding-challenges
/merge_lists.py
514
3.953125
4
def merge_lists(my_list, alices_list): # Combine the sorted lists into one large sorted list sorted_list = [] while my_list or alices_list: if not my_list: sorted_list.extend(alices_list) break elif not alices_list: sorted_list.extend(my_list) ...
19f915b2a12f4a7ebdd1f1cc31637d5c8216f660
emilycheera/coding-challenges
/max_increase_keeping_skyline.py
1,101
3.5625
4
def max_increase_keeping_skyline(grid): max_increase = 0 # Visit each building in the grid for i in range(len(grid)): for j in range(len(grid[0])): # Get the max building height in the row max_row = max(grid[i]) # Get the max building height in the column ...
4cb41de3dc08180bf6459b4f97b737c0fd09d7a8
emilycheera/coding-challenges
/group_children.py
361
3.9375
4
def group_children(ages): """Return minimum number of groups such that ages differ by <= 2 years.""" ages.sort() left_age = ages[0] num_groups = 1 for age in ages: if age > left_age + 2: left_age = age num_groups += 1 return num_groups print(gro...
b7a14c413ecbe3290e796d754fabb00b7b3ad2b8
emilycheera/coding-challenges
/instagram_pack.py
859
3.6875
4
"""Determine number of "instagram" packs needed to make a word. >>> instagram_pack("grass") 2 >>> instagram_pack("tagging") 3 >>> instagram_pack("git") 1 >>> instagram_pack("emily") -1 >>> instagram_pack("aaaaa") 3 """ from math import ceil def instagram_pack(word): ...
9d1ab467b0151e1c6e89b9ffcc36bac0aa589bcd
emilycheera/coding-challenges
/dedupe.py
632
4.21875
4
def deduped(items): """Return new list from items with duplicates removed. >>> deduped([1, 1, 1]) [1] >>> deduped([1, 2, 1, 1, 3]) [1, 2, 3] >>> deduped([1, 2, 3]) [1, 2, 3] >>> a = [1, 2, 3] >>> b = deduped(a) >>> a == b True >>> a is b False >>> deduped([]...
c4ff72e97cb7f6855ae3ffae337acb33d30bebad
emilycheera/coding-challenges
/josephus.py
784
3.59375
4
"""Given num_people in circle, kill [kill_every]th person, return survivor. >>> find_survivor(4, 2) 1 >>> find_survivor(41, 3) 31 As a sanity case, if never skip anyone, the last person will be our survivor: >>> find_survivor(10, 1) 10 """ def find_survivor(num_people, kill_every): "...
ac5389dcaa50f8f3683c6a19a9970f66bd56dc19
emilycheera/coding-challenges
/subtract_product_and_sum.py
252
3.796875
4
def subtract_product_and_sum(n): digits = [] while n > 0: digits.append(n % 10) n //= 10 product = 1 for digit in digits: product *= digit return product - sum(digits)
105538c0967b5134d176b120ab32b412d0ea3f05
emilycheera/coding-challenges
/max_sublist.py
206
3.6875
4
max_sublist(nums): current = 0 result = nums[0] for num in nums: current += num result = max(current,result) current = max(0,current) return result
32368c5f1c4db3ef35dacfad3890ef35a0edafcd
emilycheera/coding-challenges
/make_deep_copy_node.py
685
3.75
4
class Node(object): """Node class.""" def __init__(self, value, children): self.value = value self.children = children """Write a function that takes in a node and its children and returns a new node that is a duplicate of that node""" def create_node_copy(node): new_node = Node(node.va...
03d651573a004135eaf068c998312d95b757b3f8
emilycheera/coding-challenges
/hot_potato.py
371
3.796875
4
from collections import deque def hot_potato(people, num): queue = deque() for person in people: queue.appendleft(person) while len(queue) > 1: for _ in range(num - 1): queue.appendleft(queue.pop()) queue.pop() return queue.pop() print(hot_potato(["Roy", "Jenn...
72e1cf35b57f4f3460e482579c097d201881e1eb
emilycheera/coding-challenges
/check_if_can_break.py
544
3.796875
4
"""Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa. A string x can break string y (both of size n) if x[i] >= y[i] for all i between 0 and n-1. """ def check_if_can_break(s1, s2): s1 = sorted(s1) s2 = sort...
cc9ec6a59d7373763ccecd377005494c38fa8345
emilycheera/coding-challenges
/hourglass_sum.py
455
3.703125
4
def hourglass_sum(arr): hourglass_values = [] for i in range(len(arr) - 2): for j in range(len(arr[0]) - 2): current_value= 0 for k in range(3): current_value += arr[j][i + k] current_value += arr[j + 1] [i + 1] for k in range(3): ...
66629095d31ca9ec53856dfb5b62791db5836edb
emilycheera/coding-challenges
/recursive_index.py
799
4.21875
4
def recursive_index(needle, haystack): """Given list (haystack), return index (0-based) of needle in the list. Return None if needle is not in haystack. Do this with recursion. You MAY NOT USE A `for` OR `while` LOOP. >>> recursive_index("hey", ["hey", "there", "you"]) 0 >>> recursive_in...
36770dd91b91dbe53804dc447a60e39c68452106
BackToTheSchool/assignment_js
/1113/hw34.py
657
4
4
class employee() : __next = None __name = "" def _set__next(self,employee): if self.__next == None : self.__next = employee else : self = self.__next self._set__next(employee) def __init__(self,name): self.__name = name def show(self): ...
5d5612f42740c5736030d9f756c46d29e0687902
BackToTheSchool/assignment_js
/1113/hw35.py
199
4.09375
4
import random list_name = [] name = input("Enter the name : ") while name != '': list_name.append(name) name = input("Enter the name : ") print("The winner is ..",random.choice(list_name))
781880b27093f48f34a4ba7b6ba918ce0f7696d6
BackToTheSchool/assignment_js
/1108/hw11.py
232
3.96875
4
euro = float(input("How many Euro are you exchanging?")) euro_rate = float(input("What is the exchange rate ? ")) dollar_rate = 1114.8272 print(euro,"Euros at an exchange rate of",euro_rate,"is",round(euro*euro_rate/dollar_rate,3))
c8591f2e6c670969613f4e3b66f833bf08e1a060
BackToTheSchool/assignment_js
/1108/hw17.py
483
4.03125
4
weigh = float(input("How weigh are you ?")) gender = input("What is your gender ? ") hour = int(input("When did you drink ? ")) drink = float(input("How much did you drink ?" )) if gender == "male": result = (drink*5.14/weigh*0.73)-0.015*hour elif gender == "female": result = (drink * 5.14/weigh*0.6)-0.015*hour...
2ee2652b59f49dc5fa7adf8c798df2fc7990c57d
BackToTheSchool/assignment_js
/restaurant/Restaurant.py
2,826
4.1875
4
# code name : Restaurant # programmer : Joon Soo Park # description : This file is about restaurant. This file got 3 type of resaurant. It will devide by Human.person class Restaurant : # This is Restaurant, this class describe atmosphere and name def __init__(self, atmosphere, name) : self.atmosphere = ...
346d3b34955d34e1eadbead560185ff6d6bcb877
BackToTheSchool/assignment_js
/1109/hw28.py
177
4
4
number = [] for i in range(0,5) : number.append(int(input("Enter the number : "))) result = 0 for i in range(0,5) : result = result + number[i] print("Result is",result)
e93ea7a038c462cc52b5b9048a40902376328be8
oksana-gorovaya/python_learning
/tandem_repetition.py
257
3.921875
4
import sys import re pattern = r"\b[a-z]*?([a-z]{2,}?)\1+[a-z]*?\b" # r"\b(\w+)\?{2}\b" def find_occurrences(pattern): for line in sys.stdin: line = line.rstrip() print(line) if re.findall(pattern, line): print(line) find_occurrences(pattern)
f8adf9f544a79ac877a879bbfd482930a7ea9aa4
chengzheng2013/cluster_number_estimation
/experiments/indices/halkidi_vazirgannis.py
6,539
3.515625
4
# Paper Source: M. Halkidi, M. Vazirgiannis 2001. # Clustering Validity Assessment: Finding the optimal partitioning # of a data set. Proceedings of the # 2001 IEEE International Conference on Data Mining (ICDM 2001), # pp. 187–194. # Min number of clusters = 1 # The time complexity is O(nk^2), where n is the number o...
fbce9765bb1b68376329c6ba841ef03b6c4a365c
lilyhe19/final_project
/archive/final_project-master/bmi.py
887
4.625
5
def BMI(): ''' Takes user input of height (in) and weight (lb) and returns the BMI. Standard BMI is the ratio of weight (kg) to height squared (cm). For US users, this function can use pounds and inches. ''' #kilograms and centimeters # height = input("height >> ") # weight = input("weight >> ") # hMetric = int(he...
c3de034b7be518b2a8efdc445763e25d7df1d598
lilyhe19/final_project
/final_project_master/bmi.py
1,189
4.84375
5
def BMI(): ''' Takes user input of height (in) and weight (lb) and returns the BMI. Standard BMI is the ratio of weight (kg) to height squared (cm). For US users, this function can use pounds and inches. ''' print("\n This program will return your BMI, \ \n as calculated by the standard BMI...
65db4c6f4dddec3ac209294c9ba60e1c0bff0043
lilyhe19/final_project
/final_project-master/mainPage.py
2,335
3.984375
4
#import math #def main_function(x): #input is the number chosen by user # """ # docstring # """ # return [1,2,3] #if 1: run the doctor csv #if 2: run BMI calc #etc. etc. etc h #pseudocode #pseudocode #put something here #return function if __name__ == "__main__": print("Welcome to EZHealth \n \n Here ar...
de7e0b48578695178c3879302066632588568878
crakama/UdacityIntrotoComputerScience
/square.py
252
4
4
# Define a procedure, square, that takes one number # as its input, and returns the square of that # number (result of multiplying # the number by itself). def numsquare(num): square = num * num return square n = raw_input() numsquare(n)
c35edb837342ac5d37c12bea16458fb6bab6a068
crakama/UdacityIntrotoComputerScience
/hash_string.py
314
3.703125
4
# Define a function, hash_string, # that takes as inputs a keyword # (string) and a number of buckets, # and returns a number representing # the bucket for that keyword. def hash_string(keyword, buckets): h = 0 for c in keyword: h = (h + ord(c)) % buckets return h print hash_string('b', 12)
bf452fa40894920511b6956c03a4a2ced23cec05
KongsonPark/Algorithm_Playground
/BOJ/boj_4344.py
598
3.5
4
import sys t = int(input()) for _ in range(t): a = list(map(int, sys.stdin.readline().split())) n = a[0] b = a[1:] avr = sum(b) / n count = 0 for i in b: if i > avr: count += 1 answer = count / n * 100 print('{:.3f}%'.format(answer)) ## 다른 사람 풀이 n = int(input()) ...
f84c81157845d39c329cb1d4d909a8fb0406c8d9
KongsonPark/Algorithm_Playground
/BOJ/boj_10162.py
1,607
3.578125
4
''' 전자레인지 버튼 A, B, C에 지정된 시간은 각각 5분, 1분, 10초이다. A, B, C 3개의 버튼을 적절히 눌러서 그 시간의 합이 정확히 T초가 되도록 해야 한다. 단 버튼 A, B, C를 누른 횟수의 합은 항상 최소가 되어야 한다. 이것을 최소버튼 조작이라고 한다. T초를 위한 최소버튼 조작의 A B C 횟수를 첫 줄에 차례대로 출력해야 한다. 각각의 횟수 사이에는 빈 칸을 둔다. 해당 버튼을 누르지 않는 경우에는 숫자 0을 출력해야한다. 만일 제시된 3개의 버튼으로 T초를 맞출 수 없으면 음수 -1을 첫 줄에 출력해야 한다. ''' s = int...
25fe2c56ce9da140a09a9109299d4bc8133bd8d1
UnTamedLaw/DataScienceExercises
/DataScienceListWork.py
726
3.921875
4
import random #my version total = 0 for x in range(3): list_1 = [random.randint(0, 100) for x in range (0, 100)] list_2 = [x for x in list_1 if x % 3 == 0] difference2 = len(list_1) - len(list_2) total += difference2 mean = total/3.0 print(mean) number_of_experiments = 10 difference_list = [] #books ...
a576c2e4643cf7994fe0334b5aaa3ed304b06889
UnTamedLaw/DataScienceExercises
/strings.py
825
4.4375
4
#strings can be defined using single quotes and double quotes str_1 = "hello world!" str_1[0] #return as "h" str_1[-1] #return as ! #accessing the elements of a string is like accessing a list str_1 = "Hello World! I am learning data wrangling" # print(str_1 [2:10]) 'llo Worl" #str_1[-31:] # 'd! I am learning data wr...
357dbd375e41a985ae33b482b2d42ddb1c69a7cd
AlanCLo/play_ml
/aigames/aigames/games/ttt/console.py
1,933
3.703125
4
from .board import Board, Cell, Outcome from .player import AbstractPlayer, player_type P1_CHAR = 'X' P2_CHAR = 'O' class Console(object): """A View class - the console implementation""" def __init__(self): super(Console, self).__init__() def display_board(self, board): i = 1 f...
2ac89a8f9c4df5e94d9a3f97fb88ae9421d91b58
nickobrad/pman
/pman.py
8,596
4.21875
4
#!/usr/bin/env python3.9 from user_class import User from credentials_class import Credentials import random import string def create_user(first_name, second_name, username, password): newUser = User(first_name,second_name,username,password) return newUser def user_save(user): ''' Saves the newly cr...
c796213a0ed259961c0f73c51425d47bf1db0b6b
Rapixar/portfolio-deprecated
/test.py
464
3.546875
4
print("myname") class num_class: pass def __init__(self, x, y): self.x = x self.y = y def add(self, x, y): try: z = x + y return z except: raise NotImplementedError def substract(self, x, y): try: z = x - y ...
bbc250415a1372395c78f3bd8ef0d6dfe82e0389
Mumulhy/LeetCode
/1725-可以形成最大正方形的矩形数目/CountGoodRectangles.py
704
3.75
4
# -*- coding: utf-8 -*- # LeetCode 1725-可以形成最大正方形的矩形数目 """ Created on Fri Feb 4 23:00 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def countGoodRectangles(self, rectangles: List[List[int]]) -> int: ans = 0 max_len = 0 for rectangle i...
702dd529c51de80f704c898a2306c3e4614b02f9
Mumulhy/LeetCode
/757-设置交集大小至少为2/IntersectionSizeTwo.py
730
3.5
4
# -*- coding: utf-8 -*- # LeetCode 757-设置交集大小至少为2 """ Created on Fri Jul 22 19:21 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def intersectionSizeTwo(self, intervals: List[List[int]]) -> int: intervals.sort(key=lambda x: (x[0], -x[1])) ans, n, m = 0, len(in...
2330400bce62568b619eec43d411d37ae0525223
Mumulhy/LeetCode
/剑指Offer53-I-在排序数组中查找数字I/Search.py
1,411
3.734375
4
# -*- coding: utf-8 -*- # LeetCode 剑指Offer53-I-在排序数组中查找数字I """ Created on Fri Jul 16 19:54 2021 @author: _Mumu Environment: py38 """ from typing import List class Solution: def search(self, nums: List[int], target: int) -> int: if target not in nums: return 0 if target == nums[0] an...
0c23325d6342354fb98f9fdf70bb292ab91ef07a
Mumulhy/LeetCode
/1218-最长定差子序列/LongestSubsequence.py
551
3.8125
4
# -*- coding: utf-8 -*- # LeetCode 1218-最长定差子序列 """ Created on Fri Nov 5 23:59 2021 @author: _Mumu Environment: py38 """ from collections import defaultdict from typing import List class Solution: def longestSubsequence(self, arr: List[int], difference: int) -> int: dp = defaultdict(int) for nu...
530d0353f81ee179b134049ff899eef5fad6b54b
Mumulhy/LeetCode
/310-最小高度树/FindMinHeightTrees.py
1,347
3.71875
4
# -*- coding: utf-8 -*- # LeetCode 310-最小高度树 """ Created on Wed Apr 6 09:39 2022 @author: _Mumu Environment: py38 """ from collections import defaultdict from typing import List class Solution: def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]: graph = defaultdict(set) f...
6d09d05e30e60b59b504df87230ddf429ceff879
Mumulhy/LeetCode
/面试题17.19-消失的两个数字/MissingTwo.py
810
3.609375
4
# -*- coding: utf-8 -*- # LeetCode 面试题17.19-消失的两个数字 """ Created on Mon Sept 26 11:24 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def missingTwo(self, nums: List[int]) -> List[int]: xor = 0 n = len(nums) + 2 for num in nums: xor ^= num ...
721f67af0d15c02e61b405d9b4d5adcd351c667e
Mumulhy/LeetCode
/551-学生出勤记录I/CheckRecord.py
389
3.671875
4
# -*- coding: utf-8 -*- # LeetCode 551-学生出勤记录I """ Created on Tues Aug 17 22:05 2021 @author: _Mumu Environment: py38 """ class Solution: def checkRecord(self, s: str) -> bool: if s.count('A') >= 2 or 'LLL' in s: return False else: return True if __name__ == '__main__':...
b76c324dc9e02036784cf0f8b99347de26521aee
Mumulhy/LeetCode
/919-完全二叉树插入器/CBTInserter.py
1,787
3.828125
4
# -*- coding: utf-8 -*- # LeetCode 919-完全二叉树插入器 """ Created on Mon Jul 25 10:27 2022 @author: _Mumu Environment: py38 """ # Definition for a binary tree node. class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class CBTI...
af39e365c6a97c29d1743a71cec5996b075f10c7
Mumulhy/LeetCode
/653-两数之和IV-输入BST/FindTarget.py
926
3.765625
4
# -*- coding: utf-8 -*- # LeetCode 653-两数之和IV-输入BST """ Created on Mon Mar 21 14:20 2022 @author: _Mumu Environment: py38 """ from typing import Optional # Definition for a binary tree node. class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left ...
c0d3068a7360fd120d40bbd8db3f690efb903e85
Mumulhy/LeetCode
/1640-能否连接形成数组/CanFormArray.py
702
3.734375
4
# -*- coding: utf-8 -*- # LeetCode 1640-能否连接形成数组 """ Created on Thu Sept 22 09:38 2022 @author: _Mumu Environment: py39 """ from typing import List class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: n = len(arr) pieces = {piece[0]: piece for piece in pieces...
5dcb9efc540db14dbe6e906c5b26d765190f4ed2
Mumulhy/LeetCode
/952-按公因数计算最大组件大小/LargestComponentSize.py
1,732
3.5
4
# -*- coding: utf-8 -*- # LeetCode 952-按公因数计算最大组件大小 """ Created on Sat Jul 30 10:36 2022 @author: _Mumu Environment: py38 """ from collections import defaultdict from functools import lru_cache from typing import List class UnionFind: def __init__(self, n: int): self.root = list(range(n)) self....
10e88416cc2637ef5c4107f60c66994d9d52d419
Mumulhy/LeetCode
/153-寻找旋转排序数组中的最小值/FindMin.py
655
3.75
4
# -*- coding: utf-8 -*- # LeetCode 153-寻找旋转排序数组中的最小值 """ Created on Thu Apr 8 14:42 2021 @author: _Mumu Environment: py37 """ class Solution: def findMin(self, nums: list) -> int: left = 0 right = len(nums) - 1 if nums[left] <= nums[right]: return nums[left] while Tru...
af4088e965d6e858feac23430d9e7ade520ae278
Mumulhy/LeetCode
/剑指Offer42-连续子数组的最大和/MaxSubArray.py
521
3.828125
4
# -*- coding: utf-8 -*- # LeetCode 剑指Offer42-连续子数组的最大和 """ Created on Sat Jul 17 20:39 2021 @author: _Mumu Environment: py38 """ from typing import List class Solution: def maxSubArray(self, nums: List[int]) -> int: pre = 0 max_sum = nums[0] for num in nums: pre = max(pre + ...
d055382b061ac41ec37f6ccb3735dfe61e2bd141
Mumulhy/LeetCode
/326-3的幂/IsPowerOfThree.py
415
3.890625
4
# -*- coding: utf-8 -*- # LeetCode 326-3的幂 """ Created on Thu Sept 23 20:19 2021 @author: _Mumu Environment: py38 """ class Solution: def isPowerOfThree(self, n: int) -> bool: return n > 0 and 1162261467 % n == 0 # power = 1 # while power < n: # power *= 3 # return p...
7a1c8f9cd929db281826c70907dba547d53d1564
Mumulhy/LeetCode
/142-环形链表II/LinkedListCycleII.py
1,263
3.546875
4
# -*- coding: utf-8 -*- # LeetCode 142-环形链表II """ Created on Thu Oct 3 14:47 2019 @author: _Mumu Environment: py37 """ # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def detectCycle(self, head)...
bbd433b7feaa51be948526a2aee2b382f9397c06
Mumulhy/LeetCode
/442-数组中重复的数据/FindDuplicates.py
556
3.734375
4
# -*- coding: utf-8 -*- # LeetCode 442-数组中重复的数据 """ Created on Sun May 8 10:04 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def findDuplicates(self, nums: List[int]) -> List[int]: ans = [] for i in range(len(nums)): num = abs(nums[i]) ...
21fc677af46d61a8fb2c107f9ff8c03e39b72582
Mumulhy/LeetCode
/1104-二叉树寻路/PathInZigZagTree.py
748
3.828125
4
# -*- coding: utf-8 -*- # LeetCode 1104-二叉树寻路 """ Created on Thu Jul 29 18:01 2021 @author: _Mumu Environment: py38 """ from typing import List class Solution: def pathInZigZagTree(self, label: int) -> List[int]: self.bin = bin(label)[2:] self.bin_r = '1' + ''.join(['0' if j == '1' else '1' for...
f0ed59722f546ac315a72db44de169e66d2e9b84
Mumulhy/LeetCode
/1189-“气球”的最大数量/MaxNumberOfBalloons.py
470
3.734375
4
# -*- coding: utf-8 -*- # LeetCode 1189-“气球”的最大数量 """ Created on Sun Feb 13 10:24 2022 @author: _Mumu Environment: py38 """ from collections import Counter class Solution: def maxNumberOfBalloons(self, text: str) -> int: cnt = Counter(text) return min(cnt['b'], cnt['a'], cnt['l'...
6b9e26c78463686b985a03798dc0c9372d4b8ac1
Mumulhy/LeetCode
/208-实现Trie(前缀树)/Trie.py
1,839
4.03125
4
# -*- coding: utf-8 -*- # LeetCode 208-实现Trie(前缀树) """ Created on Thu Sept 16 22:11 2021 @author: _Mumu Environment: py38 """ class Trie: def __init__(self): """ Initialize your data structure here. """ self.children = [0] * 26 self.isEnd = False def insert(self, wor...
ce2916a9d79d252b58c903edb75226f912028b7a
Mumulhy/LeetCode
/899-有序队列/OrderlyQueue.py
898
3.5
4
# -*- coding: utf-8 -*- # LeetCode 899-有序队列 """ Created on Wed Aug 3 09:07 2022 @author: _Mumu Environment: py38 """ class Solution: def orderlyQueue(self, s: str, k: int) -> str: if k > 1: return ''.join(sorted(s)) n = len(s) i, j, l = 0, 1, 0 while j + l < n: ...
04cd807a9311d6ae2b50df0a6c9a234519cd9775
Mumulhy/LeetCode
/801-使序列递增的最小交换次数/MinSwap.py
792
3.59375
4
# -*- coding: utf-8 -*- # LeetCode 801-使序列递增的最小交换次数 """ Created on Mon Oct 10 10:38 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def minSwap(self, nums1: List[int], nums2: List[int]) -> int: n = len(nums1) a, b = 0, 1 for i in range(1, n): ...
27382bd0cca7820c557245bce4b235c37e416cc0
Mumulhy/LeetCode
/1235-规划兼职工作/JobScheduling.py
736
3.578125
4
# -*- coding: utf-8 -*- # LeetCode 1235-规划兼职工作 """ Created on Sat Oct 22 15:16 2022 @author: _Mumu Environment: py38 """ from bisect import bisect_right from typing import List class Solution: def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int: n = len(startTime...
afe1bf2e7e96d1bf3294f038f63c6a2c6efca201
Mumulhy/LeetCode
/面试题10.02-变位词组/GroupAnagrams.py
1,289
3.75
4
# -*- coding: utf-8 -*- # LeetCode 面试题10.02-变位词组 """ Created on Sun Jul 18 17:30 2021 @author: _Mumu Environment: py38 """ from typing import List class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: sorted_strs = {} for string in strs: sorted_string = ''.joi...
66649dad16dc412ae54432e41f430d46ef827a8d
Mumulhy/LeetCode
/819-最常见的单词/MostCommonWord.py
1,193
3.6875
4
# -*- coding: utf-8 -*- # LeetCode 819-最常见的单词 """ Created on Sun Apr 17 15:33 2022 @author: _Mumu Environment: py38 """ from collections import defaultdict from typing import List class Solution: def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: banned = set(banned) cnt = defa...
5d05339e0454e6cccccb215113c06d2ee296e165
Mumulhy/LeetCode
/794-有效的井字游戏/ValidTicTacToe.py
1,096
3.609375
4
# -*- coding: utf-8 -*- # LeetCode 794-有效的井字游戏 """ Created on Thu Dec 9 22:24 2021 @author: _Mumu Environment: py38 """ from typing import List class Solution: def validTicTacToe(self, board: List[str]) -> bool: X, O = 0, 0 lines = [0] * 8 for i in range(3): for j in range(3...
601452602967709635f1ace00187e2c4eb7ae3dd
Mumulhy/LeetCode
/58-最后一个单词的长度/LengthOfLastWord.py
556
3.796875
4
# -*- coding: utf-8 -*- # LeetCode 58-最后一个单词的长度 """ Created on Tues Sept 21 14:19 2021 @author: _Mumu Environment: py38 """ class Solution: def lengthOfLastWord(self, s: str) -> int: return len(s.split()[-1]) # length = 0 # for ch in s[::-1]: # if ch == ' ': # ...
1e27030b2c127fc6764e51f8d4ec344f8669091d
Mumulhy/LeetCode
/2044-统计按位或能得到最大值的子集数目/CountMaxOrSubsets.py
756
3.84375
4
# -*- coding: utf-8 -*- # LeetCode 2044-统计按位或能得到最大值的子集数目 """ Created on Tues Mar 15 14:54 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def countMaxOrSubsets(self, nums: List[int]) -> int: n = len(nums) max_or, ans = 0, 0 for num in nums: ...
6b95777dd1ee6c63d74013622bc3bb5c7277a7e5
Mumulhy/LeetCode
/646-最长数对链/FindLongestChain.py
571
3.640625
4
# -*- coding: utf-8 -*- # LeetCode 646-最长数对链 """ Created on Sat Sept 3 10:58 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def findLongestChain(self, pairs: List[List[int]]) -> int: curr, ans = float('-inf'), 0 for x, y in sorted(pairs, key=lambda p: p[1]): ...
bb76d50158f5dc91e0978a8b8020617dce5d62fd
Mumulhy/LeetCode
/剑指OfferII091-粉刷房子/MinCost.py
521
3.671875
4
# -*- coding: utf-8 -*- # LeetCode 剑指OfferII091-粉刷房子 """ Created on Sat Jun 25 12:24 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def minCost(self, costs: List[List[int]]) -> int: dp = costs[0] for i in range(1, len(costs)): dp = [costs[i][j] + m...
428737aad901bf7ff52c5563e57a7387f5313f95
Mumulhy/LeetCode
/954-二倍数对数组/CanReorderDoubled.py
671
3.546875
4
# -*- coding: utf-8 -*- # LeetCode 954-二倍数对数组 """ Created on Fri Apr 1 10:30 2022 @author: _Mumu Environment: py38 """ from collections import Counter from typing import List class Solution: def canReorderDoubled(self, arr: List[int]) -> bool: cnt = Counter(arr) for num in sorted(cnt.keys(), ke...
6d1f10cdb24bf4275db27cbef7c2eccd937710c9
Mumulhy/LeetCode
/26-删除有序数组中的重复项/RemoveDuplicates.py
904
3.515625
4
# -*- coding: utf-8 -*- # LeetCode 26-删除有序数组中的重复项 """ Created on Sun Sept 6 19:30 2021 @author: _Mumu Environment: py38 """ from typing import List class Solution: def removeDuplicates(self, nums: List[int]) -> int: if not nums: return 0 fast, slow = 1, 0 n = len(nums) ...
a70cee4a64861ec9bbf168881b32534c913d13ba
Mumulhy/LeetCode
/1051-高度检查器/HeightChecker.py
416
3.875
4
# -*- coding: utf-8 -*- # LeetCode 1051-高度检查器 """ Created on Mon Jun 13 10:48 2022 @author: _Mumu Environment: py38 """ from typing import List class Solution: def heightChecker(self, heights: List[int]) -> int: return sum(height != expected for height, expected in zip(heights, sorted(heights))) if _...
5ededff1f2f50722504041c28e6aa910f9d1489e
Mumulhy/LeetCode
/剑指OfferII029-排序的循环链表/Insert.py
2,061
3.671875
4
# -*- coding: utf-8 -*- # LeetCode 剑指OfferII029-排序的循环链表 """ Created on Sat Jun 18 10:22 2022 @author: _Mumu Environment: py38 """ # Definition for a Node. class Node: def __init__(self, val=None, next=None): self.val = val self.next = next class Solution: def insert(self, head: 'Node', ins...
a410af8255ad9684cebe62d1e182fb17ec45f401
Mumulhy/LeetCode
/1768-交替合并字符串/MergeAlternately.py
444
3.71875
4
# -*- coding: utf-8 -*- # LeetCode 1768-交替合并字符串 """ Created on Sun Oct 23 15:39 2022 @author: _Mumu Environment: py38 """ from itertools import zip_longest class Solution: def mergeAlternately(self, word1: str, word2: str) -> str: return ''.join(c1 + c2 for c1, c2 in zip_longest(word1, word2, fillvalue...
ee6aa2084010267e2f1f0f65d1d135f30baa8992
Mumulhy/LeetCode
/942-增减字符串匹配/DiStringMatch.py
583
3.65625
4
# -*- coding: utf-8 -*- # LeetCode 942-增减字符串匹配 """ Created on Mon May 9 10:10 2022 @author: _Mumu Environment: py38 """ from collections import deque from typing import List class Solution: def diStringMatch(self, s: str) -> List[int]: q = deque(range(len(s) + 1)) ans = [] for ch in s: ...
1c28403ca84bef178b3942698e9e54e8a9429507
Mumulhy/LeetCode
/1609-奇偶树/IsEvenOddTree.py
1,170
3.796875
4
# -*- coding: utf-8 -*- # LeetCode 1609-奇偶树 """ Created on Sat Dec 25 22:19 2021 @author: _Mumu Environment: py38 """ from typing import Optional # Definition for a binary tree node. class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.r...
12e6ec78de7e4286b7a4c5e0d1a01cde2f76eaa7
R-Rayburn/PythonCookbook
/01_data_structures_and_algorithms/15_grouping_records_based_on_field.py
1,726
4.15625
4
# Problem # You have a sequence of items you want to iterate over in groups based on a field # value. # Solution # The itertools.groupby() function is useful for grouping data together. rows = [ {'address':'5412 N CLARK', 'date': '07/01/2012'}, {'address': '5148 N CLARK', 'date': '07/04/2012'}, {'addr...
89e7e92f8951a1fb60805dd015a07ebee034d4d2
R-Rayburn/PythonCookbook
/01_data_structures_and_algorithms/14_sorting_objects_without_natve_comparison_support.py
1,459
3.96875
4
# Problem # You need to sort objects of the same class, but they don't natively support comparison operations. # Solution # The built in sorted() function takes a key argument that can be passed a callable that will return some values in the object that the sorted function will use to compare the objects. class User...
67afac6aa72419e8f67db2346ad2c0941027d001
yanazor/CoffeeMachine1
/Coffee Machine/task/machine/coffee_machine.py
3,892
4.09375
4
class CoffeeMachine: power = 'off' def __init__(self, money, beans, milk, water, cups): self.money = money self.beans = beans self.milk = milk self.water = water self.cups = cups def buy(self): coffee = input('What do you want to buy? 1 - espresso, 2 - latte...
ea299416dbb658a6371aba95d70477259441b7a9
NicoleCarpenter/tic-tac-toe-python
/test/test_string_validator.py
1,065
3.609375
4
import unittest from lib.string_validator import StringValidator class TestStringValidator(unittest.TestCase): def setUp(self): self.validator = StringValidator() def test_is_valid_return_string(self): self.assertEquals(self.__is_valid_return('John Smith'), True) self.assertEquals(self.__is_valid_ret...
00420a76d31799d350e8d0f26cc76eadf5c33f15
evukelic/APR
/lab3/Main.py
4,412
3.578125
4
from OptimisationMethods import * from ExplicitConstraint import * from ImplicitConstraint import * """ Main file which tests out the behaviour of the Optimisation algorithms. """ # task 1 print("### TASK 1 - GRADIENT DESCENT + GOLDEN SECTION / FUNCTION 3 ###") func = Function3() minimum = gradient_descent((0, 0), fu...
6dbd9724ff52a36a6080ad4940f38ab71e007037
filipeth/Machine-Learning
/exemplo_beautifulSoup.py
1,228
3.59375
4
from bs4 import BeautifulSoup import requests import urllib3 # html_doc = """<html> # <body> # <h1> My first Heading</h1> # <b><!--This is a comment line--></b> # <p title="About Me" class="test">My first paragraph.</p> # <div class="cities"> # <h2>London</h2> # </div> # </body> # </html>""" # # # soup = BeautifulSoup...