blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
3.06M
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
3.06M
67caaeba41bac64eaf538828b67f94b00018c263
anhpt1993/quiz1_lesson8
/quiz1_lesson8.py
1,485
3.890625
4
import turtle as t import random def get_color(): red = random.randint(0, 255) green = random.randint(0, 255) blue = random.randint(0, 255) return red, green, blue def draw_rectangle(x, y, color): t.pendown() t.fillcolor(color) t.begin_fill() for i in range(4): if i % 2 == 0: ...
5cdb0a6b8ea04cb5d2d5cc73aee4d0070b9922d7
gabriel-inf/programming-challenges
/avarge_links.py
1,354
3.609375
4
import sys def get_adjacent_nodes(graph, node): a = 0; b = 1 adj = [] for link in graph: if link[a] == node: adj.append(link[b]) def distance(graph, source, destine): unvisited_nodes = get_nodes_set(graph) visited_nodes = set() unvisited = [x for x in get_nodes_set()] visted = [] found = False dist =...
cced43693e52355d6f69bfb0c82027cccc6a2aee
divyanshj16/parabole-internship-test-py3
/get_unique.py
514
3.53125
4
import os inp_dir = './input' os.system('rm unique.txt') unique_list = [] with open('unique.txt','a') as op_file: for _,_,files in os.walk(inp_dir): print('reading files') for file in files: filename = os.path.join(inp_dir,file) f = open(filename,'r').read() f_list = f.split() print(f'{len(f_list)}...
0133d488f60b6ffe7c0085d709f56246fcf1971e
chetanDN/Python
/AlgorithmsAndPrograms/03_LinkedLists/ReverseSinglyLinkedList.py
316
3.515625
4
from LinkedListNode import * def reverse_single_ll(self): last = None current = self.head while(current.next != None): Next LL1 = LinkedList() LL1.add_at_end(Node(4)) LL1.add_at_end(Node(5)) LL1.add_at_beg(Node(1)) LL1.add_at_beg(Node(3)) 'hello'.split() print('*'*56) LL1.print_list()
7c821b9a5102495f8f22fc21e29dd9812c77b3bd
chetanDN/Python
/AlgorithmsAndPrograms/02_RecursionAndBacktracking/01_FactorialOfPositiveInteger.py
222
4.125
4
#calculate the factorial of a positive integer def factorial(n): if n == 0: #base condition return 1 else: return n * factorial(n-1) #cursive condition print(factorial(6))
cf4f5a6051f4e18da38625d1ef8425a4bb204416
chetanDN/Python
/QSP/JSPtoQSP/03_Area_MethodWithParameter_WithReturnType/Area07.py
220
3.984375
4
import math def find_area_circle(r1): pi = math.pi area = pi * r1 * r1 # area of circle return area # r = 10 # radius of circle area_circle = find_area_circle(10) print("area of circle :", area_circle)
e80e75d53cbf1f27575293c008a55bd03034c2b5
chetanDN/Python
/QSP/JSPtoQSP/04_Area_ClassWithoutParameter_WithoutReturnType/Area02.py
254
3.53125
4
class AreaCalculator(object): @staticmethod def find_area(): width = 10 length = 20 area_of_rectangle = width * length print("area_of_rectangle : ", area_of_rectangle) class Main: AreaCalculator.find_area()
65ac4a69beb3f9d75c98d2e667ce24b2952863c5
chetanDN/Python
/QSP/JSPtoQSP/03_Area_MethodWithParameter_WithReturnType/Area06.py
287
3.59375
4
def area_of_parallelogram(b1, h1): area = b1 * h1 # area of parallelogram return area # b = 20 # base of parallelogram # h = 10 # height from base of the parallelogram area_parallelogram = area_of_parallelogram(20, 10) print("area of parallelogram is ", area_parallelogram)
09062cbc8a7838a90528b45fc3f8c4ce9b4d2401
chetanDN/Python
/QSP/JSPtoQSP/02_Area_MethodWithParameter_NoReturnType/Area01.py
232
3.859375
4
def find_area(b, h): area_of_triangle = (1 / 2) * b * h print("Area of triangle with base {} and height {} is :{}".format(b, h, area_of_triangle)) base = 10 # base height = 20 # height_from_base find_area(base, height)
0b01302dfccf72c4d8f4a0a48e6b3069a2b72824
kriti-ixix/ml-230
/python/lambda expression.py
173
3.5625
4
def times10(x): return x * 10 myList = list(range(1, 11)) #print(myList) #print(list(map(times10, myList))) l = lambda x : x * 10 print(l(20)) print(map(l, myList))
89c489d8298afdbee18392428bf12b97e0ec2015
kriti-ixix/ml-230
/python/list comprehension.py
201
3.984375
4
myList = list(range(1, 11)) print(myList) ''' mySquares = [] for i in myList: if i%3 == 0: mySquares.append(i ** 2) ''' mySquares = [i ** 2 for i in myList if i%3 == 0] print(mySquares)
956c31200392e6e40edba2015968da4b4fdf3b12
rajatsharma369007/google_code_jam
/qualification_round_2019/problem_3/problem_3.py
3,450
3.6875
4
''' command line arguments to this script: first line takes the number of test cases and then each test case contains 2 lines, first line 2 numbers: N (use prime numbers less than N) and L (length of the list of values of cyphertext), second line contains the list of values of cyphertext. for more info, watch the probl...
dc1316bdc81f9e2ccb7595241217b4ffb1061b99
saikrishnajeeti/pythonprogramming
/ex-5.py
166
3.78125
4
a="hello world" print(a) print(a[::-1]) print(a.capitalize()) print(a.lower()) print(a.count('o')) print(a.isdecimal()) print(a.swapcase()) print(a.title())
7519f4565487e41c46dcaf95c8ccfb0550fe2409
angelah1994/holbertonschool-higher_level_programming-1
/0x0C-python-almost_a_circle/models/rectangle.py
4,421
3.671875
4
#!/usr/bin/python3 """ module Rectangle """ from models.base import Base class Rectangle(Base): """ class Rectangle that inherits from Base """ def __init__(self, width, height, x=0, y=0, id=None): """ constructor Rectangle Arguments: @width: width of rectangle @h...
cafb484c41643703892db391435d7e65e522a9cf
angelah1994/holbertonschool-higher_level_programming-1
/0x07-python-test_driven_development/2-matrix_divided.py
1,495
3.5625
4
#!/usr/bin/python3 def matrix_divided(matrix, div): new_matrix = [] ty_err = "matrix must be a matrix (list of lists) of integers/floats" le_err = "matrix must be a matrix (list of lists) of integers/floats" row_err = "Each row of the matrix must have the same size" if type(matrix) != list or len(...
fa1500021bcaadf1d892614f5a6a198b85d5a76c
angelah1994/holbertonschool-higher_level_programming-1
/0x04-python-more_data_structures/12-roman_to_int.py
552
3.71875
4
#!/usr/bin/python3 def roman_to_int(roman_string): if roman_string is None: return 0 if type(roman_string) is not str: return 0 romans = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} number = len(roman_string) value_int = romans[roman_string[number-1]] for i i...
bc5942cae139e82129c3362250cf9fe0e850b693
Nehawadhawan/Python-codes
/temp.py
1,627
3.75
4
#Importing all the required libraries import pandas as pd import numpy as np from sklearn.feature_selection import chi2 import scipy.stats #creating a dataframe which will help us have 3x2 matrix subscription = {'Age Group': ['21 and below','21-35 Age','35 and above','21 and below','21-35 Age','35 and above'], ...
9bbcd87d994a200ebe11bc09ff79995dd74eac0a
GBaileyMcEwan/python
/src/hello.py
1,863
4.5625
5
#!/usr/bin/python3 print("Hello World!\n\n\n"); #print a multi-line string print( ''' My Multi Line String ''' ); #concatinate 2 words print("Pass"+"word"); #print 'Ha' 4 times print("Ha" * 4); #get the index of the letter 'd' in the word 'double' print("double".find('d')); #print a lower-case version of the stri...
ccd9b916a7bfdc43158141e232eadb97090fd630
jeudy/intropython0415
/manejo_excepciones.py
1,334
4.03125
4
#!/usr/bin/python # -*- coding: UTF-8 -*- """ Ejemplo de manejo de excepciones en python """ # Dummy comment para probar integración con git. import random print "Digite un numero que sera denominador de division: " try: numero = int(raw_input()) # El manejo de excepciones puede ser anidado try: ...
d83ec49eb31a3a04bc1566c8bc10e7a6e1ed129e
bkdbansal/CS_basics
/leetcode_python/Recursion/second-minimum-node-in-a-binary-tree.py
2,615
3.703125
4
# V0 : DEV # V1 # http://bookshadow.com/weblog/2017/09/03/leetcode-second-minimum-node-in-a-binary-tree/ # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def findSecond...
fa7c52446c6eb86256141c692377658875189c74
bkdbansal/CS_basics
/leetcode_python/Binary_Search/search-a-2d-matrix.py
1,640
3.5
4
# V0 # V1 # https://blog.csdn.net/fuxuemingzhu/article/details/79459314 class Solution(object): def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ if not matrix or not matrix[0]: return False ...
21556471ad47a7c555ba6dabeb8205787a7f90ec
bkdbansal/CS_basics
/leetcode_python/Stack/implement-queue-using-stacks.py
3,100
4.3125
4
""" Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. empty() -- Return whether the queue is empty. Example: MyQueue queue = new MyQueue(); queue.push(1); queue.push(2); q...
8771664f660f29c36a4e450653385c8fea18fa77
bkdbansal/CS_basics
/leetcode_python/Tree/convert-bst-to-greater-tree.py
1,263
3.8125
4
# V0 # V1 # https://blog.csdn.net/fuxuemingzhu/article/details/79132336 # IDEA : RIGHT -> ROOT -> LEFT # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def convertBST(...
acdf88412c68471c0fa9459d731a0fb0f8b948f0
bkdbansal/CS_basics
/leetcode_python/Math/solve-the-equation.py
2,678
3.75
4
# V1 : to do : solve again with regular expression # class Solution(object): # def solveEquation(self, equation): # eq = equation.split("=") # left_eq, right_eq = eq[0], eq[1] # sum_constant = sum([ int(i) for i in eq[1] if i.isdigit()]) - [ int(i) for i in eq[0] if i.isdigit()] # sum_var = len([ i for i in...
1a934479feea64664c132b7d4999dc42c113f08c
Gagan42/python_programs
/tuple_basic.py
440
3.75
4
# n = int(input("Enter number of elements : ")) # # Below line read inputs from user using map() function # i=0 # while i<n: # a = list(map(int,input("\nEnter the numbers : ").strip().split()))[:n] # print("\nList is - ", a) # i=i+1 n = int(input()) input_line = list(map(int,input().strip().split(...
7b64b0a0b4904c536830b3a166d82ce22b61fd02
MarsOopo/pythonLabs
/test/format.py
384
3.9375
4
#-*- config:utf-8 -*- age=25 name='Caroline' print('{0} is {1} years old.'.format(name,age)) print('{0} is a girl'.format(name)) print('{0:.3} is a decimal.'.format(1/3)) print('{0:_^11} is a 11 length'.format(name)) print('{first} is as {second}'.format(first=name,second='Wendy')) print('My name is {0.name}'.format(...
dfb8fce1392acf90f85fefa04a69547a7c2a9b9f
bismog/leetcode
/python/enumerate.py
356
3.78125
4
## Came from: https://www.geeksforgeeks.org/enumerate-in-python/ l1 = ['eat', 'sleep', 'repeat'] s1 = 'geek' obj1 = enumerate(l1) obj2 = enumerate(s1) print "return type: ", type(obj1) print list(obj1) print list(enumerate(s1, 2)) ## in loops for ele in enumerate(l1): print ele print for index, ele in enume...
c5c9609392216f4b44066ab582d4876f0cb583c9
bismog/leetcode
/python/longest_substring_without_repeat_character.py
1,225
3.953125
4
#!/usr/bin/env python def find_longest_substring(raw): if not raw: return 0,None if len(raw) == 1: return 1,raw # i = left = cur_len = max_len = 0 i, left, cur_len, max_len = 0, 0, 0, 0 sub = '' collected_sub = {} max_sub = [] char_dict = {} while i<len(raw): ...
76ffeabe41ac120ee7ac5b6b77939efa710f65b9
VictoriaCheloshkina/my_python
/l3-l4/if_random_game.py
269
3.640625
4
from random import randint a=randint(0,4) b=int(input()) if a==b: print('Победа') else: print('Повторите ещё раз!') if a>b: print('Результат больше') else: print('Результат меньше')
649cf25dac3e32f91b4acb6a48459706b5c735ab
VictoriaCheloshkina/my_python
/l3-l4/str_n.py
192
3.796875
4
s = input('Введите строку: ') n = int(input('Введите число: ')) def fun1(s,n): if len(s) > n: return s.upper() else: return s print(fun1(s,n))
021ae5fb6f1d286eb9e71de324771ddef5aec5d6
Monali16/Assignments
/task4datastructure.py
269
4.03125
4
e_list = [2,4,6] odd_list=[1,3,5] for i in range(1,50): if(i%2==0): e_list.append(i) else: odd_list.append(i) print("even list:", e_list) print("odd list:", odd_list) k = int(input("Please enter the number between 1 to 50: "))
d49748f98dba66e65532bc359cc3321bb28d979c
aryanxk02/HackerRank-Solutions
/CodeChef DSA Series/pascalstriangle.py
457
3.859375
4
n = int(input()) lower = [1, 2, 1] final = [] if n==1: print([[1]]) elif n==2: print([[1], [1, 1]]) elif n==3: print([[1], [1, 1], [1, 2, 1]]) else: final = [[1], [1, 1], [1, 2, 1]] for i in range(n-3): upper = [1] for j in range(len(lower)-1): upper.append(...
c9be9a04471bb721c7bb573833837a3ec64367e5
aryanxk02/HackerRank-Solutions
/CodeChef DSA Series/Pair me.py
262
3.546875
4
t = int(input()) for i in range(t): x = list(map(int, input().split())) if x[0]+x[1] == x[2]: print("YES") elif x[0]+x[2] == x[1]: print("YES") elif x[1]+x[2] == x[0]: print("YES") else: print("NO")
c1618965e4ea279ffe382453a8ce0c6d68422699
aryanxk02/HackerRank-Solutions
/Problem Solving/3.py
193
3.609375
4
def mult(l): for i in range(n): l.append(int(input())) total = 1 for i in l: total = total * i print('Product :', total) n = int(input()) l = [] mult(l)
3118f5ad208d44d357d6ca9d3dc5a660d51cedc5
aryanxk02/HackerRank-Solutions
/Hackerrank/Swap Case.py
332
3.796875
4
# a = input() # l = a.split(' ') # j = ''.join(l) # for i in range(0, len(a)): # if i == i.lower() : # print(''.join([i.upper(i)])) def swap_case(s): x = (s.swapcase()) return x if __name__ == '__main__': s = input() result = swap_case(s) print(result) # a = input() # print(a...
e6b1027d2d666e0bce68cafa83223009306096b2
jasonfangmagic/Python_Basics
/machine_learning/2_Regression/P14-Part2-Regression/SVR.py
1,795
3.5
4
# Multiple Linear Regression # Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd # Importing the dataset dataset = pd.read_csv('machine_learning/2_Regression/P14-Part2-Regression/Section 8 - Polynomial Regression/Python/Position_Salaries.csv') X = dataset.iloc[:, 1:-1].val...
bbc6fba8c2ebda81450888c4016733269daed9f3
jasonfangmagic/Python_Basics
/machine_learning/8_Deep_Learning/ANN.py
2,584
3.8125
4
# Artificial Neural Network # Importing the libraries import numpy as np import pandas as pd import tensorflow as tf tf.__version__ # Part 1 - Data Preprocessing # Importing the dataset dataset = pd.read_csv('machine_learning/8_Deep_Learning/Section 35 - Artificial Neural Networks (ANN)/Python/Churn_Modelling.csv') ...
b62931d1e99fbd3ae3d875c70f24df54008b8919
WeirdistBuilds/DGM-3670
/OldScripts/Scripts/tools.py
12,816
3.8125
4
import maya.cmds as cmds import random class ToolKit: def __init__(self): pass def value_check(self, values): """ Checks values to ensure all values are of type float or int input: list return: list of only int or float values """ result =...
acf0171bc4d8a6d5312801e6eaf07ea002137ce7
kailen-hargenrader/Coding-Projects
/Python(With Turtle)/Roll Dice.py
434
4
4
import random count = 0 number = int(input("How many times would you like to roll 2 dice?: ")) for i in range(number): d1 = random.randint(0, 6) d2 = random.randint(0, 6) if d1 == d2: count+= 1 print(str(d1) + " " + str(d2)) print(str(count) + " double(s)") percent = float(count)*100/number print(str(pe...
a06a2c62765a37d82848398af7098a4ed207bcac
kailen-hargenrader/Coding-Projects
/HarvardX Intro to AI Coursework/TicTacToe/tictactoe.py
4,732
4
4
""" Tic Tac Toe Player """ import math X = "X" O = "O" EMPTY = None def initial_state(): """ Returns starting state of the board. """ return [[EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY]] def player(board): """ Returns player who has the next ...
b858cafd137fd2a70a8e5b36048fc5e40122ef01
dylburger/python-bootcamp
/scripts/random_pairs.py
946
3.78125
4
import random def pair_generator(filename): """Return an iterator of random pairs from a list of numbers.""" # Keep track of already generated pairs with open(filename, 'r') as f: students = set(f.read().splitlines()) paired_students = set() while students: pair = random.sample(...
a0cc9aac3080679741f15eb3cf29bd91931ca544
luo-simon/Wordlist-Generator
/wordlist_generator.py
1,945
4.0625
4
''' *** Wordlist Generator Fedora Project - Simon *** These are the rules being applied (based on research regarding effective rules): - Append 0...9 - Append 0...9 0...9 - Append 0...9 0...9 0...9 = append_numbers() - Uppercase - Title case = modify_case() - Substitute 'a' with '@' = sub_A() - 1337 mode (Hello...
af600a8503612f6f7c0ec2025707edf44086a818
Virajanidh/CO322-Data-structures-and-algorithms
/lab1/fib_i_java_plot.py
516
3.703125
4
# runtime values get from java iteration function is plotted seperatly import matplotlib.pyplot as plt import array y1=[3000,700,500,700,700,600,700,700,600,700,700,700,700,700,700,700,800,700,800,800,800,800,900,800,28200,1200,7800,15200,900,800,800,900,900,900,1000,1000,900,17400,900,1000,1000] x1=[] for z...
8e08df3064a353e35e91da014cdb472c74d09457
EwarJames/alx-higher_level_programming
/0x01-python-if_else_loops_functions/6-print_comb3.py
205
3.921875
4
#!/usr/bin/python3 for i in range(0, 10): for d in range(i + 1, 10): if i == 8 and d == 9: print("{}{}".format(i, d)) else: print("{}{}".format(i, d), end=", ")
34ad45e897f4b10154ccf0f0585c29e1e51ad2f8
EwarJames/alx-higher_level_programming
/0x0B-python-input_output/3-to_json_string.py
315
4.125
4
#!/usr/bin/python3 """Define a function that returns a json.""" import json def to_json_string(my_obj): """ Function that convert json to a string. Args: my_obj (str): Object to be converted. Return: JSON representation of an object (string) """ return json.dumps(my_obj)
d8de51f4144d49446f48c0c7d214552397039636
youssefhedefa/mad-libs
/mad.py
448
4
4
name = input("Your Name : ") from_where = input("Your country : ") birth_date = input("Your Birth date : ") love = input("what is you favorite hobby : ") learn = input("what do you learn : ") connect = input("how can we connect with you : ") paragraph = f"my name is {name},i am from {from_where} ,\ my birth day ...
d09aeb68e63cf04cf431c96e1af744d7a5fd8020
lloydarnold/project-euler
/problem_001.py
327
3.765625
4
## sum of multiples of 3 or 5 < 1000 def sum_multiples_lt(multOf, lessThan): i = 0 ; j = 0 ; sum = 0 while j < lessThan: sum += j ; i += 1 ; j = i * multOf return sum totalSum = sum_multiples_lt(3, 1000) + sum_multiples_lt(5, 1000) for i in range (1, 67): totalSum -= 15 * i print(to...
33b91659e0c6e9e55aee87255ce8acafdece030a
hanihaider1/Stocks
/final_stocks.py
9,137
3.84375
4
import pandas as pd import matplotlib.pyplot as plt class Stocks: ''' Attributes: stocks_ filename: this will have all the data for the stock which we want the data to be presented major_index : This will have the file **(please add info for it i don't know have what will the data have ) Met...
7f61009292028e505fe6d332e69f8cdb9113c5b0
Enigmagic/Idle-Weed-Clicker
/IdleWeedClicker005.py
8,029
3.625
4
from tkinter import * import time root = Tk() root.title("Idle Weed Clicker Version 0.0.5") # values weed = 0 weedpc = 1 weedps = 0 cashps = 0 xp = 0 doesclocktick = 0 # store prices weedupgcost = 50 sellupgcost = 50 valupgcost = 100 autogrow1cost = 25 autogrow1amount = 0 autosell1cost = 25 au...
18b20a12ad453929b2c6048ed6486beb31776ad7
JaehyunAhn/Python_Introduction
/[Py] Timer games/timer_game.py
2,263
3.515625
4
# template for "Stopwatch: The Game" import simplegui # define global variables time = 0 mil_second = 0 second = 0 minute = 0 success_s = 0 total_s = 0 stop_flag = False def setup_time(time): # define helper function format that converts time # in tenths of seconds into formatted string A:BC...
da7784a5f76cae546845d02e3c17c58c1657da65
pi408637535/Algorithm
/com/study/algorithm/daily/260. Single Number III.py
457
3.546875
4
from typing import List class Solution: def singleNumber(self, nums: List[int]) -> List[int]: eor = 0 for ele in nums: eor ^= ele right_only = eor & (~eor + 1) res = 0 for ele in nums: if ele & right_only != 0: res ^= ele retu...
d0141e9d1bcc7b945569983ffad80aed37f5bfa9
pi408637535/Algorithm
/com/study/algorithm/daily/424. Longest Repeating Character Replacement.py
2,000
3.59375
4
import collections class Solution: ''' 难点:1.如何确定sub数组中,最多的字符(dp中的f可以算连续) 2.当字符不一样时,如何解决扩充问题 ''' def characterReplacement(self, s: str, k: int) -> int: length = len(s) if length < 2: return length freq = [1] * 26 max_count = 0 #用于统计sub_string中字符出现次数最多的字母 ...
28de5e5e0e93c64b1a2552caf0a97f9bb3ca0768
pi408637535/Algorithm
/com/study/algorithm/offer/面试题 01.02. 判定是否互为字符重排.py
1,469
3.53125
4
class Solution(object): def CheckPermutation(self, s1, s2): """ :type s1: str :type s2: str :rtype: bool """ dic_s1 = {} dic_s2 = {} for ele in s1: dic_s1[ele] = dic_s1.get(ele,0) + 1 for ele in s2: dic_s2[ele] = dic_s...
b4c0ee58577cdea91d424cff0f69926db260de37
pi408637535/Algorithm
/com/study/algorithm/tree/Path Sum.py
1,139
3.828125
4
class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def hasPathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: bool """ if not root: retu...
4c28ba5cd901d92a3b1c69f16b124e937f3523ed
pi408637535/Algorithm
/com/study/algorithm/sorted_algorithm/bubble.py
475
3.921875
4
class Solution(object): def sortArray(self, nums): """ :type nums: List[int] :rtype: List[int] """ n = len(nums) for i in range(n): for j in range(i+1,n): if nums[i] > nums[j]: temp = nums[i] nums[i]...
c586d70ca535e549c0b7ece9217c6f3785b10073
pi408637535/Algorithm
/com/study/algorithm/binary_search/Search_in_Rotated_Sorted_Array.py
2,184
3.84375
4
# -*- coding: utf-8 -*- # @Time : 2020/6/3 10:19 # @Author : piguanghua # @FileName: Search_in_Rotated_Sorted_Array.py # @Software: PyCharm #两个问题:1.是否是正常段 2.target是否在里面 #https://www.jianshu.com/p/874e1d6a3156 class Solution(object): def search(self, nums, target): """ :type nums: List[int] ...
132a7051488a2313cedf938074551d4f98ec6064
pi408637535/Algorithm
/com/study/algorithm/daily/503. Next Greater Element II.py
1,401
3.5625
4
from typing import List ''' 1.如何解决循环问题 在circular array中,我们需要去循环数值。例如[3,2,1]. 但是至多循环一次就行。所以可以考虑使用 i <= 2 * n - 1这种方式 2.单调栈 单调栈存放元素要唯一。所以本题可以使用索引值来指代元素 单调栈性质: 右侧,首个满足要求的元素 ''' class Solution: def nextGreaterElements(self, nums: List[int]) -> List[int]: stack = [] ...
e5bed2c58223c7edaa9001d48a9486e844db9ded
pi408637535/Algorithm
/com/study/algorithm/arrays/Kth Largest Element in an Array.py
2,036
3.515625
4
import heapq class Solution(object): def findKthLargest(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ heap = [] for ele in nums: if len(heap) < k: heapq.heappush(heap, ele) else: ...
96c99c5e8ccad5dc71a097a64fc300a75af91add
pi408637535/Algorithm
/com/study/algorithm/daily/5709. Maximum Ascending Subarray Sum.py
1,173
3.53125
4
# finish from typing import List class Solution: def maxAscendingSum(self, nums: List[int]) -> int: if not nums: return 0 max_num = nums[0] n = len(nums) f = [0] * (n) f[0] = nums[0] for i in range(1, n): if nums[i] > nums[i-1]: ...
62fafb589b46b86fe10364387821215ce9836832
pi408637535/Algorithm
/com/study/algorithm/dp/coordinate/Triangle.py
1,031
3.640625
4
# -*- coding: utf-8 -*- # @Time : 2020/7/15 15:58 # @Author : piguanghua # @FileName: Triangle.py # @Software: PyCharm import numpy as np class Solution(object): def minimumTotal(self, triangle): """ :type triangle: List[List[int]] :rtype: int """ n = len(triangle) ...
16d00d1caa75d764ea7c0237e471605c73039185
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 57 - II. 和为s的连续正数序列.py
771
3.875
4
# -*- coding: utf-8 -*- # @Time : 2020/8/12 17:01 # @Author : piguanghua # @FileName: 剑指 Offer 57 - II. 和为s的连续正数序列.py # @Software: PyCharm class Solution(object): def findContinuousSequence(self, target): """ :type target: int :rtype: List[List[int]] """ ans = [] ...
574b2e0faa7cb71c695865ea596d10ca4373ee93
pi408637535/Algorithm
/com/study/algorithm/reference/Reverse Linked List II.py
3,929
3.921875
4
class ListNode(object): def __init__(self, val=0, next=None): self.val = val self.next = next class Solution(object): def reverseBetween(self, head, m, n): """ :type head: ListNode :type m: int :type n: int :rtype: ListNode """ dummy = Lis...
c8df630bf76452a47fbbcfc4b01498f5f890c80e
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 35. 复杂链表的复制.py
1,218
3.734375
4
# -*- coding: utf-8 -*- # @Time : 2020/8/10 17:00 # @Author : piguanghua # @FileName: 剑指 Offer 35. 复杂链表的复制.py # @Software: PyCharm # Definition for a Node. class Node: def __init__(self, x, next=None, random=None): self.val = int(x) self.next = next self.random = random class Solution...
a0969dfc22ed4afc68666f814da64d5439fdcdc7
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 68 - II. 二叉树的最近公共祖先.py
2,173
3.8125
4
class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def lowestCommonAncestor(self, root, p, q): """ :type root: TreeNode :type p: TreeNode :type q: TreeNode :rtype: TreeNode ...
e9c636d3a67cbcf1d343e5960cca1796613e1793
pi408637535/Algorithm
/com/study/algorithm/daily/919 · Meeting Room II.py
930
3.828125
4
class Interval(object): def __init__(self, start, end): self.start = start self.end = end import heapq class Solution: """ @param intervals: an array of meeting time intervals @return: the minimum number of conference rooms required """ def minMeetingRooms(self, intervals): ...
e10de385224675e3badd4f550bc46303beeb64eb
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 59 - I. 滑动窗口的最大值.py
634
3.8125
4
# -*- coding: utf-8 -*- # @Time : 2020/8/12 17:18 # @Author : piguanghua # @FileName: 剑指 Offer 59 - I. 滑动窗口的最大值.py # @Software: PyCharm import sys class Solution(object): def maxSlidingWindow(self, nums, k): """ :type nums: List[int] :type k: int :rtype: List[int] """ ...
73308dff4b4921c94b440721722748b05fe600f2
pi408637535/Algorithm
/com/study/algorithm/offer/面试题 01.01.判定字符是否唯一.py
393
3.59375
4
class Solution(object): def isUnique(self, astr): """ :type astr: str :rtype: bool """ res = 0 for ele in astr: temp = ord(ele) - ord('a') if 1 << temp & res != 0: return False else: res = 1 << temp | res return True if __n...
8438aab0ed6a9d5601b2d7477a2e73f121a281b4
pi408637535/Algorithm
/com/study/algorithm/daily/802. Find Eventual Safe States.py
3,786
3.546875
4
#思路:dfs ''' output degrees is zero is terminial node ''' import collections class Solution(object): def eventualSafeNodes(self, graph): """ :type graph: List[List[int]] :rtype: List[int] """ n = len(graph) degree = [0] * n tree = collections.defaultdict(l...
7d48f7a711080c6e46fedf5c552489441eaec148
pi408637535/Algorithm
/com/study/algorithm/daily/48. Rotate Image.py
788
3.90625
4
class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ n = len(matrix) m = len(matrix[0]) matrix_new = [ [0 for j in range(m)] for i in range(n)] # 对...
f80add3e9111cef2c45c50a1aa77f779f5185826
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 32 - II. 从上到下打印二叉树 II.py
1,609
3.75
4
# -*- coding: utf-8 -*- # @Time : 2020/8/10 14:35 # @Author : piguanghua # @FileName: 剑指 Offer 32 - II. 从上到下打印二叉树 II.py # @Software: PyCharm import collections class Solution(object): def __init__(self): self.queue = [] def levelOrder(self, root): """ :type root: TreeNode ...
431384abd81af78ff79355d261528645cf9c100b
pi408637535/Algorithm
/com/study/algorithm/daily/diameter-of-binary-tree.py
1,370
4.15625
4
''' 树基本是递归。 递归:四要素 本题思路:left+right=diameter https://www.lintcode.com/problem/diameter-of-binary-tree/description ''' #思路: #Definition of TreeNode: class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None class Solution: """ @param root: a r...
3aeeae19d749fff098e5baf532104818bf166105
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 58 - I. 翻转单词顺序.py
420
3.78125
4
class Solution(object): def reverseWords(self, s): """ :type s: str :rtype: str """ s = s.strip() data = [ ele for ele in s.split(" ") if ele != " " and ele != ''] data = data[::-1] return " ".join(data) if __name__ == '__main__': s = "the sky is...
c008a3bdc021986efe88fd9f8d4fb4c6a6632501
pi408637535/Algorithm
/com/study/algorithm/daily/766. Toeplitz Matrix.py
728
3.640625
4
import numpy as np from typing import List #本质:元素的左上角元素都相同 class Solution: def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: if not matrix or not matrix[0]: return True m, n = len(matrix), len(matrix[0]) for i in range(m): for j in range(n): ...
090a7589c64b3ade87ad23fe04d3e15e900d1672
pi408637535/Algorithm
/com/study/algorithm/daily/54. Spiral Matrix.py
1,052
3.609375
4
from typing import List class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: if not matrix or not matrix[0]: return [] m, n = len(matrix), len(matrix[0]) visited = [[False] * n for i in range(m) ] length = m * n k = 0 directions =...
69d71a1a6ab328e677a80380fd498b0129d582cd
pi408637535/Algorithm
/com/study/algorithm/tree/Binary Tree Maximum Path Sum.py
926
3.703125
4
class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None #技巧,如何保证二叉树路径不被走两次 import sys class Solution(object): def __init__(self): self.ans = -sys.maxsize def helper(self, root): if not root: return -sys.maxsize l = max(...
b605c9d28dfd635b66db2c32805da88110996f79
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 65. 不用加减乘除做加法.py
284
3.609375
4
class Solution(object): def add(self, a, b): """ :type a: int :type b: int :rtype: int """ c = a ^ b n = (a & b) << 1 return n + c if __name__ == '__main__': a = -10 b = -20 print( Solution().add(a, b) )
a0bed7c593134bdfdb5706efd76c001d69d827df
pi408637535/Algorithm
/com/study/algorithm/daily/655. Print Binary Tree.py
2,443
3.796875
4
from typing import List class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def getWidth(self, root): if not root: return 0 left = self.getWidth(root.left) right = se...
5a1acdece16c985bb248a231fe62c5605bdc4ea3
pi408637535/Algorithm
/com/study/algorithm/offer/剑指 Offer 25. 合并两个排序的链表.py
1,100
4
4
class ListNode(object): def __init__(self, x): self.val = x self.next = None class Solution(object): def mergeTwoLists(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ dummy = ListNode(0) pre = dummy ...
0bdbc795e77f49e71b6f870284e7619298813bb6
Cicciodev/EzPyGame
/ezpygame/scene.py
5,091
3.65625
4
class Scene: """An isolated scene which can be ran by an application. Create your own scene by subclassing and overriding any methods. The hosting :class:`.Application` instance is accessible through the :attr:`application` property. Example usage with two scenes interacting: .. code-block:: ...
a05d4c56c5636085df5662d5493af4287999cb69
antonplkv/itea_advanced_february
/lesson_4/abc_exmp.py
1,717
3.90625
4
from abc import abstractmethod, ABC class AbstractVehicle(ABC): @abstractmethod def drive(self): print('Driving') @abstractmethod def beep(self): print('BEEP!') class Vehicle(AbstractVehicle): def __init__(self, model, engine): self._model = model self._engine =...
203aea397838551ab2e739d89d63718526102534
nidhidivechavalu/KV-Material
/TKinter/button.py
499
4
4
# Importing Tkinter Module from tkinter import * # Create GUI Application Main Window window = Tk() # Adding Widgets And Configure Window window.geometry("512x512") window.title("KV Button Application") # Code Of Button def buttonClick(): print("Yeah.... You Have Clicked Me....") Button(text="Magic",background=...
a927877bec7e1f50885773b95d73951684c43c14
tb0700372/Script
/找空目录.py
468
3.5625
4
#!/usr/bin/env Python # -*- coding: UTF-8 -*- import os """ 找出路径下所有空目录 """ path = r"E:\Project\CSDN_Python\Week02\Work" def pathSize(path): ''' 得到路径参数,递归查找所有空目录 ''' fileList = os.listdir(path) if len(fileList)==0: print(path) for file in fileList: newPath = os.path.join(path, ...
64b9643395bb5d5a5f22fa50cb8d7fc0502567f0
Apurvapimparkar/Python
/Eval.py
83
3.546875
4
temp=eval(input('Enter a temperature celcius:')) print('Temp in F', (9/5)*temp+32)
3cdc7229d948641bd3f2f81b53a533f59ba30516
antonvasyuk/data-structures
/single-linked-list/single_linked_list.py
1,311
3.921875
4
class Node: def __init__(self, data): '''создание элемента списка''' self.data = data self.next = None class SingleLinkedList: def __init__(self): '''создание списка''' self.head = None self.tail = None def push(self, data): '''добавление эле...
f7f7b52bc28d00e63b826756aa557a0e78b32ee3
SauravJalui/data-structures-and-algorithms-in-python
/Binary Search Tree/BinarySearchTree.py
2,613
3.875
4
from queue_linkedlist import LinkedQueue class BinarySearchTree: class Node: __slots__ = "element", "left", "right" def __init__(self, element, left = None, right = None): self.element = element self.left = left self.right = right def __init__(self): ...
e3e9d96fbfcea9d640719624a47c8503b16c9033
SauravJalui/data-structures-and-algorithms-in-python
/LinkedList/doublelinkedlist.py
2,991
3.578125
4
from exceptions import Empty class DoublyLinkedList: class Node: __slots__ = "element", "prev", "next" def __init__(self, element, prev, next): self.element = element self.prev = prev self.next = next def __init__(self): self.head = self.Node(None, N...
714f5e573699fbcfbe26f144db77a5f0726ca990
CassinSackett/SNP_capture
/fastq_trimmer.py
765
3.640625
4
#!/usr/bin/python # Program goes through a FastQ file and trims from 75 onward (removes last 25 bp) # FastQ format: # Line 1: Sequence ID # Line 2: Sequence # Line 3: '+' (and repeat of sequence ID) # Line 4: Quality scores # import statements import string import sys # define functions def trimmer(line): if len(...
ce6ab7bc02a009197d467e8b6069122d18f63d96
mjschwenne/atlas
/src/Backend/Region.py
4,072
4.0625
4
from src.Backend.Polygon import Polygon class Region(Polygon): """ Region storing a list of Vertices and a District with functions to determine what the Region is in Attributes ---------- district : District The district of the Region vertices : list of Points The points that ...
b77ba10e155fdfb08c8fd501f9e21086e0e5cb64
mjschwenne/atlas
/src/Backend/Point.py
8,446
4.625
5
import math class Point: """ Point storing x and y coordinates with associated distance functions. Attributes ---------- x : float The point's x value. y : float The point's y value. Methods ------- set_x(x_new) Sets the x value of the point. set_y(y_n...
d2f4f0bc3a4e66ebad6983cb8d6eb70540d29e7b
veerasai18/Twitter_scrapper
/main.py
1,390
3.8125
4
# pip install tweepy if you don't have tweepy installed import tweepy import pandas as pd import time #user credentials to authenticate API #you will get these credentilas when creating a developer account on Twitter consumer_key = "cdxBcqlqkQMrlBJSbQa6NNrIh" consumer_secret = "ZJf84rcKXCTDe2M2h3eZYjUKzHQ2z2bi...
b1b8734d308d1636e5b6794c3b17a89f849a3fc6
dariasuslova/python_homework
/homework_1/task_3.py
324
3.625
4
class UniqObject: obj = None def __init__(self, name): self.name = name @classmethod def create_object(cls): if cls.obj is None: cls.obj = UniqObject('object') return cls.obj Singleton = UniqObject('object') print(Singleton.create_objec...
a4e48d9e8139f78bdbe323299d5cef40c663b588
PNeekeetah/Leetcode_Problems
/Combination_Sum.py
1,788
3.703125
4
# -*- coding: utf-8 -*- """ Created on Fri Mar 5 17:21:49 2021 @author: Nikita """ class Solution: def combinationSum(self, candidates: list(), target: int) -> list(list()): solution = list() def combo(curr_target,curr_sol,position): nonlocal solution, candidates if (curr_...
f2b2b1c9a6c111475e9f7dc0a92d762a8bda1e69
PNeekeetah/Leetcode_Problems
/Most_Profit_Assigning_Work.py
1,624
3.6875
4
# -*- coding: utf-8 -*- """ Created on Tue Mar 16 10:35:23 2021 @author: Nikita """ class Solution: def maxProfitAssignment1(self, difficulty, profit, worker): diff_and_profit = [] for diff,prof in zip(difficulty, profit): diff_and_profit.append((diff,prof)) diff_and_profit.sor...
48494013345d258fb17e1ba214f143b778a1f3bb
PNeekeetah/Leetcode_Problems
/Reverse_Words_in_a_String.py
683
3.609375
4
# -*- coding: utf-8 -*- """ Created on Tue Jun 29 22:17:09 2021 @author: Nikita """ """ Took me less than 10 minutes to code this. It beats 42% in terms of runtime and 0% in terms of memory. 4th time submission sucessful. The fact that I could have multiple white spaces tripped me. """ class Solution: def re...
c72b9ef840cd2737fd951764e469751d119884f5
PNeekeetah/Leetcode_Problems
/Next_Greater_Node_In_Linked_List.py
1,433
3.609375
4
# -*- coding: utf-8 -*- """ Created on Sun Apr 4 11:10:30 2021 @author: Nikita """ class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Solution: def nextLargerNodes(self, head: ListNode): #-> List[int]: Friend's solution v=[] ...
682e2b251cb91497b72aa066dba4415d3a51451d
PNeekeetah/Leetcode_Problems
/Count_Complete_Tree_Nodes.py
683
3.625
4
# -*- coding: utf-8 -*- """ Created on Sat Jun 12 15:54:55 2021 @author: Nikita """ """ Beats 5.46 in terms of runtime and 76.23% in terms of memory It took me 3 minutes 30 to solve it. """ class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left ...
17166e94a5b7d70158a2d27547b287114c6d0601
PNeekeetah/Leetcode_Problems
/Contest/Check_if_Binary_String_Has_at_Most_One_Segment_of_Ones.py
900
3.578125
4
# -*- coding: utf-8 -*- """ Created on Sun Mar 7 17:49:14 2021 @author: Nikita """ class Solution: def checkOnesSegment(self, s: str) -> bool: number = int(s,2) if (number % 2 == 0): while ( number % 2 == 0): number //= 2 while ( number % 2 == 1): ...
94789dc05dfda60945baf5c051a14829f5c5ffab
PNeekeetah/Leetcode_Problems
/Fizz_Buzz.py
1,143
3.875
4
# -*- coding: utf-8 -*- """ Created on Thu Oct 29 02:10:25 2020 @author: Nikita """ n1 = 15 class Solution(): def __init__(self): None def fizzBuzz (self, n: int) -> list: fblist = [] for elem in range(1,n+1): if (elem%3 == 0 and elem%5 == 0): ...
7a4c2819f42a1bb5709df9830bff7b621ddf7103
PNeekeetah/Leetcode_Problems
/First_Unique_Character_in_a_String.py
2,951
3.5625
4
# -*- coding: utf-8 -*- """ Created on Tue Nov 3 17:38:19 2020 @author: Nikita """ """ Second attempt beats 14.54% in terms of runtime and 0% in terms of memory. First time submisssion succesful. I marked it with # attempt 2 """ class Solution: def __init__(self) -> None: pass def firstU...
bdc5e301cbdba557cadbbb8dd256b9d97634a5aa
PNeekeetah/Leetcode_Problems
/Intersection_of_Two_Arrays_II.py
3,025
3.984375
4
# -*- coding: utf-8 -*- """ Created on Tue Oct 27 22:03:07 2020 @author: Nikita """ """ 1. Iterate through the first list 2. Create a new entry in a dictionary where you append 1 whenever you encounter the element 3. Repeat steps 1-2 for list 2, but append 2 rather than 1 4. Select smaller list 5. Create a set fro...