blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
3fd6fb5054e36e469b5663159becd1875fdcaaa2
patricia-asico/csdc105-n2-asico
/exercise4/geometry.py
653
3.953125
4
# Author : {Patricia P. Asico} # Course and Year : {1-BSIT} # Filename : {geometry.py} # Description : {Two functions named perimeter and triangle_heronsarea which computes the perimeter and the area of a triangle with valid lengths.} # Honor Code : I have not given nor received any unathorized help in # c...
8e43e823296592a53c745dfb203d108dae9b4888
Yingminzhou/FPExamples
/random_test.py
354
3.5625
4
__author__ = 'yingminzhou' import random names = ["Mary","Isla","Sam"] # unfunctional one code_names = ['Mr. Pink', 'Mr. Orange', 'Mr. Blonde'] for i in range(len(names)): names[i] = random.choice(code_names) print(names) #functional one secret_names = map(lambda x: random.choice(['Mr. Pink', 'Mr. Orange', '...
8c19737d7460858c48ed7b0de1372c8e0cb5021f
lusch0620/aoc2019
/day1/sol.py
691
3.609375
4
import math def findFuel(mass: int) -> int: ans = math.floor(mass/3) - 2 return ans def actualFuel(mass: int) -> int: ans = 0 while mass > 0: temp = findFuel(mass) if temp < 0: break else: mass = temp ans += temp return ans assert actualFuel...
b28abeb75373ccdc0df0a3bd87b44a7b96cb7812
vish4321/Thingspeak-Python
/thingspeak.py
7,781
3.546875
4
import urllib.request import urllib.parse import json import collections import matplotlib.pyplot as plt import requests import time import thingspeak_params ''' Put "import thingspeak" or "from Thingspeak import channel" near the top of your python file. This module gives you a few functions to communicate over a spe...
309d971b624272f31316c834677d83ddcffb0a5d
AminuIsrael/Word-Scrabble-game
/Assignment1_PIN.py
1,571
3.9375
4
""" Created on Sun Apr 14 22:18:27 2019 @author: Israel """ print("-------------------------------------------------------------------------------") print(" Welcome to the Word Scrabble game \n") print(" You are to re-arrange a scrabbled word collected from a dictionary\n") print...
55d89a854272f93903ecb231bf276fdb322b3b16
LEROY482/operators
/Opera.py
966
4.34375
4
#the floor division // rounds the result down to the nearest whole number p = 15 t = 2 print(p // t) #Assignment operators are used to assign values to variables u = 5 t **= 3 print(t) #Comparison operators are used to compare two values: # returns True because 8 is not equal to 3 t = 8 f = 3 print(t != f) #Logical ...
5d3b40f70bc23d0749dac8db08440fefe4832a61
PiTiLeZarD/MorPy
/codes/sanitizer.py
111
3.5625
4
def sanitize(string, code): return "".join([ c if c == ' ' or c in code else "" for c in string.lower() ])
bfe65742a07be91415c4bfbf6f6fa00a56245c1b
0xd2e/python_playground
/Pythonchallenge solutions/pythonchallenge10.py
954
3.90625
4
#!/usr/bin/python3 # http://www.pythonchallenge.com/pc/return/bull.html # If needed, use username and password from challenge 8 from itertools import groupby def calc_seq_len(n, a): ''' Inputs: n -- positive integer, number of the element in the sequence a -- string with the natural number, starti...
6a09c2e61c8c38868cacda727723dbe4c13245ea
0xd2e/python_playground
/Daftcode Python Level UP 2018 solutions/utils.py
3,436
3.6875
4
#!/usr/bin/python3 from os import path from requests import get, exceptions def prepare_file_path(filename, extension, dirpath=''): ''' Inputs: filename -- string, file name extension -- string, file extension -- use empty string if extension is included in the fil...
033755ebe182aeca6230d5d3b96cae6849365547
joshua-dai/pygames
/dodge.py
6,272
3.546875
4
# -*- coding: utf-8 -*- """ Created on Tue Jan 19 22:47:06 2021 @author: joshu full game, with classes """ import pygame as pg import sys, random, time from pygame.locals import * # colour constants, we don't need the extra functionality with pg.Color()_ BLUE = (0, 0, 255) RED = (255, 0, 0) GR...
9deb5c8de7636eb763c026c9d33cf4cf222969fc
AyeJayTwo/smsAnalyze
/errata/tester.py
607
3.90625
4
#import sqlite3 # #persons = [ # ('Hugo', "Boss"), # ("Calvin", "Klein") # ] # #con = sqlite3.connect(":memory:") # ## Create the table #con.execute("create table person(firstname, lastname)") # ## Fill the table #con.executemany("insert into person(firstname, lastname) values (?, ?)", persons) # ## Print the ...
ad1c6d14491a906f3fe9496d11be2f4ab9ebac89
DorgyFilho/CodeWars
/#10 - Consecutive Strings.py
434
3.53125
4
def longest_consec(strarr, k): n = len(strarr) if n == 0 or k > n or k <= 0: return '' longest, point = 0, 0 for i in range(n - k + 1): lth = sum([len(s) for s in strarr[i: i+k]]) if lth > longest: longest = lth point = i return ''.join(stra...
7aea13f4fd67d97b80a3f2c0de9cb087f6d52fa1
DorgyFilho/CodeWars
/#13 - Vowel Count.py
300
3.71875
4
def getCount(inputStr): num_vowels = 0 a = inputStr.count('a') e = inputStr.count('e') i = inputStr.count('i') o = inputStr.count('o') u = inputStr.count('u') total = a+e+i+o+u num_vowels += total return num_vowels inputStr = 'Dorgival' print(getCount(inputStr))
8dfa64c907bc551d695505593320d41e804aef47
sunnycd/HackerRank-Python
/itertools/permutations.py
255
3.625
4
#from __future__ import print_function from itertools import permutations data = raw_input().split() word = data[0] parameter = int(data[1]) print word print parameter b = list(permutations(word, parameter)) for item in sorted(b): print("".join(item))
cbb89e82545fd8289b7fdddb2d6b0c645ed39d8b
shirin-john/Python-Proj
/fairytales.py
3,866
3.96875
4
import time from emoji import emojize as e def fairytale(): while True: print("_" * 130) print(e(":bookmark: Fairytales:")) print("\n*Please Note: You Can Borrow Only One Book At A Time. Once You have Borrowed A Book, You May Log Out Or Exchange Your Book.") print("\nFairyta...
0d871c5db4292ff706390e0e67bbc3dee0536a97
shirin-john/Python-Proj
/alphabet_books.py
6,338
4
4
import time from emoji import emojize as e def alph(): while True: print("_" * 130) print(e(":bookmark: Alphabet Books:")) print("\n*Please Note: You Can Borrow Only One Book At A Time. Once You have Borrowed A Book, You May Log Out Or Exchange Your Book.") print("\nAlphabet...
dcc587fef3af5679478582ff5b9f7c08085663f6
bowen903/python_study
/python_study_098.py
2,135
4.0625
4
# -*- coding:utf-8 -*- """ @author:Xiaoping @file:python_study_098.py @time:2017/9/1 19:14 """ # 二维数组操作 def init(row, line): #生成数组 if 0<= row <=9 and 0<= line <= 9: arr = [[i for i in range(line)] for j in range(row)] print 0 return arr else: print -1 def exchange(arr, so...
32e86f7e851957173c90a84d3e565032a28d94af
bowen903/python_study
/python_study_071.py
803
3.609375
4
# encoding: utf-8 """ @author: Xiaoping @file: python_study_071.py @time: 2017/8/18 23:27 """ # 查找最长的公共子串 while True: try: str1 = raw_input() str2 = raw_input() if len(str1) < len(str2): str_short = str1 str_long = str2 else: str_short = str2 ...
9ea1f0bda1c3f45a822bcf960d1413beeb0db1ba
bowen903/python_study
/python_study_0106.py
402
3.59375
4
# -*- coding:utf-8 -*- """ @author:Xiaoping @file:python_study_0106.py @time:2017/9/2 14:59 """ #计算n x m的棋盘格子 def count(n,m): if n == 1: return m+1 if m == 1: return n+1 return count(n-1,m)+count(n,m-1) while True: try: line = raw_input().split() n = int(line[0]) ...
cf50ab6990b35fe58de49ea3d7603531521d53dd
bowen903/python_study
/python_study_010.py
462
3.78125
4
#-*-coding:utf8-*- class Student(object): def __init__(self,name,score): self.name = name self.score = score def __str__(self): return '(%s: %s)' %(self.name, self.score) __repr__ = __str__ #实例化 def __cmp__(self, s): if self.score == s.score: return cmp(self...
71dcab67b165332582b46e87b6080a42eb0c3bbe
bowen903/python_study
/python_study_0113.py
755
3.640625
4
# -*- coding:utf-8 -*- """ @author:Xiaoping @file:python_study_0113.py @time:2017/9/6 19:10 """ # 最长子串 while True: try: line = raw_input() digitline = '' num =0 maxcount = 0 res = [] for i in line: if i.isdigit(): digitline += i ...
3a27671592f52bbeb512a0fc5413590ff3ea6a07
bowen903/python_study
/python_study_043.py
866
3.59375
4
# encoding: utf-8 """ @author: Xiaoping @file: python_study_043.py @time: 2017/7/19 23:41 """ def encode(str0): li = map(int, str0.split('.')) str1 = '' for s in li: s1 = bin(s)[2:] s1 = (8-len(s1) )* '0' +s1 str1 +=s1 int0 = int(str1, base = 2) return int0 def decode(int0 )...
5ae2f631283d34de14d3131d54b7561c61e0e8ea
bowen903/python_study
/python_study_0101.py
483
3.5
4
# -*- coding:utf-8 -*- """ @author:Xiaoping @file:python_study_0101.py @time:2017/9/1 22:03 """ #二进制中1 最多的连续次数 while True: try: num = int(raw_input()) str1 = str(bin(num))[2:] count = 0 max1 = 0 for i in str1: if int(i)==0: count =0 el...
bc2253dbbc5bcb929e4c0850a4bd859e2af0240f
bowen903/python_study
/python_study_0126.py
796
3.859375
4
# -*- coding:utf-8 -*- """ @author:Xiaoping @file:python_study_0126.py @time:2017/9/21 20:16 """ # 二叉树遍历 前序遍历 \\\ class node(): def __init__(self, k=None, l=None, r=None): self.key = k self.left = l self.right = r def create(root): for a in root: if a is '#': root...
683ee979ec93c25dfda5be6bfd57d2d5886fc6cc
FB-18-19-PreAP-CS/wordplay-mosgood549
/textreader.py
4,946
3.90625
4
import re #def read_file(): # with open("words.txt") as file: # count_the = 0 # for line in file: # for word in line.strip().split(): # count_the +=1 # print(count_the) def at_least(): ''' reads word.text and prints the words w...
4e989179f0d79619d95d0eed5e494e9799a7a96e
AlexGeorgeLain/SSD_CodeSnippets
/basic_shell.py
790
3.703125
4
"""Basic python shell with 4 commands""" import os def shell(): while True: command = input('$ ').lower() if command == 'list': for content in os.scandir('.'): if content.is_file(): print(content.name) if command == 'add': num_1...
f1197c4c6c5346125a56486bd5f0c1092a86a86b
fxy1018/Leetcode
/188_BestTimeToBuyAndSellStockIV.py
3,080
3.890625
4
""" Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most k transactions. Note: You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again). 需要用动态规划Dynamic Pro...
b3e1978870c59632249340628a01177b6e45c593
fxy1018/Leetcode
/103_Binary_Tree_Zigzag_Level_Order_Traversal.py
1,471
4.0625
4
""" Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ ...
a68ec65c96a1e8bbaf9cddef45a1a621ecd6bb35
fxy1018/Leetcode
/403_FrogJump.py
4,124
4.3125
4
''' A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water. Given a list of stones' positions (in units) in sorted ascending order, determine if the frog is able to cross the river by landing o...
ffa8585317b33491d33033573e9d7b28cbd2373b
fxy1018/Leetcode
/114_Flatten_Binary_Tree_to_Linked_List.py
1,885
4.15625
4
""" Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 """ from platform impo...
d3f648d21e2cde6b3132c847f275087da5be657a
fxy1018/Leetcode
/LC_1408_Gas Station II.py
2,577
4.15625
4
''' A car is driving on a straight road and it has original units of gasoline. There are n gas stations on this straight road, and the distance between the i-th gas station and the starting position of the car is distance[i] unit distance, which can add apply[i] unit gasoline to the car. The vehicle consumes 1 unit of ...
c09a301039654ddd8849df2c69271f623e56463b
fxy1018/Leetcode
/513_FindBottomLeftTreeValue.py
1,138
4.03125
4
''' Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 3 Output: 1 Example 2: Input: 1 / \ 2 3 / / \ 4 5 6 / 7 Output: 7 Note: You may assume the tree (i.e., the given root node) is not NULL. ''' # De...
ce599ea06636c5f1b637d4127b9582b10d3ac4e8
fxy1018/Leetcode
/637_AverageofLevelsinBinaryTree.py
1,266
3.859375
4
''' Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Input: 3 / \ 9 20 / \ 15 7 Output: [3, 14.5, 11] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11]....
ca6e71275f0e4e2136495a348975a77285e75d86
fxy1018/Leetcode
/200_Number_of_Islands.py
2,337
3.71875
4
""" Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. """ ''' Created on Jan 15, 2017 @author: fanxueyi ''' # ...
80878be93cdff1ea50aaf5497073d7d3165f2002
fxy1018/Leetcode
/LC_657_Insert Delete GetRandom O(1).py
2,567
3.859375
4
''' Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val from the set if present. getRandom: Returns a random element from current set of elements. Each element must have the same probab...
1ce5bb9aa1f6528113156e8b3169d3ac75673381
fxy1018/Leetcode
/98_Validate_Binary_Search_Tree2.py
3,142
4.1875
4
""" Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees ...
452ca37ff31bc74524d7eccf7a01ea4ee567db14
fxy1018/Leetcode
/145_Binary_Tree_Postorder_Traversal.py
3,419
3.96875
4
""" Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Note: Recursive solution is trivial, could you do it iteratively? """ ''' Created on Mar 12, 2017 @author: fanxueyi ''' #method1: Recursives solutio...
8b5dd1b0248264c7893ba4650b12206b71422863
fxy1018/Leetcode
/300_Longest_Increasing_Subsequence.py
2,631
3.515625
4
""" Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Note that there may be more than one LIS combination, it is only necessary for you to return the ...
fb732331c2793e68c045838335cb29e097da3608
fxy1018/Leetcode
/BinarySearch.py
426
4.03125
4
''' Created on Feb 18, 2017 @author: fanxueyi ''' def binarySearch(arr, target): arr = sorted(arr) left = 0 right = len(arr)-1 while left <= right: mid = (left+right)//2 # get the interger if arr[mid ]< target: left = mid+1 elif arr[mid] > target: righ...
7630eed1713748789d5e76c810ab54000fabe7e0
fxy1018/Leetcode
/54_Spiral_Matrix.py
1,620
4.25
4
""" Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You should return [1,2,3,6,9,8,7,4,5]. """ ''' Created on Jan 30, 2017 @author: fanxueyi ''' """ 转圈打印矩阵,需要设置left, ri...
839d27585c2d586a71c964bfb7bf8441e7f0e6c8
fxy1018/Leetcode
/reverse_stack.py
575
3.640625
4
""" given a stack, return reversed stack (in-place) """ ''' Created on Mar 4, 2017 @author: fanxueyi ''' class Solution(object): def popFistElementOfStack(self, stack): num = stack.pop() if not stack: return(num) return(self.popFistElementOfStack(stack)) def reverse...
4026573f3eb5c717187b2a99a326132187cfdcc2
fxy1018/Leetcode
/753_Cracking the Safe.py
1,262
3.78125
4
''' There is a box protected by a password. The password is n digits, where each letter can be one of the first k digits 0, 1, ..., k-1. You can keep inputting the password, the password will automatically be matched against the last n digits entered. For example, assuming the password is "345", I can open it when I ...
8358e28ae838adc6db7facb3e26cbf3cbbda7f6f
fxy1018/Leetcode
/655_PrintBinaryTree.py
3,566
4.21875
4
''' Print a binary tree in an m*n 2D string array following these rules: The row number m should be equal to the height of the given binary tree. The column number n should always be an odd number. The root node's value (in string format) should be put in the exactly middle of the first row it can be put. The column ...
20a735727f7ceed3134035dae2a653af2fc36f55
fxy1018/Leetcode
/92_Reverse_Linked_List_II.py
3,141
4.03125
4
""" Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the following condition: 1 <= m <= n <= length of list. """ from macholib.mach_o import prebind_cksum_command ''' Created on...
80c9e1ce93bc7875d35e67dc4aadf9c36668312e
fxy1018/Leetcode
/build_tree.py
1,176
3.8125
4
""" 第二个人是给一组输入,第一列是node,第二列是parent,让你建个树返回。例如: node                parent 2              1 3              1 7              1 4              2 5              2 那么建出来的树就是:            1          /        |        \         2        3        7        / \        |      4   5 6 """ class Node(object): def __init__(se...
e5405837e8d81d7e83cae6582c796e8f8d427743
fxy1018/Leetcode
/lintcode/185_Matrix_Zigzag_Traversal.py
1,913
3.65625
4
""" Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-order. Given a matrix: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10, 11, 12] ] return [1, 2, 5, 9, 6, 3, 4, 7, 10, 11, 8, 12] """ ''' Created on Feb 14, 2017 @author: fanxueyi ''' class Solution: # @param: ...
40505a7fd30fbf64a27306f634e7ddd5a0356f6b
fxy1018/Leetcode
/823_BinaryTreesWithFactors.py
1,237
4.09375
4
''' Given an array of unique integers, each integer is strictly greater than 1. We make a binary tree using these integers and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of it's children. How many binary trees can we make? Return the answ...
4207786a439bcfcaa0661de047bc749251822922
fxy1018/Leetcode
/238_Product_of_ArrayExceptSelf.py
1,541
3.953125
4
''' Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n). For example, given [1,2,3,4], return [24,12,8,6]. Follow up: Could you solve it with constant space complexity? (N...
4d12aa8adbe1acf3d9c0985615a533d706826c60
fxy1018/Leetcode
/537_ComplexNumberMultiplication.py
1,148
4.1875
4
''' Given two strings representing two complex numbers. You need to return a string representing their multiplication. Note i2 = -1 according to the definition. Example 1: Input: "1+1i", "1+1i" Output: "0+2i" Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i. Example 2:...
fc2da4e3ccfbfcd25fbe08b87cb1f982e078802f
fxy1018/Leetcode
/179_LargestNumber.py
1,639
4.1875
4
''' Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. ''' Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the larges...
8094c7b124de6c8f3efe5b046675b07525d0e964
fxy1018/Leetcode
/520_Detect_Capital.py
1,662
4.4375
4
''' Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this word are capitals, like "USA". All letters in this word are not capitals, like "leetcode". Only the first letter in ...
dff16e7dfb497bf79a3c1c2d032d1c72672f3336
fxy1018/Leetcode
/2501_Longest_Square_Streak_in_an_Array.py
1,067
4.03125
4
''' You are given an integer array nums. A subsequence of nums is called a square streak if: The length of the subsequence is at least 2, and after sorting the subsequence, each element (except the first element) is the square of the previous number. Return the length of the longest square streak in nums, or return -1...
adbc20fa832373317f3f7c7a9b48bb5415fe700d
fxy1018/Leetcode
/LC_1482. Minimum Sum Path.py
732
3.703125
4
""" Definition of TreeNode: class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None """ class Solution: """ @param root: the root @return: minimum sum """ def minimumSum(self, root): # Write your code here self.minSum = float("I...
c280b3cf957ce93ed17c410378ca6c60b890f4d1
fxy1018/Leetcode
/529. Minesweeper.py
974
3.578125
4
class Solution(object): def updateBoard(self, board, click): """ :type board: List[List[str]] :type click: List[int] :rtype: List[List[str]] """ row = len(board) col = len(board[0]) queue = [(click[0], click[1])] visited = set((click[0], click[1])) while queue: x,y = queue.pop(0) if board[x][...
ba31ef9b566cdaec2701a00435e7f49d8829c369
fxy1018/Leetcode
/117_PopulatingNextRightPointers_in_EachNodeII.py
2,170
4.21875
4
''' Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extra space. For example, Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ...
2e5c394d3ff2f45db1d8a526743b60a782489811
fxy1018/Leetcode
/138_Copy_List_with_Random_Pointer.py
5,408
3.765625
4
""" A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. """ ''' Created on Jan 16, 2017 @author: fanxueyi ''' #method1: #先遍历链表一次,拷贝next节点,并将原节点与拷贝过后的复制节点的映射关系用hashmap保存起来。然后再遍历一次链表,通过读取hashmap的映射关系来更新复制...
a1c1e3d0813156911a1fb3dcdfa6ef90c561def7
fxy1018/Leetcode
/311_Sparse_Matrix_Multiplication.py
1,309
3.8125
4
#Given two sparse matrices A and B, return the result of AB. #You may assume that A's column number is equal to B's row number. ''' Created on Jan 5, 2017 @author: fanxueyi ''' class Solution(object): def multiply(self, A, B): """ :type A: List[List[int]] :type B: List[List[int]] ...
667d8e7f909de03157bfcba7cbaeddfecd40e251
fxy1018/Leetcode
/350_Intersection_of_Two_Arrays_II.py
2,058
4.0625
4
""" Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as many times as it shows in both arrays. The result can be in any order. Follow up: What if the given array is already sorted? How w...
7564d8ff351074e8ee88f0927a0af5a11e4fe37c
fxy1018/Leetcode
/124_BinaryTreeMaximumPathSum.py
1,484
4.09375
4
''' Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root. For example: Given the below binary tre...
12732d0baa8263f8e23b30f4bb3d5c4d652d5480
fxy1018/Leetcode
/24_Swap_Nodes_in_Pairs.py
1,137
3.859375
4
""" Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. """ ''' Created on Jan 16, 2017 @author: ...
78a1b334606c3afc0abfc403fdaa8691f94af658
fxy1018/Leetcode
/172_Factorial_Trailing_Zeroes.py
438
3.890625
4
""" Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. """ ''' Created on Jan 13, 2017 @author: fanxueyi ''' class Solution(object): def trailingZeroes(self, n): """ :type n: int :rtype: int """ o...
80692e8e6e6da8dfe211513afe59ae4f83039f04
fxy1018/Leetcode
/5_Longest_Palindromic_Substring.py
1,580
3.90625
4
#Given a string s, find the longest palindromic substring in s. #You may assume that the maximum length of s is 1000. ''' Created on Jan 8, 2017 @author: fanxueyi ''' class Solution(object): def longestPalindrome(self, s): """ :type s: str :rtype: str """ #use Dynamic Pro...
910321e8ab0fa688cdbef858046142ec01cf199c
fxy1018/Leetcode
/229_MajorityElementII.py
1,571
3.8125
4
''' Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. ''' class Solution: def majorityElement(self, nums): """ :type nums: List[int] :rtype: List[int] """ if not nums: ...
c79ddd87591d6af288df4bcf9221fe929c94c11d
fxy1018/Leetcode
/845_Longest Mountain in Array.py
1,735
4.09375
4
''' Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: B.length >= 3 There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1] (Note that B could be any subarray of A, including the entire array A.) Given an array A of int...
809bdca639697417661273e86e39715c68c5e515
fxy1018/Leetcode
/415_Add_Strings.py
1,264
3.875
4
""" Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading zero. You must not use any built-in BigInteger library or convert th...
c29c7200d84fbaeb8cdada12698591789461c7f9
fxy1018/Leetcode
/14_Longest_Common_Prefix.py
551
3.59375
4
""" Write a function to find the longest common prefix string amongst an array of strings. """ ''' Created on Jan 13, 2017 @author: fanxueyi ''' class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if not strs: r...
5d7dbb6eb51c80813e62e2920a20607d30002730
fxy1018/Leetcode
/76_MinimumWindowSubstring.py
1,589
3.921875
4
''' Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOBECODEBANC", T = "ABC" Output: "BANC" Note: If there is no such window in S that covers all characters in T, return the empty string "". If there is such window, yo...
781a1b601d11379711590e4d7902a27a11410a66
fxy1018/Leetcode
/821_Shortest Distance to a Character.py
1,437
3.90625
4
''' Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Example 1: Input: S = "loveleetcode", C = 'e' Output: [3, 2, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0] Note: S string length is in [1, 10000]. C is a single character, and guaranteed to ...
a4cebe7a044b30d2ed6c6b4497ec1e35b9f37a19
Lutfi1337/panda
/PandaV1.0.py
12,610
3.671875
4
def clear (): import os os.system('cls') def IPK(): def daftar(): print ("") print ("") print ("\tPanel Count IPK") print ("\n=================================") print ("") print ("\nChoose : ") for IPK in ["1. Count Your Ipk (D4)","2. Count Your Ipk (...
e7e1e8a07927fa6905d1857a9d4871d601c42321
GranotOn/Neural-Network
/SoftmaxLayer.py
760
3.5
4
from Layer import Layer import numpy as np class SoftmaxLayer(Layer): def __init__(self): super().__init__() def forward_propagation(self, inputs): self.inputs = inputs inputs -= np.max(inputs) exponents = np.exp(inputs) exponents_sum = np.sum(exponents) self.o...
506dff1bb8aca7d8711eecca36f4d637a7e762ae
on1ystar/networkAssignment
/assignment_4/threadTest.py
282
3.5625
4
import threading import time def myThread(index): for i in range(index): print("My thread") time.sleep(2) t = threading.Thread(target = myThread, args=(3,)) t.start() for i in range(3): print("main") time.sleep(1) print("---end---")
df758427766c3bce803670ddbfc8f2fd08b9de3a
VarshaRadder/APS-2020
/Code library/77.additive number.py
647
3.828125
4
# -*- coding: utf-8 -*- """ Created on Mon Apr 27 23:05:18 2020 @author: Varsha """ import itertools #Additive number is a string whose digits can form additive sequence def isAdditiveNumber(num): n = len(num) for i, j in itertools.combinations(range(1, n), 2): a, b = num[:i], num[i:j] ...
d949b3c5a70cc0ed53a529a00adeb7bc47056b40
VarshaRadder/APS-2020
/Code library/22.maximising_xor.py.py
394
3.734375
4
# -*- coding: utf-8 -*- """ Created on Tue Mar 24 15:16:15 2020 @author: Varsha """ def maximizingXor(l, r): a = l^r b = 0 while(a): b += 1 a >>= 1 c, d = 0, 1 while (b): c += d d <<= 1 b -= 1 retur...
641cef8f37d07100bde7aea031a5ce454a147dd5
VarshaRadder/APS-2020
/Code library/124.chocolate feast.py
609
4.03125
4
# -*- coding: utf-8 -*- """ Created on Tue Apr 28 19:54:02 2020 @author: Varsha """ #!/bin/python3 import math import os import random import re import sys # Complete the chocolateFeast function below. def chocolateFeast(n, c, m): cost=n//c temp=cost while temp>=m: x=temp//m ...
23495414ee0504f8b7ae8961988111479c58c8d0
VarshaRadder/APS-2020
/Code library/127. Flipping bits.py
378
4
4
# -*- coding: utf-8 -*- """ Created on Tue Apr 28 15:19:31 2020 @author: Varsha """ import math import os import random import re import sys import math # Complete the flippingBits function below. def flippingBits(num): return ~ num + (1 << 32) q = int(input()) for q_itr in range(q): n...
7001a82dd58f17f1fc54b9124d8c8f9e7053fdbf
VarshaRadder/APS-2020
/Code library/142. Is subsequence.py
335
3.875
4
# -*- coding: utf-8 -*- """ Created on Tue Apr 28 18:49:19 2020 @author: Varsha """ ''' check if s is subsequence of t ''' def isSubsequence(s,t): for i in s: if i in t: t = t[t.index(i) +1:] else: return False else: return True s=input() t=input() print(isSu...
c3b43770095dd0553ccabaa11f983078041ae303
VarshaRadder/APS-2020
/Code library/64.climbing_stairs in n steps.py
504
3.859375
4
# -*- coding: utf-8 -*- """ Created on Mon Apr 27 20:52:56 2020 @author: Varsha """ def climbStairs(n): def factorial(n): res =1 for i in range(1,n+1): res = res*i return res if n <=3: return n else: ...
6bcfd9298ef5f502a88b4626b9ee408a09df4bf2
wdingmtsu/Master
/Sim.py
14,321
3.5
4
#!/usr/bin/env python3 #Author: Ryan Florida #Purpose: This program simulates our first M&M modeling project, without death # and without immigration. from random import sample #Some parameters. NUM_OF_MM = 63 START = 8 ROW = 21 COL = 16 #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$...
07f6a0737dbc342f5b7e5440ea5765c08e2ff671
nao-tarrillo/Trabajo10
/app6.py
2,696
3.59375
4
import libreria def pedir_nombre_restaurante(): libreria.pedir_nombre("agregar Blue garden:") print ("agrega Blue garden:") def pedir_El_sagitario(): print("agregar El sagitario:") def pedir_El_paisa(): print("agregar El paisa:") def pedir_El_comedor(): print("agregar El paisa") def pedi...
d625055bfa66c9bcade5afc5befd802c71a0514e
nao-tarrillo/Trabajo10
/app1.py
1,650
3.859375
4
import libreria def pedir_precio1(): libreria.pedir_numero("ingrese S/.:") print("se agrega S/.") def pedir_cantidad("ingrese kg"): libreria.pedir_numero("ingrese kg") def agregar_cantidad(): input("agregar cantidad") print("se agrega cantidad") def agregar_precios(): input("agre...
8aea596d32b82ddee158d1882ea1f1f7e505df24
arnavahuja123/project99
/Removing.py
491
3.578125
4
import os import shutil import time path=input("path to remove old files: ") days = input("delete files before:") timeComparer=(time-time())-1*86400 for fileName in os.listdir(path): if os.path.getmtime(os.path.join(path,fileName))<timeComparer: if os.path.isfile(os.path.join(path,fileName)): ...
cba93b8925ffe6e92bb70aede6cccc5ae3406fba
darwingug/lab4.py
/lab4_darwin.py
977
4.03125
4
#dana hedman djh393@nau.edu #darwin guglielmo rg797@nau.edu #the objective is to create the game and be able to win it basically import random #this will help us with the randomization def main(): board = [] row = 5 col = 5 square = [["\N{'WHITE SQUARE'}" for i in range(col)] for j in range(row)] for row in ...
fab0e39c65fc6eb4d6642bd7c744cfb84fe08580
paulov59/folha-de-pagamento-ester
/main.py
3,511
3.921875
4
from funcionario import Funcionario from folha import Folha funcionarios = [] def setId(): for i in funcionarios: i.id = funcionarios.index(i) def listar(): if funcionarios == []: print("\nAinda não há funcionários cadastrados") else: print("\nid - Nome") for i in funciona...
fa9e01533e55d9f5321e44bbc5825264d9dd38f2
yaboijules/yaboijules.github.io
/python/regexlearning.py
222
4.0625
4
import re while True: message = input('enter some text. itll look for a phone number ') phoneRegex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') found = phoneRegex.search(message) print('Phone number found: '+found.group())
85c6900a470f5f99428978187751f4d13c3a7cb2
yaboijules/yaboijules.github.io
/python/pathagriantriples.py
816
4.25
4
def thefunction(a,b,c): if (pow(a,2) + pow(b,2) == pow(c,2)): print('It is a pythagorean triple') else: print('It is not a pythagorean triple') def checkdigit(x): try: int(x) return True except ValueError: print('That is not a valid number.') return False go = True while go: while True: hypotenuse ...
dfabbdd7097bfe1ffd4bb947d5a0f308a55cf4af
yaboijules/yaboijules.github.io
/python/phonecheck.py
651
4.0625
4
def isPhoneNumber(text): if len(text) != 12: return False for i in range(0,3): if not text[i].isdecimal(): return False if text[3] != '-': return False for i in range(4,7): if not text[i].isdecimal(): return False if text[7] != '-': return False for i in range(8,12): if not text[i].isdecimal(): ...
25a8bb8a9797cc83cbeebc725040dcf04f9680b3
yaboijules/yaboijules.github.io
/python/mmm.py
1,966
3.984375
4
import math def checkint(x): try: int(x) return True except ValueError: print('Please enter a whole number!') return False def findmedian(x): #------ makes new list in numerical order ------- #------ also could have just used the .sort() list method medianlist = [] holder = x[:] for i in range(len(hold...
075e0243d0c40bd96d53544f6338bf2a36d58bc8
mike-chu/insightcc
/src/word_count.py
2,288
3.890625
4
#!/usr/bin/env python2.7 """ This word_count module will read data from STDIN, split into words and output a list of tuples containing words and total counts to wc_output/wc_result.txt. Also , this module will output running median count to wc_output/med_result.txt """ import sys import string from collections import...
0c3c11a33497dbfea1a0cffcf606bc455ce6cc77
ValeraNaviton/PythonPlayground
/Leetcode/LonelyNodes.py
883
3.5625
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 visitNode(self, root) -> List[int]: result = [] if root.left: result.extend(self.visitNode(root....
00636af42dfac8d1ba5dd42cecf147b07304a05b
ValeraNaviton/PythonPlayground
/Hackerrank/ViralAd.py
674
4
4
#!/bin/python3 import math import os import random import re import sys # # Complete the 'viralAdvertising' function below. # # The function is expected to return an INTEGER. # The function accepts INTEGER n as parameter. #https://www.hackerrank.com/challenges/strange-advertising/problem def viralAdvertising(n): ...
9b9c16043a0d8f05b197fc9dfec0406bcbe7cfd0
ValeraNaviton/PythonPlayground
/Hackerrank/CorrectingLoop.py
973
4.125
4
#https://www.hackerrank.com/challenges/correctness-invariant/submissions/code/225539739 def Qsort(array, low, high): if (low < high): pivot = low i = low j = high while (i < j): # Main While Loop while array[i] <= array[pivot] and i < high: # While Loop "i" ...
3f024272d09b1cf417a656a5d0589c22b9566418
Colibri7/sorts
/selection sort.py
325
3.875
4
def selection_sort(arr): for i in range(0, len(arr) - 1): cur_min_idx = i for j in range(i + 1, len(arr)): if arr[j] < arr[cur_min_idx]: cur_min_idx = j arr[i], arr[cur_min_idx] = arr[cur_min_idx], arr[i] arr = [5, 7, 0, 14, 6, 88] selection_sort(arr) print(arr)...
56a4b96d7b6161ce36c7f65d818e12c0c7f67647
divya144/HacktoberFest2020
/Guess_Game.py
2,469
4.21875
4
import random import math #Welcome Message print("Welcome to the Guess Game") #Getting Player Name and options to play user_name = input("Enter your name : ") #Getting Choices print(user_name + " enter the choice between which you wish to guess : ") print("You have got infinite chances, chill and all the best !") pr...
8ce7fe4d5b019c79330de431d651e96528b3ef08
l2mIam/lc101
/crypto/vigenere.py
1,454
3.671875
4
""" LaunchCode lc101 Crypto assignment due 5/14/2017 11:59pm Vigenere """ __author__ = "Loren Milliman" __date__ = "5/8/2017" import unittest from helper import rotate_character, alphabet_position, is_alpha def encrypt(word, key): """ takes a string and shifts each char by rot PARAM1: word (str): A string ...
333fa37862ba6353420640df80f2dafc2123b653
nikita199801/double_linked_list
/node.py
317
3.546875
4
class Node(): # Запись (элемент) списка def __init__(self, data, prev, next): self.data = data # данные self.prev = prev # указатель на предыдущий элемент self.next = next # указатель на следующий элемент
9a131836c1c0808fe3832f3cf71460b29faf631b
Tw090131/pythonworkplace
/m_list.py
277
3.5625
4
mlist = ['aaaaa','bbbbb','cccccc'] mlist.append("lall") mlist.insert(2,'ddddd') print(mlist) for key in mlist: print(key) mlist = range(1,100) for val in mlist: print(val) mlist = list(mlist) print(sum(mlist)) square = [value ** 2 for value in range(1,11)] print(square)
11f712a72ac493022d3cfeada0612d2138e7a0ba
Tw090131/pythonworkplace
/sec9/9-4.py
783
3.65625
4
class Restaurant(): def __init__(self,restaurnat_name,cuisine_type): self.restaurnat_name = restaurnat_name #cuisine 美食 self.cuisine_type = cuisine_type self.number_served = 0 def describe_restaurant(self): print("restaurant describetion") def open_restaurant(self): print("open restaurant") def show_...
08e57ca29cbaba029d912642b40b1225f19f221f
bsaliba1/cs-coursework
/CS_110/CS-Notes/Boolean.py
327
3.921875
4
def main(): num =int(input("Please enter a number ")) if(num!=0): if (num>0): result = 20/num print(result) else: if (num<0): result = -20/num print(result) else: print("I told you not to enter 0") ...
73a661c1241e789e1310bd6665994ddf4f9b44a6
bsaliba1/cs-coursework
/CS_110/CS-Notes/CW_Booleans2py.py
158
3.578125
4
def main(): a = int(input("Choose a number, any number")) if a < 0: b = return(a-a) else: b = return(a-(a)) print(b) main()
efe4c02fc19a52ae2115ed3c1d48aa5442736e26
bsaliba1/cs-coursework
/CS_110/CS-Notes/bad_input.py
420
3.703125
4
import json def badinput(): num = 0 while num==0: num = int(input("Please enter a number:")) if num != 0: 1/num badinput() def exception_handeling(): try: fptr = open('data.txt','r') x= 1/0 except FileNotFoundError: fptr = open ('data.txt','w')#creates file print("file not found") except ZeroDivisi...