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
98e28e359e25217a5e70f2c9669fab5d302f4f24
zhouyuhangnju/freshLeetcode
/Length of Last Word.py
319
3.9375
4
def lengthOfLastWord(s): """ :type s: str :rtype: int """ words = s.split(' ') res = 0 for i in range(len(words)-1, -1, -1): if len(words[i]) > 0: res = len(words[i]) break return res if __name__ == '__main__': print lengthOfLastWord('aaaa ')
64a2774b9be616d89077fdea4c6cffb974272981
zhouyuhangnju/freshLeetcode
/Multiply Strings.py
764
3.578125
4
def multiply(num1, num2): """ :type num1: str :type num2: str :rtype: str """ res = [0] * (len(num1) + len(num2)) for i in range(len(num1)-1, -1, -1): carry = 0 for j in range(len(num2)-1, -1, -1): print i, j, tmpres = int(num1[i]) * int(num2[j]) + c...
99f280cbf763611fd31ef647fe6aab135d54155a
zhouyuhangnju/freshLeetcode
/Best Time to Buy and Sell Stock.py
337
3.859375
4
def maxProfit(prices): """ :type prices: List[int] :rtype: int """ buyprice = 2**31-1 profit = 0 for i in range(len(prices)): buyprice = min(buyprice, prices[i]) profit = max(profit, prices[i] - buyprice) return profit if __name__ == '__main__': print maxProfit([7...
1936d952a8761e5e73c9946fdc7d9bdc37886e9f
zhouyuhangnju/freshLeetcode
/Pascal's Triangle.py
480
3.578125
4
def generate(numRows): """ :type numRows: int :rtype: List[List[int]] """ res = [] if numRows <= 0: return res res.append([1]) for i in range(1, numRows): preres = res[-1] currres = [] currres.append(1) for j in range(len(preres)-1): ...
0437daed01bce0f5a3046616917a2c29a1ed15d0
zhouyuhangnju/freshLeetcode
/Combination Sum.py
1,252
3.71875
4
def combinationSum(candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ res = [] candidates = sorted(candidates) def combinationRemain(remain, curr_res): if remain == 0: res.append(curr_res) return ...
de630b1e32d6ef9285d0b52a41c44c21395469b7
teckMUk/CodeWars
/RomanNumbers/RomanNumbers.py
1,499
3.609375
4
import sys def solution(n): # TODO convert int to roman string roman_dict = {1:"I",5:"V",10:"X",50:"L",100:"C",500:"D",1000:"M"} x = str(n) roman_value = "" for num in reversed(range(len(x))): postion = pow(10,num) res = int(n/postion) res = res*postion if res==0: ...
4e3523f91eb5fbc31870525547e6cdbb2288e39c
Code4Bugs/APSSDC-Python-Training-2019
/function.py
257
3.796875
4
def star(n): return "* "*n for i in range(6): for j in range(6): if i<=j: print(star(j)+" ") break for i in range(6): for j in range(6): if j<=i: print(star(5-i)) break
2f2020646ec5fd3b3b9a2b86819e568ac3acbb2c
Code4Bugs/APSSDC-Python-Training-2019
/whileloop.py
95
3.84375
4
n=int(input("enter number : ")) i=1 sum=0 while i<=n: sum=sum+i i+=1 print(sum)
589622c55a74eca1fc73975a0a765d941516878c
wohao/cookbook
/file5_1.py
1,759
3.515625
4
with open('somefile.txt','wt') as f: f.write('I Love You') f = open('somefile.txt','rt') data = f.read() f.close() with open('D:\python\cookbook\somefile.txt','wt') as f: print('Hello world!',file=f) print('ACME',50,91.5) print('ACME',50,91.5, sep='') print('ACME',50,91.5, sep=',') print('ACME',50,91.5, sep='',en...
fb801c2f3b6afaab1a64650d8a10811d0726a5e7
wohao/cookbook
/counter1_12.py
563
4.15625
4
from collections import Counter words = [ 'look', 'into', 'my', 'eyes', 'look', 'into', 'my', 'eyes', 'the', 'eyes', 'the', 'eyes', 'the', 'eyes', 'not', 'around', 'the', 'eyes', "don't", 'look', 'around', 'the', 'eyes', 'look', 'into', 'my', 'eyes', "you're", 'under' ] word_counters = Counter(word...
33786128937eb324ac6fed3d932c6ee6d3cc9e70
nsambold/solutions
/codewars/Python/5kyu/anagrams.py
491
4.09375
4
# anagrams.py __author__ = awakenedhaki from typing import List def anagrams(word: str, words: List[str]) -> List[str]: ''' Returns all anagrams of a word in a list of words. :param word: str :param words: List of str :return: Returns a list of words that are anagrams ''' word: str = sor...
34ce63cd53249aba4a901cf6324418641fb2c822
masterace007/codeforces_harwest
/atcoder/abc186/C.py
461
3.734375
4
n = int(input()) count_7_decimal = 0 count_7_octal = 0 count = n; text = "" common_od = set() for i in range(1,n+1): text = str(i); if '7' in text: common_od.add(i) #count_7_decimal = count_7_decimal + 1 text = "" for i in range(1,n+1): text = str(oct(int(i))); if '7' in text: c...
afcfc4ab4dd8196bfe5ab57ae2ebe2a064e3840e
Im-Hal-9K/python_training
/ex40.py
707
3.78125
4
# This is the fortieth exercise. # Date: 2014-06-27 class Song(object): def __init__(self, lyrics): self.lyrics = lyrics def sing_me_a_song(self): for line in self.lyrics: print line def length(self): print len(self.lyrics) happy_bday = Song(["Happy birthday to you",...
df4a4165ed70cee917e537eb19b1ed040703dbc7
Craby4GitHub/CIS129
/Mod 2 Pseudocode 2.py
2,879
4.3125
4
######################################################################################################################## # William Crabtree # # 27Feb17 ...
4b1ae200aa26d0259e03ec346abdb42c4671b26b
Craby4GitHub/CIS129
/Final/Final.py
2,265
4.1875
4
######################################################################################################################## # William Crabtree # # 26Apr17 ...
0c6fcf179c696e2456889b9b608c3a40acc0d2e3
WarrenJames/LPTHWExercises
/morecodecademy.py
1,526
3.953125
4
# Conditional Statement Syntax """ 'if' is a conditional statement that executes some specified code after checking if its expression is True """ # define function(): which consists of # if True: return to the user "Success #1" def using_control_once(): if 32 <= 4**4: return "Success #1" # define function(...
75c9f003fff66ac0040f72abcbf582ebeb098632
WarrenJames/LPTHWExercises
/exl12.py
950
3.84375
4
# Excercise 12: Prompting People # variable age is equal to raw_input with prompt of "How old are you? " age = raw_input("How old are you? ") # variable height is equal to raw_input with prompt of "How tall are you? " height = raw_input("How tall are you? ") # variable weight is equal to raw_input with prompt of "Ho...
b0666fa53d392b325bafe7d6ae5f9f259cda7a13
WarrenJames/LPTHWExercises
/numgame.py
826
3.90625
4
import random secretNum = random.randint(1, 10) guesses = [] def game(): while len(guesses) < 5: try: guess = int(raw_input("Guess a number between 1 and 10: ")) except ValueError: print "That isn't a number." else: if guess == secretNum: ...
0c7c129434bb1a73f9d5e70413356a68ccbe6541
WarrenJames/LPTHWExercises
/exl38.py
2,061
4.09375
4
# Exercise 38: Doing things to Lists import random # creates variable with string of text "Apples Oranges Crows Telephone Light Sugar" ten_things = "Apples Oranges Crows Telephone Light Sugar" # prints "Wait there are not 10 things in that list. Let's fix that." print "Wait there are not 10 things in that list. Let's...
f5f85d737006dc462254a2926d4d7db88db72cb6
WarrenJames/LPTHWExercises
/exl9.py
1,005
4.28125
4
# Excercise 9: Printing, Printing, Printing # variable "days" is equal to "Mon Tue Wed Thu Fri Sat Sun" days = "Mon Tue Wed Thu Fri Sat Sun" # variable "months" is Jan Feb Mar Apr May Jun Aug seperated by \n # \n means words written next will be printed on new a line months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nAug" # p...
64303bcf3bb4a4f8750babc4a23940d19bcf1366
WarrenJames/LPTHWExercises
/exl19redone.py
1,370
4.03125
4
# Exercise 19: Study drill # Create a function of my own design and run it 10 different ways from sys import argv script, filename = argv def bottles_of_beer(on_the_wall, bottles_to_go): print """%s bottles of beer on the wall\n%s bottles of beer! Take one down, pass it around %s bottles of beer""" % (on_the_...
e6f1bf912c575ed81b4b0631514ee67943a26f2f
WarrenJames/LPTHWExercises
/exl18.py
1,977
4.875
5
# Excercise 18: Names, Variables, Code, Functions # Functions do three things: # They name pieces of code the way variables name strings and numbers. # They take arguments the way your scripts take argv # Using 1 and 2 they let you make your own "mini-scripts" or "tiny commands" # First we tell python we want to...
fd90e5312f0798ca3eb88c8139bdd2fe17786654
SaloniSwagata/DSA
/Tree/balance.py
1,147
4.15625
4
# Calculate the height of a binary tree. Assuming root is at height 1 def heightTree(root): if root is None: return 0 leftH = heightTree(root.left) rightH = heightTree(root.right) H = max(leftH,rightH) # height of the tree will be the maximum of the heights of left subtree and right subtr...
4af84efdf7b997185c340f2b69e7873d5b87df73
SaloniSwagata/DSA
/Tree/BasicTree.py
1,377
4.1875
4
# Creating and printing a binary tree # Creating a binary tree node class BinaryTreeNode: def __init__(self,data): self.left = None self.data = data self.right = None # Creating a tree by taking input tree wise (i.e, root - left subtree - right subtree) # For None, the user enters -1 def ...
c868093ac8ba3e14bad9835728fcc45598e0dfd5
SaloniSwagata/DSA
/Tree/levelOrder.py
1,309
4.25
4
# Taking input level order wise using queue # Creating a binary tree node class BinaryTreeNode: def __init__(self,data): self.left = None self.data = data self.right = None import queue # Taking Level Order Input def levelInput(): rootData = int(input("Enter the root node data: ")) ...
90120ad0fd9d5ffc0f4963c184a027fd32aa8f9d
SaloniSwagata/DSA
/Dynamic Programming/knapsack_memo.py
1,312
3.640625
4
#now we convert the recursive code into meoization #for memoization we have to make a matrix #where row and columns are the changable parameters arr = [] row = 4 #we take this value with the help of contstrains columns = 52 #this value also taken from constraints for i in range(row): col = [] for j in range(columns...
064012613d9281287932b73cfd4db3c5d6055c83
woutboat/Project-Euler
/working/052.py
507
3.65625
4
def testMult(num, mux): return num * mux def sum_digits(n): s = 0 while n: s += n % 10 n //= 10 return s potato = True num = 125875 counter = 0 while potato: if sum_digits(num) == sum_digits(testMult(num, 2)): if sum_digits(num) == sum_digits(testMult(num, 3)): if sum_digits(num) == sum_digits(testMul...
526638e90298bbb4278bd5b234a375f931d59868
woutboat/Project-Euler
/027.py
988
3.734375
4
import time def primeFind(number): oldnum = number factor = 1 while number > 1: factor += 1 if number % factor == 0: if 1 < factor < oldnum: print("Returned False") return False # is not prime number //= factor return True # is pri...
80c5b40067d54f809a8dc24237b1aef8a77870b9
woutboat/Project-Euler
/working/029.py
282
3.875
4
#distinct answers for a^b where 2 <= a <= 100 and 2 <= b <= 100 numbers = [] for a in range(2,101): for b in range(2,101): print(str(a) + " " + str(b)) numbers.append(a ** b) print("Removing repeats") numbers = sorted(set(numbers)) print(str(len(numbers))) #Answeer 9183
7880ee09e3f4e8425a814265508135661127dada
arthurazs/uri
/c/1017.py
86
3.765625
4
time = int(input()) speed = int(input()) print('{:.3f}'.format((time * speed) / 12))
38b369d86a9fd1397d2edbfa25b9a7635b9d431c
kevhunte/Academic-Projects
/oop_city.py
2,292
3.890625
4
import random, sys firstnames = ['Bobby','James','Kevin','Lisa','Mary','Diane','Joan','Garret','Sila','Gordon','Michael','David'] lastnames = ['Johnson','Hunt','Katz','Marley','Roberson','Smith'] class Person(): population = 0 def __init__(self, first = None, last = None, age = None): if(first an...
c054ecfee06ec508de88efe67246bfa47ba93085
unicefuganda/rapidsms-generic
/generic/reports.py
3,232
3.75
4
from .utils import flatten_list, set_default_dates class Column(object): def add_to_report(self, report, key, dictionary): pass class Report(object): """ A report was found to be a useful callable for more complicated aggregate reports, in which each column of the report is a complicated que...
65db0ad60b8ae2b5e772ff2f19872703a517b089
Sudeep-K/hello-world
/Automating Tasks/Spreadsheet Cell Inverter.py
814
3.984375
4
#! python3 # Spreadsheet Cell Inverter.py - invert the row and column of the cells in the spreadsheet. import openpyxl # create two workbook 'wb' for original file and 'wb2' a blank workbook for storing inverted sheet wb = openpyxl.load_workbook('F:\\python\\example.xlsx') wb2 = openpyxl.Workbook() sheet1 ...
bb658c8b753d83cd676804dbb504db3a659ff05c
Sudeep-K/hello-world
/Automating Tasks/multiplicationTable.py
1,260
4.0625
4
#! python3 # multiplicationTable.py - takes a number N from the command line and # creates an N×N multiplication table in an Excel spreadsheet. import openpyxl, sys from openpyxl.styles import NamedStyle, Font #store the N to variable named 'N' if len(sys.argv) > 1: N = int(sys.argv[1]) #create a new wor...
dbd90779db40037c1cdf29d85485c84b397405fc
Sudeep-K/hello-world
/Automating Tasks/Mad Libs.py
1,445
4.5
4
#! python ''' Create a Mad Libs program that reads in text files and lets the user add their own text anywhere the word ADJECTIVE, NOUN, ADVERB, or VERB appears in the text file. The program would find these occurrences and prompt the user to replace them. The results should be printed to the screen and saved to...
755371b69db100b2b309f216273a0bfa0a861d89
SohaHussain/Python-visualisation
/coursera_week3.py
12,383
4.46875
4
# Subplots import matplotlib.pyplot as plt import numpy as np # If we look at the subplot documentation, we see that the first argument is the number of rows, the second the number # of columns, and the third is the plot number. # In matplotlib, a conceptual grid is overlayed on the figure. And a subplot command all...
f037ac24bce609e36980347f01fbb22e8be42657
nest-lab/Cosmic-Nestlab-FDay
/problem6.py
284
3.984375
4
def is_anagram(s1,s2): a = len(s1) b = len(s2) if a == b: for l in s1: if l in s2: return True return False string_1 = raw_input("Enter any string: ") string_2 = raw_input("Enter any string: ") print is_anagram(string_1, string_2)
b98306cce6acc5e3a85fc390204286ea7d39eba4
TimZeng/Python-practice
/Object_Oriented_Programming.py
2,171
4.0625
4
class Fraction(object): """ A number represented as a fraction """ def __init__(self, num, denom): """ num and denom are integers """ assert type(num) == int and type(denom) == int, "ints not used" self.num = num self.denom = denom self.reduce() def reduce(s...
626a4941c3ba6437fbd1301a1a12e05fbe0b284c
ruizj3/facebook_message_parser
/fb_chat.py
15,857
3.84375
4
import datetime class Chat(object): """An object to encapsulate the entire Facebook Message history. - Contains a list of Thread objects, which can be accessed using item accessing Chat["Thread Name"] style. - When initialising, 'myname' should be the name of the user, and 'threads' ...
11e03d080050f7c7e88648c68451d826820c95a1
andreatta/2D_matrix
/create2Dmatrix.py
3,379
3.546875
4
#!/usr/bin/env python """ Create 2D Matrix bitmpap from Ferag String. """ import re import os.path import argparse import codecs from PIL import Image PATTERN = r"\{SK\|(\d+)\|(\d+)\|(\d+)\|([\s\S]+)\}" FONT = [] parser = argparse.ArgumentParser() parser.add_argument('file', nargs='?', default='2DMatrix.bin') args =...
3942be2adf64c4d9ff0ec29bc562014e7d6b43cb
JoneLn/project2_pandas
/Python数据分析从入门到精通/MR/Code/03/41/demo.py
293
3.78125
4
from pandas import Series #从pandas引入Series对象,就可以直接使用Series对象了,如Series([88,60,75],index=[1,2,3]) s1=Series([88,60,75],index=[1,2,3]) print(s1) print(s1.reindex([1,2,3,4,5])) #重新设置索引,NaN以0填充 print(s1.reindex([1,2,3,4,5],fill_value=0))
e1b59e4b26347d0e067fa73b68c4df8dba94a0d3
JoneLn/project2_pandas
/Python数据分析从入门到精通/MR/Code/08/46/demo.py
178
3.578125
4
import numpy as np #创建矩阵 data1= np.mat([[1, 2], [3, 4],[5,6]]) data2=np.mat([1,2]) print(data1-data2) #矩阵减法法运算 print(data1/data2) #矩阵除法运算
5a5941f0967ed5510e28f210dbc5dea3cafb4d01
JoneLn/project2_pandas
/Python数据分析从入门到精通/MR/Code/08/32/demo.py
136
3.734375
4
import numpy as np #创建3行4列的二维数组 n=np.array([[0,1,2,3],[4,5,6,7],[8,9,10,11]]) print(n[1]) print(n[1,2]) print(n[-1])
4b01fdcfb56d1acaf43d6601e9c836ecb5fe5410
JoneLn/project2_pandas
/Python数据分析从入门到精通/MR/Code/04/28/demo.py
286
3.5
4
import pandas as pd df = pd.DataFrame({'a':[1,2,3,4,5], 'b':[(1,2), (3,4),(5,6),(7,8),(9,10)]}) print(df) # apply函数分割元组 df[['b1', 'b2']] = df['b'].apply(pd.Series) print(df) #或者join方法结合apply函数分割元组 #df= df.join(df['b'].apply(pd.Series)) #print(df)
0696d0acdb4fa1b26b9f31760b6e01717f959bbf
JoneLn/project2_pandas
/Python数据分析从入门到精通/MR/Code/03/09/demo.py
295
3.8125
4
import pandas as pd data = [[110,105,99],[105,88,115],[109,120,130]] index = [0,1,2] columns = ['语文','数学','英语'] df = pd.DataFrame(data=data, index=index,columns=columns) print(df) #遍历DataFrame表格数据的每一列 for col in df.columns: series = df[col] print(series)
e10c4cd35fce90bc44dbb4dd3ffaf75b13adcaa9
harishvinukumar/Practice-repo
/Break the code.py
1,503
4.28125
4
import random print('''\t\t\t\t\t\t\t\t### --- CODEBREAKER --- ### \t\t\t\t\t1. The computer will think of 3 digit number that has no repeating digits. \t\t\t\t\t2. You will then guess a 3 digit number \t\t\t\t\t3. The computer will then give back clues, the possible clues are: \t\t\t\t\tClose: You've guessed a corre...
bc28d90671f845043771f4154ca9f227101bd521
weigelb1988/projectEuler
/python/problem19.py
972
3.859375
4
# You are given the following information, but you may prefer to do some research for yourself. # # 1 Jan 1900 was a Monday. # Thirty days has September, # April, June and November. # All the rest have thirty-one, # Saving February alone, # Which has twenty-eight, rain or shine. # And on leap years...
a70c316aaa8edc181caca26f2173c277d9813bde
weigelb1988/projectEuler
/python/problem24.py
1,324
4.03125
4
# function to swap array elements fullList = [] count = 0 def swap (v=[], i=0, j=0): t=0 t = v[i] v[i] = v[j] v[j] = t # recursive function to generate permutations def perm (v=[], n=0, i=0): # this function generates the permutations of the array # from element i to element n-1 # ...
af069f0404ed5594b2fb77da8613ebda76b8c040
DreamHackchosenone/python-algorithm
/binary_tree/traversing.py
1,311
4.1875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/3/19 22:10 class TreeNode(object): # 定义树结构 def __init__(self, root=None, left=None, right=None): self.root = root self.left = left self.right = right def preorder_traverse(tree): # 递归遍历顺序:根->左->右 if tree is None:...
ddb08e49497c629955107ca654146485a21eaeab
balajisomasale/Hacker-Rank
/Python/03 Sets/01 Introduction to Sets.py
313
3.859375
4
def average(array): # your code goes here count=0 n1=0 s1=set(array) for item in s1: count+=item n1+=1 return count/n1 if __name__ == '__main__': n = int(input()) arr = list(map(int, input().split())) result = average(arr) print(result)
432238cc169768713e448629b0c909d8577aa410
balajisomasale/Hacker-Rank
/30 Days of Code Python/06 Even and Odd Index Strings .py
325
3.71875
4
# Enter your code here. Read input from STDIN. Print output to STDOUT n=int(input()) for i in range(n): name=str(input()) mylist=list(name) result=("".join(mylist[::2])) result2=("".join(mylist[1::2])) print(result+" "+result2) ...
e8d1bdad2417a751ffe3baa29ffa62c8894c94f8
balajisomasale/Hacker-Rank
/Python/03 Sets/Set .union() Operation.py
200
3.578125
4
# Enter your code here. Read input from STDIN. Print output to STDOUT n=input() students = set(map(int,input().split())) b=input() b1=set(map(int,input().split())) print(len(students.union(b1)))
d3b12b7ac69eb02b0f0416e90c96ccdd91a5d886
brandoncfsx/OpenCV
/simple_thresholding.py
2,234
3.65625
4
import numpy as np import argparse import cv2 ap = argparse.ArgumentParser() ap.add_argument('-i', '--image', required=True, help='Path to the image.') ap.add_argument('-t', '--threshold', type=int, default=128, help='Threshold value.') args = vars(ap.parse_args()) image = cv2.imread(args['image']) image = cv2.cvtCol...
42cd6a6b4f83acd0f4ff49c8916b8c86ebaaf8bb
brandoncfsx/OpenCV
/shapedetector.py
1,248
3.75
4
import cv2 class ShapeDetector: def __init__(self): pass def detect(self, c): # Initialize shape's name and approximate contour based on the contour input. shape = 'Unknown' # First compute the perimeter of the contour. peri = cv2.arcLength(c, True) # Contour a...
e2eae931e495e69dbebcd02835ef1779a5f95f15
weiyinfu/learnMatplotlib
/动画/掉在地上的皮球.py
815
3.515625
4
import pylab as plt from matplotlib.animation import FuncAnimation fig = plt.figure(figsize=(3, 3)) x, y = 0, 2 # 小球的位置 v = 0 # 小球的速度 p = plt.scatter(x, y, s=500) # 把小球画出来 plt.plot([-1, 1], (-0.25, -0.25)) # 画一条地平线 dt = 0.1 # 每个间隔的时间 g = 1 # 重力系数 def update(frame_index): global y, v need_time = ((v * v...
c4084cb912f3cfb50941c976ef2d16120ff4b6b1
weiyinfu/learnMatplotlib
/110-cbook模块函数注册.py
432
3.515625
4
""" cbook即为cookbook,是一些小工具组成的库 """ from matplotlib.cbook import CallbackRegistry callbacks = CallbackRegistry() sum = lambda x, y: print(f'{x}+{y}={x + y}') mul = lambda x, y: print(f"{x} * {y}={x * y}") id_sum = callbacks.connect("sum", sum) id_mul = callbacks.connect("mul", mul) callbacks.process('sum', 3, 4) callb...
b099354a6fac9fee379d1b066c7b93bc329d0564
fudong1127/PyLimitBook
/orderList.py
1,861
3.71875
4
#!/usr/bin/python from order import Order class OrderList(object): def __init__(self): self.headOrder = None self.tailOrder = None self.length = 0 self.volume = 0 # Total share volume self.last = None def __len__(self): return self.length def __iter__(self): self.last = self.headOrder return sel...
fed641241861ce73df700305c6926319647d5b39
JHorwitz1011/DFA2020-2021-UCP
/Experimental Input/PongOpenCV.py
6,730
3.53125
4
# Simple Pong in Python 3 for Beginners # By @TokyoEdTech # Part 10: Simplifying Your Code (One Year and a Half Later!) import turtle import imutils from cv2 import cv2 as cv FRAME_WIDTH = 800 FRAME_HEIGHT = 800 RADIUS = 25 FRAMES_NEEDED = 5 frame_count_up = 0 frame_count_down = 0 #Currently set to a green object f...
00bbf91aae928270723a1fae3c252ab67929139c
111111xiao/tf_keras_cnn_handwritten_recognition
/module/calcul.py
8,926
3.578125
4
import math def calculator(l1): list_number = [] list_operator = [] list_power = [0] sum = j = flag = 0 power = 1 for i in l1: if i == '=': flag = 1 if i != '+' and i != '-' and i != '*' and i != '/' and i != '=' and i != '^': sum = sum * 10 + float(i) ...
228cb176446af1f696ea57220eedd81e0ab97f3b
zhouf1234/untitled8
/BeautifulSoup-demo30.py
3,597
3.796875
4
from bs4 import BeautifulSoup soup = BeautifulSoup('<p>Hello</p>','lxml') print(soup.p.string) #Hello print() html=''' <html><head><title>The Dormouse's story</title></head> <body> <p class="title" name="dormouse"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; ...
d68a6d351de04e57ba60432ac1e2e1191c68b238
zhouf1234/untitled8
/空值测试2.py
307
3.953125
4
# keys = ['a', 'b', 'c'] # values = [1, 2, 3] # v = [11, 22, 33] # dictionary = list(zip(keys, values,v)) # print(dictionary) # for i in dictionary: # for j in i: # print(j) # list = [] # for i in range(1,10): # print(i) # if i not in list: # list.append(i) # print(list)
2b25649637cefbdec2e8e389202a08fd82dbf1f0
ramyagoel98/acadview-assignments
/assignment11.py
651
4.28125
4
#Regular Expressions: #Question 1: Valid Emaild Address: import re as r email = input("Enter the E-mail ID: ") matcher = r.finditer('^[a-z][a-zA-Z0-9]*[@](gmail.com|yahoo.com)', email) count = 0 for i in matcher: count += 1 if count == 1: print('Valid E-mail Address') else: print('Inval...
f880fb9bda8b4b9a9efe35ef53b62c9de6ed6caa
josterpi/AdventOfCode
/year2020/day7.py
1,182
3.59375
4
def parse_input(filename): rules = {} with open(filename) as f: for line in f: bag, spec = line.strip(".\n").split(" bags contain ") bag_rules = {} if spec != "no other bags": for part in spec.split(", "): part = part.split()[:-1]...
f875225db753a4100d62aa08f1a76db0bfbcf1cc
josterpi/AdventOfCode
/day2.py
523
3.59375
4
def main(): input = [line.strip().split() for line in open("input/day2.txt")] x, y = 0, 0 y2, aim = 0, 0 for direction, units in input: units = int(units) if direction == "forward": x += units y2 += units * aim if direction == "up": y -= units...
e031bcc758f86d335c787fe87cccc70cf37306e2
LucianoJunnior/Python
/Python/(média)ex008.py
258
3.765625
4
medida = float(input('Digite a Medida em Kilometros \n' )) cm = medida*100 mm = medida*1000 dc = medida/100 hc = medida/1000 print('A medida de {:.1f}km coresponden a {:.1f}cm , {:.1f}mm, {} Devimetros,{} Hectometros. '.format(medida, cm, mm, dc, hc))
0da902b8ef7b15740fa920bdd6c02fbc3d8daf6c
prkprime/trimester-8
/IS/rsa_implementation.py
1,627
3.84375
4
""" Name : Pratik Gorade Year : T.Y. B.Tech Panel : 2 Batch : B2 Roll No. : PB02 Usage : python3 rsa_implementation.py """ from math import sqrt from itertools import count, islice def gcd(a, b): #returns relative GCD of a and b if b == 0: return a else: return gcd(b, a%b) def isPrime(n)...
97aa8452a4bab355d139eed764ebfd5f692ab06b
shaikzia/Classes
/yt1_cor_classes.py
691
4.21875
4
# Program from Youtube Videos - corey schafer """ Tut1 - Classes and Instances """ #Defining the class class Employee: def __init__(self,first,last,pay): self.first = first self.last = last self.pay = pay self.email = first + '.' + last + '@company.com' def fullname(self): ...
94d737b1eb5d4fa7d9714e85c7c3fd2f925077a0
lukasbindreiter/enternot-pi
/enternot_app/pi/distance.py
774
4.125
4
from math import sin, cos, sqrt, atan2, radians def calculate_distance(lon1: float, lat1: float, lon2: float, lat2: float) -> float: """ Calculate the distance in meters between the two given geo locations. Args: lon1: Longitude from -180 to 180 lat1: Latitude from ...
ab105ea16b1b7eaa79ded84ca64dd55396f972e7
armenuhiarakelyan1978/python_task
/x.py
175
3.796875
4
#!/usr/bin/python n1 = int(input("Input int ")) n2 = 0 while n1 > 0: digit = n1 % 10 n1 = n1 / 10 print (n1) n2 = n2 * 10 n2 = n2 + digit print (n2)
1d7925d3427de20e82b1c1796e9d29468fe2dc59
amirkhan1092/competitive-coding
/leap_year.py
108
3.65625
4
def leap_year(y): return y%4 == 0 and y%100 != 0 or y%400 == 0 k = int(input()) print(leap_year(k))
86b51ad1d4b4282943a6e8282735985cecb6d6ea
amirkhan1092/competitive-coding
/jumbuled_sequence.py
503
4.09375
4
# This problem was asked by Pinterest. # # The sequence [0, 1, ..., N] has been jumbled, and the only clue you have for its order # is an array representing whether each number is larger or smaller than the last. Given this information, # reconstruct an array that is consistent with it. For example, given [None, +, +, ...
4e1c6f197f7e099b7ef3cc2c520343b5a48da64f
amirkhan1092/competitive-coding
/substring_anagram.py
551
3.984375
4
# substring anagram in a given string with all matches def substring_anagram(dictionary: list, sub: list) -> None: dictionary_sort = list(map(sorted, dictionary)) sub_sort = map(sorted, sub) m = [] for i in sub_sort: m.append(dictionary_sort.count(i)) return m # # all_word = ['abc', 'a',...
acfadec0f2eb814774cd1f07841af99a48afb5b8
Deepkumarbhakat/Python-Repo
/factorial of a nummber.py
236
3.921875
4
# n=5 # fact=1 # for i in range(n,0,-1): # if i==1: # fact=fact*1 # else: # fact=fact*i # print(fact) def fact(n): if n==1 or n==0: return 1 else: return n*fact(n-1) x=fact(5) print(x)
4e592149e3f98f2d428bb5a37dd85431ad7be763
Deepkumarbhakat/Python-Repo
/factorial.py
206
4.25
4
#Write a program to find the factorial value of any number entered through the keyboard n=5 fact=1 for i in range(0,n,-1): if i==1 or i==0: fact=fact*1 else: fact=fact*i print(fact)
866d38f72f63b3d2d1ec87bfd1b330f04cf33635
Deepkumarbhakat/Python-Repo
/Write a program to check if a year is leap year or not. If a year is divisible by 4 then it is leap year but if the year is century year like 2000, 1900, 2100 then it must be divisible by 400..py
320
4.28125
4
#Write a program to check if a year is leap year or not. y=int(input('enter any year : ')) if (y % 4 == 0): if (y % 100 == 0): if (y % 400 == 0): print('leap year') else: print('not a leap year') else: print('leap year') else: print('not a leap year')
27cd32606dddc864ce68c35f824a533e1467419d
Deepkumarbhakat/Python-Repo
/function3.py
243
4.28125
4
# Write a Python function to multiply all the numbers in a list. # Sample List : (8, 2, 3, -1, 7) # Expected Output : -336 def multiple(list): mul = 1 for i in list: mul =mul * i print(mul) list=[8,2,3,-1,7] multiple(list)
3a98e9a55e3217f3f4faa76b71ab08a75adf1d8e
Deepkumarbhakat/Python-Repo
/function9.py
434
4.25
4
# Write a Python function that takes a number as a parameter and check the number is prime or not. # Note : A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors # other than 1 and itself. def prime(num): for i in range(2,num//2): if num % i == 0: print...
63507dcd1e550687bbc7d6108211bd15cf2164af
Deepkumarbhakat/Python-Repo
/string15.py
282
4.15625
4
# Write a Python program that accepts a comma separated sequence of words as input # and prints the unique words in sorted form (alphanumerically). # Sample Words : red, white, black, red, green, black # Expected Result : black, green, red, white,red st=("input:"," , ") print(st)
2a6d1f1f594ba9b7f442b8dcb366e47aa51a2906
Deepkumarbhakat/Python-Repo
/Write a Python program that accepts a word from the user and reverse it.py
143
4.21875
4
#Write a Python program that accepts a word from the user and reverse it char = " abcde" y=char.split() print(y) char=char[-1::-1] print(char)
086d0231677f2cda2886ee87d302a4a223063565
Deepkumarbhakat/Python-Repo
/list4.py
164
4.0625
4
# Write a Python program to get the smallest number from a list. a=[int(b) for b in input("enter the number : ").split()] print("smallest number",min(a)) print(a)
d6c07b75b2300ffbe75848a01fb59252c778bfc5
Deepkumarbhakat/Python-Repo
/Write a program to print absolute vlaue of a number entered by user..py
152
4.1875
4
#Write a program to print absolute vlaue of a number entered by user. x = int(input('INPUT :')) if x < 0: y=x*(-1) print(y) else: print(x)
7a7827eedd2369dddd5165fff5cc972090a0c43d
Deepkumarbhakat/Python-Repo
/sum of 10 nnatural number.py
164
4
4
#Write a program to calculate the sum of first 10 natural number. n = int(input("enter any number : ")) sum = 0 for i in range(1,n+1): sum = sum + i print(sum)
85756f1b81c845de56bdd9b04134c7cce3b5f1ec
MersenneInteger/sandbox
/binary.py
581
4.03125
4
powers = [] for pow in range(15, -1,-1): powers.append(2 ** pow) binaryOutput = '' while True: decimalInput = int(input('Enter a number between 1 and 65535: ')) if decimalInput <= 65535 and decimalInput >= 1: for power in powers: binaryOutput = binaryOutput + str(decimalInput // power) ...
8e1573dc618a825cb850cd98db16867c9ee52a43
MersenneInteger/sandbox
/OOP/inheritance.py
1,761
3.96875
4
#!usr/bin/python import random class Date(object): def getDate(self): return '09-02-18' #time inherits Date class Time(Date): def getTime(self): return '07-07-07' dt = Date() print(dt.getDate()) tm = Time() print(tm.getTime()) print(tm.getDate()) #object.attribute lookup hierachy #1)the ins...
b936f7dc39b2a3a4a28e5e80bb9c70af4685d964
MersenneInteger/sandbox
/functional-py/optimizing.py
3,344
3.8125
4
#Implementing Utilities and Optimizing Storage ##composite design pattern #creates tree-like hierarchical structures #each component in a composite design may be a leaf node or a composite node #three elements #component: defines basic properties of all elements in structure #leaf: bottom-most element, contai...
f7d5ccb63d48723c1596c5f6d126a76be881e5cb
MersenneInteger/sandbox
/functional-py/basics.py
6,543
3.890625
4
##functional programming import itertools ##recursion def factorial(n): result = 1 for x in range(1, n+1): result = result * x return result print(factorial(6)) def recuFactorial(n): if n <= 1: return n return n * recuFactorial(n-1) print(recuFactorial(6)) #fibonacci - i...
423ade86419e6532d864a6357ad33594368b9549
MersenneInteger/sandbox
/LeetCode/hammingDistance.py
562
3.5625
4
def intToBin(num): powers = [] for pow in range(255, -1,-1): powers.append(2 ** pow) binaryOutput = '' for power in powers: binaryOutput = binaryOutput + str(num // power) num %= power return binaryOutput class Solution(object): def hammingDistance(self, x, y): ...
9fa4fb38ce6f4eb0d77ad39bff0fc0287430ced4
Aryasankar5/python-programs-2
/positive number list.py
355
4.09375
4
# -*- coding: utf-8 -*- """ Created on Fri Sep 25 18:08:04 2020 @author: ARYA SHANKAR """ list=[] n=int(input("Enter the number of elements : ")) for i in range(1,n+1): a=int(input("Enter the %d element :" %i)) list.append(a) print("The list of positive numbers are : ") for num in range(n): if...
652d7afaa86a4297813f8051fe450816ab7fc1e9
ZheniaTrochun/embedded-systems
/neuron.py
792
3.5625
4
sigma = 0.1 x1 = (1, 5) x2 = (2, 4) p = 5 initial_w1 = 0 initial_w2 = 0 def delta(y, p): return int(p - y) def func(w1, w2, point): return point[0] * w1 + point[1] * w2 def update(w, x, delta): return w + delta * x * sigma def check(w1, w2): y1 = func(w1, w2, x1) y2 = func(w1, w2, x2) return (y1 > p) ...
b70cb8128ef8ccabfd7b8e2620709777a5b0a088
Tanasiuk/Homework
/first and last ver2.py
517
3.546875
4
def firstnlast(a): try: new_list = list(int(item) for item in a.split()) print("Массив чисел:", new_list) print("Первый элемент списка:", new_list[0]) print("Последний элемент списка:", new_list[-1], "\n") except ValueError: print("Снова сломал?! Работаем с числами...
8b0dec00c444b34636b0d7d4775a48fa8829d633
Tanasiuk/Homework
/first and last ver1.py
493
3.703125
4
def firstnlast(a): newlist = " ".join(str(x) for x in a) print("Первый элемент списка:", newlist[0]) print("Последний элемент списка:", newlist[-1]) try: y = int(input("Укажите длину массива:\n")) a = [int(input("Введите число массива:\n")) for i in range(y)] print("\nМасссив чисел:\n",...
60587c257c99bd0e42d92e66d2ebe75eacbeab73
cloi1994/session1
/Uber/24.py
687
3.71875
4
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def swapPairs(self, head): """ :type head: ListNode :rtype: ListNode """ root = prev = ListNode(1) ...
067479493ca1e35a30bdcd26941ca3f3a32e1853
cloi1994/session1
/Amazon/138.py
971
3.6875
4
# Definition for singly-linked list with a random pointer. # class RandomListNode(object): # def __init__(self, x): # self.label = x # self.next = None # self.random = None class Solution(object): def copyRandomList(self, head): """ :type head: RandomListNode :rt...
05d749540382f8e673991ff307f3762b358bf4b2
cloi1994/session1
/Facebook/680.py
778
3.5
4
class Solution(object): def validPalindrome(self, s): """ :type s: str :rtype: bool """ """ :type s: str :rtype: bool """ i = 0 j = len(s) - 1 allowOnce = 0 while i <= j: ...
e4a8749cda9171f0332b15f56c0f65b69121a8ce
cloi1994/session1
/Amazon/160.py
1,234
3.71875
4
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def getIntersectionNode(self, headA, headB): """ :type head1, head1: ListNode :rtype: ListNode """ if not hea...
09618d1974a7d16fd8593d8141aef9d3534850db
cloi1994/session1
/Facebook/277.py
635
3.703125
4
""" The knows API is already defined for you. @param a, person a @param b, person b @return a boolean, whether a knows b you can call Celebrity.knows(a, b) """ class Solution: # @param {int} n a party with n people # @return {int} the celebrity's label or -1 def findCelebrity(self, n): # Write you...
9c1e279e48c091090367f039361e43cad7a9a895
cloi1994/session1
/Amazon/102.py
735
3.734375
4
# 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 levelOrder(self, root): """ :type root: TreeNode :rtype: List[List[int]] """ ...
dc5203f536fbefe8ae06198b3c0cda6c6871690c
remix7/python3-nome
/learningpy3/线程与进程/22线程共享非全局变量.py
273
3.609375
4
from threading import Thread import time def test1(): g_num = 100 g_num += 1 print(" test 1 g_num is %d"%g_num) def test2(): g_num = 1 print(" test 2 g_num is %d"%g_num) p1 = Thread(target=test1) p1.start() #time.sleep(3) p2 = Thread(target=test2) p2.start()
e2c959e1a18bb0321d69ffa040f1d709d717c296
remix7/python3-nome
/learning/LenClass.py
360
3.921875
4
class myClass1: """A simple example class""" def __init__(self): # 构造函数 self.data = [] i = 12345 # 普通成员属性 def f(self): # 普通成员函数 return 'what fuck' class A: pass class myClass2: def __init__(self, r, i): self.r = r self.i = i x = myClass1() print...
fd172a7bbc1eb7a5fe0426f99302bca769d277bc
remix7/python3-nome
/learningpy3/raiseException.py
283
3.828125
4
class ShortInputException(Exception): def __init__(self,first,last): self.first = first self.last = last def main(): try: s = "an" if len(s) < 3: raise ShortInputException(len(s),3) except ShortInputException as res : print(res) else: print("no exception") main()