blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
545k
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
545k
5de6ac6f73174911e22c15ee3b7512db6c226bd1
jiangwqcooler/PracticeOnTensorflow
/training_graph.py
2,169
3.5625
4
""" 训练与评估类 构建 TensorFlow 数据流图 """ import model import tensorflow as tf class TrainingGraph(object): # placeholder for local data # img_local_h = tf.placeholder("float32", [None, 28, 28, 3]) # lab_local_h = tf.placeholder("int32", [None]) # channel of img , the value is 3 for RGB, 1 for gray chann...
54d1eedf796b230cc362455be7b7ccbfeb7acb9b
rizkyfarhan/fullmodul1
/logic.py
1,041
3.890625
4
# ------------------------------------ PERTEMUAN KETIGA ------------------------------------ nilai = 40 if(nilai>80) : print("Excellent!") elif(nilai>=60 and nilai<=80) : print("Good Job!") else : print("Don't Give Up!") # LATIHAN 1 angka = int(input('Masukkan angka : ')) if(angka%2 == 0) : print('...
0aebc44ed8652540acc65de0c113920286ec2f89
rizkyfarhan/fullmodul1
/loop.py
1,880
4.03125
4
# ------------------------------------ PERTEMUAN KETIGA ------------------------------------ # angka = 1 # while(angka <= 10) : # print(angka) # angka += 1 # listItem = list(range(1,11,2)) # print(listItem) # range -> # angka pertama mulainya # angka kedua selesainya (ga termasuk) # angka ketiga stepnya...
0b94a77ec45729dedc452ce76482dba3251219a1
Stanleyli1984/myscratch
/lc/prob_75_ac.py
692
3.5
4
class Solution: # @param {integer[]} nums # @return {void} Do not return anything, modify nums in-place instead. def sortColors(self, nums): if not nums: return p_1 = p = 0 p_3 = len(nums) - 1 while p <= p_3: print p, p_1, p_3, nums if num...
9a55cc5d01abc886ebcb6dac7f3d267b532f05ff
Stanleyli1984/myscratch
/lc/prob_86.py
827
3.640625
4
# Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: # @param {ListNode} head # @param {integer} x # @return {ListNode} def partition(self, head, x): dummy_heads = (ListNode(-1), ListNode(-1)) ptrs ...
e9687cedf73e803b42eeaac71bd5a40bd819486b
Stanleyli1984/myscratch
/lc/prob_222_BFC_bisect_TLE.py
1,418
3.8125
4
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param {TreeNode} root # @return {integer} def countNodes(self, root): node_count = 0 level = 0 level_n...
cd29f89690cccc1e45aa29844b1ddf6fb84d60f2
Stanleyli1984/myscratch
/lc/prob_73.py
1,344
3.5
4
class Solution: # @param matrix, a list of lists of integers # @return nothing (void), do not return anything, MODIFY matrix IN PLACE. def setZeroes(self, matrix): first_x, first_y = (None, None) for x in xrange(len(matrix)): for y in xrange(len(matrix[0])): if 0 ...
c42f0c88f3d2c801ff23345b21c7df080a2b5300
Stanleyli1984/myscratch
/lc/prob_77.py
667
3.515625
4
class Solution: # @return a list of lists of integers def __init__(self): self.results = [] self.current = [] def combine(self, n, k): if not k: return [] self.recurse(1, n, k) return self.results def recurse(self, starting, ending, remaining): ...
2691eec0e693f2ffea456e8d52ff63d2182b4d6c
Stanleyli1984/myscratch
/lc/prob_111.py
842
3.90625
4
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param root, a tree node # @return an integer min_depth = 0xffffffff def update_depth(self, depth): self.min_depth ...
05760a5eade1539803ad2de3fe34e8fb76334ee8
Stanleyli1984/myscratch
/lc/prob_206.py
462
3.796875
4
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # @param {ListNode} head # @return {ListNode} def reverseList(self, head): if not head: return None prev = None ptr = hea...
8da08d4b2a73ca6306f0ecce5dc85e3cb33bac03
NIX369/Image_Filter
/Image_Filter.py
4,379
3.8125
4
import numpy as np import time import cv2 path = input("Enter the path of the image: ") img = cv2.imread(path,1) dict = {1:"Gray Scale Image", 2:"Binary Image", 3:"Blue", 4:"Smoothing Image", 5:"Blurring the Image", 6:"Detecting the edge of an Image", 7:"Saturation", 8:"Green", 9:"Red", 10:"Value ", 11:"Hue",...
ffaab16f7ee68be9b9599cca7e2906279430d19d
trangthnguyen/PythonStudy
/integercuberootwhile.py
388
4.34375
4
#!/usr/bin/env python3 #prints the integer cube root, if it exists, of an #integer. If the input is not a perfect cube, it prints a message to that #effect. x = int(input('Enter integer number:')) guess = 0 while guess ** 3 < abs(x): guess = guess + 1 if guess ** 3 == abs(x): if x < 0: guess = - guess print('Cube ...
c58cd3ffc8bc84c8b21d8821daf55fca3f197eb3
trangthnguyen/PythonStudy
/numberstringsum.py
418
4.1875
4
#!/usr/bin/env python3 #Let s be a string that contains a sequence of decimal numbers #separated by commas, e.g., s = '1.23,2.4,3.123'. Write a program that prints #the sum of the numbers in s. x = input('Enter a string:') count = 0 sum = 0 for i in x: if i in '0123456789': count = count + 1 sum = sum + int(i) if ...
e24d59a861b003830ad8bbfecc75eac48829ad67
lugomezll/lugomezll_Lab1AlgorithmicTrading
/Cloned from _Getting Started Tutorial - Lesson 3_.py
5,200
3.609375
4
#!/usr/bin/env python # coding: utf-8 # ## Pipeline API # The Pipeline API is a powerful tool for cross-sectional analysis of asset data. It allows us to define a set of calculations on multiple data inputs and analyze a large amount of assets at a time. Some common uses for the Pipeline API include: # # * Selecti...
b746488781f821eb33c48c5ae33d9149eaedef10
shanemat/CIS-530-MP-02
/python/aig.py
13,089
3.640625
4
import sys import re import copy from enum import Enum class InputMode(Enum): """ Enumeration representing possible types of incidence input """ LIST = 1 MATRIX = 2 class Graph: """ Class representing simple directed graph """ def __init__(self): self.nodes_count = 0 ...
2099c05a3ba44b6ef5de606903e552c9f2694fa4
Valdanial/python
/robot-name/robot_name.py
685
3.59375
4
import random names_list = [] class Robot(object): def __init__(self): self.name = generate_unique_robot_name() def reset(self): self.name = generate_unique_robot_name() def generate_unique_robot_name(): name = generate_uppercase_string(2) name += generate_digit_string(3) if name i...
88ada59e580512949e857b32892a599596272eb6
kovach10/pythonlab
/lab_5/task_1.py
162
3.75
4
import math a = float(input("enter a: ")) n = int(input("enter n: ")) ans = 0 for i in range(n): ans += math.log(math.fabs(a**(n-i))) print(ans)
18f2bd97a2e55bb6408451cc75184a399ad119a2
YusraMasoodUIT/Assignment-3.1---3.15
/Ex 3.5.py
871
3.96875
4
print("Yusra Masood , 18B-093-CS , Section A") print("Ex 3.5") print("This program will tell you the words that have four letters in it") list = [] #create an empty list num = eval(input("how many words do you want to enter "))#ask the user for the number of inputs a = 1 while a != num + 1: # loop to enter the wo...
46f088d9938e1e1fbd9f2b3edcfa55c5fa9a83d3
YusraMasoodUIT/Assignment-3.1---3.15
/Ex 3.13.py
1,244
4.03125
4
print("Yusra Masood , 18B-093-CS , Section A") print("Ex 3.13") print("Use of help function ") def average(num1 , num2): 'function average takes 2 integers as input and calculates the average of them' sum = num1 + num2 avg = sum/2 print("The average is ") return avg def noVowel(sen): ...
088e67f95b5d4e226d360a31d1300078deec5800
vikramtharakan/Basic_Matrix_Math
/basic_matrix_algebra/matrix_algebra.py
3,938
4.40625
4
import math import matplotlib.pyplot as plt class Matrix: """ Matrix Class for creating a matrices that we can then manipulate with basic functions Attributes: numbers: List of all numeric values in matrix. No row/column structure row: Number of rows in matrix col: Number of column...
229a6f283d51cebbbdfed27cad8cc7d25290511f
koking0/PythonFullStack
/第一模块_开发基础/2019-12-19/双色球选购作业.py
1,789
4.03125
4
''' 作业:双色球选购 1 双色球(假设一共八个球,6个红球,球号1-32、2个蓝球,球号1-16) 2 确保用户不能重复选择,不能超出范围 3 用户输入有误时有相应的错误提示 4 最后展示用户选择的双色球的号码 效果图:双色球作业展示 升级需求: 1 一个while循环 思路: 1.用列表choose记录选择的球 2.while循环更新falg的值 3.while循环中: 提示用户选择; 判断选择是否超出范围; 判断选择是否重复; 判断选择是否完成 ''' red_choose = [] blue_choose = [] while True: if len(red_choo...
109dad0040f839bdea627113d4cfd00f00eb7ccc
koking0/PythonFullStack
/第一模块_开发基础/课件/day1_基础语法/用户输入.py
426
3.96875
4
name = input("输入你的名字:") age = float(input("输入你的年龄:")) height = input("输入你的身高:") question = input("你是不是全身都黑:") # msg = ''' ---------Personal Info---------- Name : %s Age : %f Height : %s Answer : %s ----------End------------------- ''' % (name,age,height,question) print(msg) if question == "Y" or question ...
51dbf9106eaa544feeb2d93a43d11b9e4386b259
koking0/PythonFullStack
/第二模块_函数编程/课件/day4_常用模块/备课用/日期.py
857
3.65625
4
# import pickle data = {'k1':123,'k2':'Hello'} # # # pickle.dumps 将数据通过特殊的形式转换位只有python语言认识的字符串 # p_str = pickle.dumps(data) # 注意dumps会把数据变成bytes格式 # print(p_str) # # # pickle.dump 将数据通过特殊的形式转换位只有python语言认识的字符串,并写入文件 # with open('result.pk',"wb") as fp: # pickle.dump(data,fp) import json # json.dumps 将数据通过特殊的形式...
311324690170a60d696aefff2562e86c72834d2d
koking0/PythonFullStack
/第二模块_函数编程/课件/day3_函数编程/闭包.py
197
3.546875
4
def outer(): name = "小猿圈,自学编程" def inner(): print("Inner",name) return inner func = outer() # 返回的是inner的内存地址, inner func() #inner()
b1838396c02c752eb66255a8371762f0aec76da7
koking0/PythonFullStack
/第二模块_函数编程/课件_copy/day3_函数编程/列表生成式.py
221
3.65625
4
# # a = [1,3,4,6,7,7,8,9,11] # # for index,i in enumerate(a): # #print(index,i) # a[index] +=1 # # # print(a) a = [1,3,4,6,7,7,8,9,11] # a = list(map(lambda x:x+1,a)) # print(a) a = [i**i for i in a ] print(a)
ade68a8e32731a8437cb8bab7a486ab4bf76db39
koking0/PythonFullStack
/第二模块_函数编程/exam.py
745
3.59375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2020/1/18 下午9:08 # @File : exam.py # @Project : PythonFullStack # @Software : PyCharm # ---------------------------------------------- # ☆ ☆ ☆ ☆ ☆ ☆ ☆ # >>> Author : alex # >>> QQ : 2426671397 # >>> Mail : alex18812649207@gmail.com # >>> G...
01e3b245c431acac5589cac4fa875d61a1ef6f67
koking0/PythonFullStack
/第一模块_开发基础/课件/day1_基础语法/流程控制.py
1,621
3.96875
4
# today_weather = "sun_day" # # #单分支 # if today_weather == "rain_day": # print("take your umbrella with you ") # 双分支 # age_of_oldboy = 58 # if age_of_oldboy > 50: # print("Too old, time to retire..") # print("hahah") # else: # print("还能折腾几年!") # # age = 35 # # if age < 12: # print("you are child...
936bed9d61c1769c69bed22e50e00b92733455b7
crystalattice/Fantasy_RPG
/Adv_Dark_Deep/dice_roller.py
1,634
4.03125
4
from random import randint from typing import Any, Union def rand_num_gen(choice: int) -> int: """Get a random number to simulate a d6, d10, or d100 roll.""" die: Union[int, int] = 1 if choice == 6: # d6 roll die = randint(1, 6) elif choice == 10: # d10 roll die = randint(1, 10) ...
cc1ca4c04649c9043952a2693951476df77f6ac8
xglxia/MIT-6.0001-Course
/ps1/ps1c.py
2,044
3.953125
4
# -*- coding: utf-8 -*- """ Created on Thu Jul 22 20:47:46 2021 @author: Guoli Collaborator: Joshua William Fleming """ #Assignment 1 #Part C #Task: Determine the required savings rate to afford downpayment in 3 years. annual_salary = float(input('Please enter your annual salary:')) while annual_salary < ...
d3fd871df4268691da7dd5b54e86167e950b6a00
anandashish456/python_testing
/threading.py
777
3.53125
4
import threading import os, time def square(num): print("PID of square thread is {}".format(str(os.getpid()))) print("Name of square thread is {}".format(threading.current_thread().name)) print(num*num) def cube(num): print("PID of cube thread is {}".format(str(os.getpid()))) print("Name of cube...
77d0ec2e9b0033ac30d13a22ada20393e78dec5c
whoget/practical-python-opencv
/masking.py
1,249
3.59375
4
import numpy as np import argparse import cv2 # Parse the command line arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required=True, help="Path to the image") args = vars(ap.parse_args()) # Load and display the original image image = cv2.imread(args["image"]) cv2.imshow("Original", image) c...
a7e6c5cd9d9d8c27dd2bdfd09c4ce3805f6930e7
muziyuchong1/python
/Python closures.py
376
3.84375
4
#对象是带有附加方法的数据,闭包是带有数据的函数()方法 def make_counter(): i = 0 def counter():# counter is a closure nonlocal i i+=1 return i return counter a = make_counter() b = make_counter() print( a(),a(), b(),b()) #闭包允许您将变量绑定到函数,而不将它们作为参数传递
37772d48011eafb49e9b0b7161930153f2037598
kshruti1410/python-assignment
/src/q1.py
1,158
3.515625
4
import mysql.connector from mysql.connector import Error def execute_query_to_point_table(): """"Execute sql query to point employees table""" MY_CURSOR.execute("select * from employees") def get_ten_records_of_employee_details_of_table(size): """" Implementation of generator function ,Returning 10...
f22285f06df5b6c8d79febe605d7471919356199
kshruti1410/python-assignment
/src/q2.py
822
4.15625
4
""" abc is a by default abrstract class present """ from abc import ABC, abstractmethod class Person(ABC): """ inherit ABC class """ @abstractmethod def get_gender(self): """ skipping the function """ pass class Female(Person): """ this class return gender of a person """ def...
bcb068344d4db4f5ae984ad6f6d63a378587ad83
Abed01-lab/python
/notebooks/Handins/Modules/functions.py
1,289
4.28125
4
import csv import argparse def print_file_content(file): with open(file) as f: reader = csv.reader(f) for row in reader: print(row) def write_list_to_file(output_file, lst): with open(output_file, 'w') as f: writer = csv.writer(f) for element in lst: f....
d0d00052a67aa24475eeb32e74e61747002ca500
allisonlynnbasore14/TextMining
/Project3_Abasore.py
3,708
3.953125
4
import requests import string """ Project Plans: to sort the requencies of words for each book by Jane Austen. Then, adjust with ratio for size of book. Compare her most frequent words from the beginng,middle, and end of her career. """ def adjust_factor(max, freq): """ take frequency and max frequency as an i...
df2a52c105c02cbbc6b8971e26ac064dcc2a6315
Weless/leetcode
/python/树/637. 二叉树的层平均值.py
1,112
3.59375
4
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None from typing import List class Solution: def averageOfLevels(self, root: TreeNode) -> List[float]: if not root: return [] from collections import deque queue = dequ...
ca8788e76c54f03284e37c8039d0540b02cc2a55
Weless/leetcode
/python/队列/406. 根据身高重建队列.py
930
3.78125
4
from typing import List # 解题思路:先排序再插入 # * 1.排序规则:按照先H高度降序,K个数升序排序 # * 2.遍历排序后的数组,根据K插入到K的位置上 # * # * 核心思想:高个子先站好位,矮个子插入到K位置上,前面肯定有K个高个子,矮个子再插到前面也满足K的要求 # [7,0], [7,1], [6,1], [5,0], [5,2], [4,4] # 再一个一个插入。 # [7,0] # [7,0], [7,1] # [7,0], [6,1], [7,1] # [5,0], [7,0], [6,1], [7,1] # [5,0], [7,...
9108c975d35e8567de4fc0090b346ac453b5642b
Weless/leetcode
/python/树/951. 翻转等价二叉树.py
585
3.6875
4
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def flipEquiv(self, root1: TreeNode, root2: TreeNode) -> bool: if root1 == root2: return True if not root1 or not root2 or roo...
b43497739df66a2244758081ef7cd0cc55db693f
Weless/leetcode
/python/栈/331. 验证二叉树的前序序列化.py
721
3.65625
4
class Solution: def isValidSerialization(self, preorder: str) -> bool: stack = [1] i = 0 while i < len(preorder): if not stack: break if preorder[i] == ',': i+=1 elif preorder[i] == '#': stack[-1]-=1 if stack...
bc95d518bf5b36dbcbaceb5ed69487a3a97f39a6
Weless/leetcode
/python/字符串/125. 验证回文串.py
314
3.734375
4
class Solution: def isPalindrome(self, s: str) -> bool: t = '' for i in s: if i.isdigit(): t+=i elif i.isalpha(): t+=i.lower() return t == t[::-1] s = Solution() test = "A man, a plan, a canal: Panama" print(s.isPalindrome(test))
36e21c8ee00bb2f4309d8a9f18cfc0cf4eea12ca
Weless/leetcode
/python/链表/147. 对链表进行插入排序.py
1,142
3.8125
4
class ListNode: def __init__(self, x): self.val = x self.next = None # start指向部分有序的链表 # 当出现链表节点逆序的情况,出现逆序的节点插入到start指向的部分有序的链接中 class Solution: def insertionSortList(self, head: ListNode) -> ListNode: if not head: return head start = head cur = head.next pre = he...
9403ba938f8b0b621a2a51c363d8b28d1464a75a
Weless/leetcode
/python/程序员面试金典/面试题 08.03. 魔术索引.py
673
3.546875
4
from typing import List class Solution: def findMagicIndex(self, nums: List[int]) -> int: def binarySearch(nums,i,j): if self.res != -1: return if i <= j : mid = (i+j)//2 if nums[mid] == mid : self.res = mid bina...
7d2d0ae6f29d13b29cc9ce770de688a91b38b58a
Weless/leetcode
/python/剑指offer/面试题40. 最小的k个数.py
420
3.65625
4
from typing import List class Solution: def getLeastNumbers(self, arr: List[int], k: int) -> List[int]: if k == 0: return [] result = [] arr.sort() count = 0 for i in arr: result.append(i) count +=1 if count == k: ...
ea01165b8a27e783181912d103cef78b638aaeb5
Weless/leetcode
/python/general/1022. 从根到叶的二进制数之和.py
521
3.5625
4
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def sumRootToLeaf(self, root: TreeNode) -> int: def dfs(root,path): if root: path += str(root.val) if not root.left and not root.rig...
8090a01ef78b1d7887e0ec4129178c6528d9092d
Weless/leetcode
/python/general/1200. 最小绝对差.py
779
3.578125
4
class Solution: def minimumAbsDifference(self, arr): arr.sort() result = [] minList = [] if len(arr) == 2: return [arr] for i in range(1,len(arr)): minList.append(arr[i]-arr[i-1]) minNum = min(minList) for num in range(len(minList)): ...
64bb9ccb9638262f54aee685e7aca31fe32b8ace
Weless/leetcode
/python/dfs/127. 单词接龙.py
1,391
3.65625
4
from typing import List class Solution: def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int: if len(wordList) < 2 or endWord not in wordList: return 0 from collections import deque,defaultdict d = defaultdict(list) tmp = [beginWord] + wordList if beginWor...
33d1df1043776b642844814b74d42ed1574bfa6d
Weless/leetcode
/python/常用算法/归并排序.py
606
3.921875
4
def mergeSort(alist): if len(alist) <= 1: return alist mid = len(alist)//2 left = mergeSort(alist[:mid]) right = mergeSort(alist[mid:]) return merge(left,right) def merge(left, right): # left与right的下标指针 l, r = 0, 0 result = [] while l < len(left) and r < len(right): ...
94d5b51027e50210a32d9ab54a315011d5a5890c
Weless/leetcode
/python/回溯法/216. 组合总和 III.py
543
3.546875
4
from typing import List class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: def dfs(path,k,target,start): if k == 0: if target == 0: res.append(path[:]) return return for i in range(star...
fc3e55050de45ea1e075a38a2e7c7039a79d81af
Weless/leetcode
/python/常用算法/非递归后续遍历.py
772
3.703125
4
# 使用栈存储结点; # 当结点存在或者栈不为空,判断结点; # 当结点存在,结点值保存,结点入栈,并将指针指向结点的右子树; # 当栈不为空,结点出栈,并将指针指向左子树; # 重复2-4直到结果产生; # 逆序输出结果,利用Python列表的-1. class Solution(object): def postorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ ret = [] stack = [] while...
af599a97fbcd1071fc0aab80049ee4f5f152ae3c
Weless/leetcode
/python/字符串/1763. 最长的美好子字符串.py
772
3.515625
4
class Solution: def longestNiceSubstring(self, s: str) -> str: max_len = 0 max_str = "" for i in range(len(s)): j = i+1 while j < len(s)+1: tmp = s[i:j] if self.checkBeautifulStr(tmp): if len(tmp) > max_len: ...
98db4b8ebff5a75174191a066c0ae62ad0fc712e
Weless/leetcode
/python/hash/599. 两个列表的最小索引总和.py
743
3.59375
4
from typing import List class Solution: def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]: d = dict() for i,v in enumerate(list1): d[v] = i res = [] for i,v in enumerate(list2): if v in d: index = i + d[v] ...
4e7c56af381978e78d5c995b9df39411f374f193
Weless/leetcode
/python/general/349. 两个数组的交集.py
1,145
3.796875
4
from typing import List class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: set1 = set(nums1) set2 = set(nums2) return self.set_intersection(set1,set2) def set_intersection(self,set1,set2): if len(set1) > len(set2): return self.se...
6863d06f8d80a4f67b68400f4c5bcec6f9a5be46
Weless/leetcode
/python/周赛/197周赛/5460. 好数对的数目.py
570
3.578125
4
from typing import List class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: dic = {} for i in nums: if i not in dic: dic[i] = 1 else: dic[i] += 1 def multi(x): res = 1 for i in range(x-1,x+1): ...
2fa55b4de46ac3c131bd256a6e86f0fed79db18c
Weless/leetcode
/python/剑指offer/面试题30. 包含min函数的栈.py
551
3.78125
4
class MinStack: def __init__(self): """ initialize your data structure here. """ self.stack = [] self.minNum = [] def push(self, x: int) -> None: self.stack.append(x) if self.minNum == [] or x <= self.minNum[-1]: self.minNum.append(x) d...
8485c0364d0e07a47aa98dd9d50e3e1fb410d956
Weless/leetcode
/python/general/1313. 解压缩编码列表.py
734
3.5
4
from typing import List # class Solution: # def decompressRLElist(self, nums: List[int]) -> List[int]: # l = len(nums) # i = 1 # result = [] # while i <= l: # result += [nums[i]] * nums[i-1] # i+=2 # return result s = Solution() nums = [1,1,2,3] prin...
e8f9840bbc0d7a51e277676226c5a34466f4574b
Weless/leetcode
/python/数组/896. 单调数列.py
1,063
3.71875
4
from typing import List class Solution: def isMonotonic(self, A: List[int]) -> bool: tag = 0 up,down = True,True for i in range(1,len(A)): if A[i] < A[i-1]: up = False break if up: return True for i in range(1,len(A)): ...
d2b9fb47bd4ffdf0b8d4fa346f751af70939e8c7
Weless/leetcode
/python/字符串/1408. 数组中的字符串匹配.py
539
3.859375
4
from typing import List class Solution: def stringMatching(self, words: List[str]) -> List[str]: res = [] for word1 in words: for word2 in words: if word1 != word2: if len(word1) <= len(word2): continue if wo...
b24730e33f0dcc649c038b83d139da901f192a2a
Weless/leetcode
/python/lru/146. LRU缓存机制.py
1,896
3.765625
4
class DNode: def __init__(self,key=0,value=0): self.pre = None self.next = None self.key = key self.value = value class LRUCache(object): def __init__(self, capacity): """ :type capacity: int """ self.cache = dict() self.capacity = capaci...
e6d282bdb1afcb55bdafc85fa69cb4ac72cd4f15
Weless/leetcode
/python/general/1252. 奇数值单元格的数目.py
509
3.640625
4
from typing import List class Solution: def oddCells(self, n: int, m: int, indices: List[List[int]]) -> int: alist = [[0]*m for _ in range(n)] # print(alist) for x,y in indices: for i in range(n): alist[i][y] += 1 for j in range(m): al...
c86e736affbf576f41dc3e494236503a568202db
Weless/leetcode
/python/剑指offer/面试题21. 调整数组顺序使奇数位于偶数前面.py
1,172
3.5
4
from typing import List class Solution: def exchange(self, nums: List[int]) -> List[int]: from collections import deque d = deque() for i in nums: if i % 2 != 0: d.appendleft(i) else: d.append(i) return list(d) class Solutio...
bd016b86133192808256fb43cae1c9afd8500b15
Weless/leetcode
/python/general/219. 存在重复元素 II.py
531
3.5
4
from typing import List class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: if len(nums) == 0: return False aMap = {} for id,v in enumerate(nums): if v not in aMap.keys(): aMap[v] = id else: i...
573420db0d9000aac1e31e6b4eb2b3106fd494fe
Weless/leetcode
/python/general/1295. 统计位数为偶数的数字.py
286
3.65625
4
from typing import List class Solution: def findNumbers(self, nums: List[int]) -> int: count =0 for num in nums: if len(str(num)) % 2 == 0: count +=1 return count s = Solution() nums = [12,324,2,6,7896] print(s.findNumbers(nums))
c1e7f70159c0ff74250ad5dc68b33ff1219fe145
Weless/leetcode
/python/dfs/529. 扫雷游戏.py
2,736
3.59375
4
from typing import List class Solution: directions = [(1,0),(-1,0),(0,-1),(0,1),(1,-1),(1,1),(-1,1),(-1,-1)] def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]: i,j = click if board[i][j] == 'M': board[i][j] = 'X' return board m,n =...
57f32716656a395a4f48d883da2b9eab5fb859e9
Weless/leetcode
/python/剑指offer/面试题42. 连续子数组的最大和.py
532
3.53125
4
from typing import List class Solution: def maxSubArray(self, nums: List[int]) -> int: if not nums: return 0 n = len(nums) dp = [0]*n dp[0] = nums[0] # dp[i] 代表以元素nums[i] 为结尾的连续子数组最大和 for i in range(1,n): if dp[i-1]>0: dp[i] = d...
348d427c180da89d273bfe088ba025e50c606b92
Weless/leetcode
/python/字符串/58. 最后一个单词的长度.py
354
3.75
4
class Solution: def lengthOfLastWord(self, s: str) -> int: if not s: return 0 words = s.split() res = 0 for i in words[-1]: if i.isalpha(): res +=1 else: return 0 return res s = Solution() test = "Hello Worl...
95b54de8921722ee84e243ba3c3e619b96b69d96
Weless/leetcode
/python/剑指offer/面试题51. 数组中的逆序对.py
1,112
3.671875
4
from typing import List class Solution: def reversePairs(self, nums: List[int]) -> int: def mergeSort(nums, start, end): if start >= end: return mid = (start + end) >> 1 mergeSort(nums, start, mid) mergeSort(nums, mid + 1, end) merge(nums, start,...
bccbc0f35e8d4b6bdbc865a0af2dddd9e6e8c9f1
Weless/leetcode
/python/程序员面试金典/面试题 17.12. BiNode.py
482
3.578125
4
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def convertBiNode(self, root: TreeNode) -> TreeNode: self.pre = self.ans = TreeNode(-1) def dfs(root): if not root: return dfs(root.left) ...
49f4242c6d40b77787f0d1434ec7ad46a668ff3b
Weless/leetcode
/python/数组/170. 两数之和 III - 数据结构设计.py
837
3.859375
4
class TwoSum: def __init__(self): """ Initialize your data structure here. """ self.res = [] self.isSorted = False def add(self, number: int) -> None: """ Add the number to an internal data structure.. """ self.res.append(number) ...
78ec212c2700061af25da1d98f3b762af31d1219
Weless/leetcode
/python/剑指offer/面试题53 - I. 在排序数组中查找数字 I.py
439
3.546875
4
from typing import List # 二分查找 class Solution: def search(self, nums: List[int], target: int) -> int: import bisect left,right = bisect.bisect_left(nums,target),bisect.bisect_right(nums,target) return right - left class Solution: def search(self, nums: List[int], target: int) -> int: ...
b9f095334c64e9b16087fba55eddf4589e602464
Weless/leetcode
/python/前缀和/525. 连续数组.py
843
3.5625
4
from typing import List class Solution: def findMaxLength(self, nums: List[int]) -> int: # 前缀和字典: key为1的数量和0的数量的差值,value为对应坐标 hashmap = {0:-1} # 当前1的数量和0的数量的差值 counter = ans = 0 for i,num in enumerate(nums): # 每多一个1,差值+1 if num: counter...
5f4b2a213b37945b145719f7122e37591dc43099
Weless/leetcode
/python/hash/692. 前K个高频单词.py
512
3.53125
4
from typing import List class Solution: def topKFrequent(self, words: List[str], k: int) -> List[str]: from collections import defaultdict d = defaultdict(int) for word in words: d[word]+=1 res = [] for key,value in d.items(): res.append((key,value))...
66f13c1dd9976c712f334b6739d4782a7c8cc9e5
Weless/leetcode
/python/树/863. 二叉树中所有距离为 K 的结点.py
1,163
3.5625
4
from typing import List class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def distanceK(self, root: TreeNode, target: TreeNode, K: int) -> List[int]: ans = [] def dfs(root): if not root: return -1 ...
db6b09f00849052baac31ca02512619ff97b76e0
JEub/PythonFiles
/Arcade/arrayChange.py
818
3.640625
4
"""You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input.""" def arrayChange(inputArray): # Setting change as list in case later you want the output of each c...
4b823d158f8335c444c5ca817e9f5d749eddea2c
Doomvortex/aer
/hello.py
62
3.578125
4
name = input("Name please?") print("Nice job" + name + "!!")
ad7819e0dde2bf2b8583f992ec18f7ef5261cd0b
Intro-to-python/homework1-MaeveFoley
/problem2.py
534
4.34375
4
#homework1 #Due 10/10/18 # Problem 2 #Write a Python program to guess a number between 1 to 9. # User is prompted to enter a guess. If the user guesses wrong then #the prompt appears again until the guess is correct, on successful guess, #user will get a "Well guessed!" message, and the program will exit. #(Hint use a...
a167c993b92f31f6caaf9f8675443dc2594f4341
etemical/python
/文件、图片框架操作/operfile/myOperFile.py
3,452
4.0625
4
"""打开文件,默认是读""" import os f = open("question.txt") print(f.readable()) # ch = f.read(5)#读取5个字符 # print(ch) # print(f.read()) # ch = f.readline() # 参数n同样指定读取的字符数,读取的都是上次一没读完的剩下的部分 # print(len(ch)) ch = f.readlines() # 一次性读完所有的返回一个list print(ch,len(ch)) f.close() print("==================================================...
445b42c2bfa4c2c1c790faf89be91f8b1d834d99
ZhuRonghui/program
/Test01.py
290
4.03125
4
hours = input("Enter Hours:") rate = input("Enter Rate:") try: hours = float(hours) rate = float(rate) if hours > 40: print("Pay:", (hours - 40) * 1.5 * rate + 40 * rate) else: print("Pay:", hours * rate) except Exception as e: print(e)
1c5c0b0ae71ae6aac287256b27465d37b6f410df
archepro84/Algorithm_Interview
/p153_Group_Anagrams.py
979
3.546875
4
import collections import heapq import functools import itertools import re import sys import math import bisect from typing import * # 애너그램은 문자열 정렬을 하면 같은 값을 가진다. "문자열 배열을 받아 애너그램 단위로 그룹핑 하라" class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: anagrams = collections.defaultdict(...
83505fd0aa99599e4f6a55a0340082ec2602cb41
AbrahamZak/Network-Science
/FriendshipNetworkAnalysis.py
1,151
3.703125
4
import networkx as nx import matplotlib.pyplot as plt if __name__ == '__main__': #load in our data g = nx.read_adjlist(path="frienship_network.txt", delimiter=" ", comments="#", create_using=None, nodetype=None, encoding="utf-8") #print the connected components print("Number of connected components: "...
232e7a4410a686889c0d196e828577158eb90e7c
Megha3636/Launchpad-Assignments
/problem1.py
144
3.890625
4
name = input("Enter name:") age = int(input("Enter age:")) result = 100 + (2020-age) print(f"you will be 100 years old in the year {result}")
aa5483e124907b374410de77cff466226135528d
detiuaveiro/cd2021-final-97880_100055
/slave.py
16,058
3.53125
4
#Definitely not a botnet from const import * import base64 import socket import struct import selectors import time import string import pickle import copy import datetime BASE62 = string.ascii_lowercase+string.ascii_uppercase+string.digits def encode(num, alphabet): """Encode a positive number into Base X and re...
edac7d307b6001b92023f46bddd49fd29af13715
williamwbush/codewars
/unfinished/algorithm_night.py
2,116
4.15625
4
# Problem 1: # https://www.hackerrank.com/challenges/counting-valleys/problem # Problem 2: # You found directions to hidden treasure only written in words. The possible directions are "NORTH", "SOUTH","WEST","EAST". # "NORTH" and "SOUTH" are opposite directions, as are "EAST" and "WEST". Going one direction and coming ...
12798dc33791ecbb9b51c7f00f8776b044988c33
williamwbush/codewars
/solved_5_kyu/josephus_permutation.py
1,471
3.875
4
# https://www.codewars.com/kata/5550d638a99ddb113e0000a2/solutions/python # This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege. # Refusing to surrender to the ...
d7b4b736b94ca9d5d7c8bc0d21c6e997b989717d
williamwbush/codewars
/solved_5_kyu/diophantine_equation.py
1,398
3.84375
4
# https://www.codewars.com/kata/554f76dca89983cc400000bb # In mathematics, a Diophantine equation is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied. # In this kata we want to find all integers x, y (x >= 0, y >= 0) solutions of a diophantine equati...
2dff234fa43a392f0dcc9adaee0893ff169f8635
williamwbush/codewars
/unfinished/paperfold.py
324
3.671875
4
# i = 8 # print (i & (i & -i) << 1) # print (i & ((i & -i) << 1)) # print ((i & (i & -i)) << 1) from math import sqrt primes = [] for i in range (2, 101): factors = [] for n in range(1, i + 1): if i % n == 0: factors.append(n) if len(factors) <= 2: primes.append(i) print(primes)...
a08c1d70f50820ebd29a57103cef9c5bfe7ebe29
goingforbrooke/meme_tracker
/show_images.py
732
3.546875
4
"""Display collected images in a web browser. Run `python3 show_images.py` and navigate to `http://localhost:5000<http://localhost:5000>` in a web browser. """ from flask import Flask, render_template, url_for from pathlib import Path app = Flask(__name__, static_folder='saved_images/full', template_folder='web/temp...
5372d2c467497cbe97eec54e2e2caa94ece36403
AhmadMusa089/python-basic
/shamim2.py
556
3.5
4
namem = input ("Enter your name :") namef =input ("Enter your father name :") namemo =input ("Enter your mother name :") age = input ("Your age :") school = input ("Your School :") gpa = input ("Input your GPA: ") print ("About your self") print ("----------------------") print ("Name : " +namem) print ("F...
2058d274abf731fafc94eadb50bf63f23aeaabef
sdelpercio/Sprint-Challenge--Data-Structures-Python
/reverse/reverse.py
1,615
4
4
class Node: def __init__(self, value=None, next_node=None): self.value = value self.next_node = next_node def get_value(self): return self.value def get_next(self): return self.next_node def set_next(self, new_next): self.next_node = new_next class LinkedList:...
288d8d62c5b15e6a5bb9fa266539dd8f03d4615d
userkaranb/pants-viewer
/server/services/DatabaseRowToProductTranslator.py
1,604
3.546875
4
"""Translate database rows to models""" from models.InventoryItem import InventoryItem from models.Product import Product class DatabaseRowToProductTranslator(object): """Static class translating a database row to a map, mapping product id to product""" @staticmethod def translate_rows_to_model(rows): ...
ee497cc6d0d6ef9b18d773b89b3369c860293b85
462454/pythonDataStructures
/code/排序.py
5,214
3.90625
4
# 冒泡排序 def bubbleSort(arr): for i in range(1, len(arr)): for j in range(0, len(arr) - i): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] return arr print(bubbleSort([24, 48, 65, 48, 22, 12, 36, 98, 45])) def bubbleSort(alist): for passnum in range(len...
b3f94df3babc2810020a3aa8d5c71efbab0234f4
kevinelong/vamaze
/board.py
1,077
3.796875
4
import random class Board: def __init__(self, size=9): self.size = size self.clear() self.player_location = self.place_random() def place(self, x, y, symbol): self.board[y][x] = symbol def place_random(self, symbol="^"): occupied = True while occupied: ...
749a6fbefdc2792c7c00b5cbb1b242eeb0fd0298
lpianta/LucaPianta_Learnn
/rock_paper_scissors/RockPaperScissors.py
18,089
3.75
4
import random import tkinter as tk LARGE_FONT = ("Verdana", 12) # Images rock_img = "imgs/rock.png" paper_img = "imgs/paper.png" scissors_img = "imgs/scissor.png" player_img = "imgs/player.png" computer_img = "imgs/robot.png" win_player_img = "imgs/player_biceps.png" win_computer_img = "imgs/robot_biceps.png" compute...
5736a7ae8ed15714aad0fef1936419cb63a9acd0
JCrawford1122/ups_routing
/hashTable.py
2,647
3.8125
4
# hashTable.py # Author: Justin Crawford # Student ID: 000918681 # Date: 5/17/2020 # HashTable class using chaining. import csv from package import Package class HashTable: # constructor sets initial capacity of the hash table # O(1) def __init__(self, initial_capacity=40): # initialize the hash...
6be6f247af34e40837c10f7481e1730387087d50
bottlekids/simple_tiny_flask_api
/tiny_api.py
949
3.671875
4
from flask import Flask,jsonify import requests # First we get the latest news in Germany with the help of NewsAPI (https://newsapi.org/) url = ('http://newsapi.org/v2/top-headlines?' 'country=de&' 'apiKey=76fb69866b1d42fdb58866ba66f4f45c') response = requests.get(url) news_list = response.json()...
897b8e71306efd653c16e0a879202cc555ba463b
daren996/Information-Retrieval-System-for-Amazon-Products
/IR/search.py
6,426
3.5625
4
""" Search program 1 index_arr is a list contains indexes of several search terms 2 the result is a list contains all result doc_ids """ import math import operator import conf import linecache import json class Search: def __init__(self, index_arr): # list of index: two level map : word_id -> d...
b24197f3659b6bcd0fdd87de00376281c1f60fe6
stockhamc/Industry-4.0-GUI
/GUI_Feb22.py
9,576
3.703125
4
import tkinter as tk from tkinter import * # python 3 from tkinter import font as tkfont # python 3 #import Tkinter as tk # python 2 #import tkFont as tkfont # python 2 class SampleApp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.title...
615b00ffe0a15294d2b65af008f6889ef622e005
igauravshukla/Python-Programs
/Hackerrank/TextWrapper.py
647
4.25
4
''' You are given a string S and width w. Your task is to wrap the string into a paragraph of width w. Input Format : The first line contains a string, S. The second line contains the width, w. Constraints : 0 < len(S) < 1000 0 < w < len(S) Output Format : Print the text wrapped paragraph. Sample Input...
1e843d06650cefe912212a5b96f0186ace3389ae
HBCompass/hackbright
/Exercise08/markov.py
3,071
3.6875
4
#Pair Programming - partnered with Lauren Chow #!/usr/bin/env python #import sys import random import twitter #tapi = twitter.Api() #print tapi.VerifyCredentials() def make_chains(corpus): """Takes an input text as a string and returns a dictionary of markov chains.""" # This section reads the corp...
fe4e1ff98d3bbc8865da3d39e9bf5e124cd4e3e8
mafer564/piedra-papel-python
/juego.py
1,144
3.984375
4
print("Piedra papel o Python") usuario=input("con que quiere jugar? piedra=0, papel=1 o Python=2") opciones={ "piedra"=="0" "papel"=="1" "Python"=="2" } import random computadora=random.choice([0,2]) print("computadora: ",computadora) print("usuario: ",usuario) if computadora==usuario: print("empate") elif comp...