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
5d9a6b609128071afd4fc54db8c4b8751e575b0b
vonunwerth/TrivialPursuitFramework
/database_statistics.py
2,364
3.96875
4
import codecs import sqlite3 def create_connection(db_file): """ Create a database connection to a SQLite database :param db_file: SQLite file containing the database :return: Connection """ try: connection = sqlite3.connect(db_file) return connection except sqlite3.Error a...
372ce9f69e2146eab9a4f155c4af3d1c38cbba61
weitingchou/jagereye
/framework/jagereye/brain/utils.py
997
3.8125
4
import json def jsonify(s, encoding=None): """Deserialize a str/bytes object, containing a JSON document, to a dict object. XXX: This wrapper is used to enforce the JSON standard which specified key or value should be in double quotes, however, this wrapper would cause side-effect when ...
0fca9aaf7cc908ae116a2ea88831bf67ae730cdd
alexandreyy/license_plate_recognizer
/models/quadrilateral.py
2,256
3.703125
4
''' Created on 06/04/2015 @author: Alexandre Yukio Yamashita ''' import math class Quadrilateral: ''' Quadrilateral with 4 points 2D. ''' def __init__(self): self.points = [] def add_point(self, point): ''' Add point if point quadrilateral is not complete. ...
8805998bbb4672bff80c5ba135e2175df2ff64a6
ndmnhat71/truck_dat295
/src/path_planning/scripts/model.py
3,644
3.578125
4
from math import * import matplotlib.pyplot as plt from helper_functions import * class Point: def __init__(self, x , y): self.x = x self.y = y class Vector: def __init__(self, x , y): self.values = (x,y) def magnitude(self): #magnitude of the vector (x,y)= self....
6a1716818b21e765ba02e275553467a060c21269
Kids-Hack-Labs/Fall2020
/Activities/Week02/Code/activity1_suggested_solution.py
737
4.125
4
""" Kids Hack Labs Fall 2020 - Senior Week 02: Python Review Activity 1 """ #Step 1: Function that takes 2 arguments and displays greater def greater(num_a, num_b): if num_a > num_b: print(num_a, "is greater than", num_b) else: print(num_b, "is greater than", num_a) #step 2: Inp...
1c7b497ffce28f0a1f2faa790eca25693b2814c1
Kids-Hack-Labs/Fall2020
/Activities/Week04/Code/act2.py
1,116
4.3125
4
""" Kids Hack Labs Fall 2020 - Senior Week 04: Introduction to Classes Activity 2 """ #Suggested answer: class Animal(): def __init__(self, _type, _name, _legs, _sound): self.type = _type self.name = _name self.legs = int(_legs) self.sound = _sound def walk(self)...
c58359a746beaaa275045aafa9d1509b028a2760
Kids-Hack-Labs/Fall2020
/Homework/W02/Code/w02_hw_suggested_solution.py
1,213
4.125
4
""" Kids Hack Labs Fall 2020 - Senior Week 02: Python Review Homework: Number guessing game """ #Step 1: random module import import random #Step 2: application main entry point def main(): #setup (steps 2.1 through 2.5) random.seed() tries = 5 #total tries granted guesses = 0 #total ...
51a4127c314722d0a562f5786cb238bbe251631b
tmishinev/Recommendation_Watson_Dataset
/user_user.py
5,316
3.75
4
import pandas as pd import numpy as np import matplotlib.pyplot as plt import pickle # create the user-article matrix with 1's and 0's def create_user_item_matrix(df): ''' INPUT: df - pandas dataframe with article_id, title, user_id columns OUTPUT: user_item - user item matrix Desc...
82773292dc34c1f8309cb73bbc15494c8569eef5
FranciscoChaconTTU/Quiz3
/Quiz3.py
4,819
4.03125
4
import math def dot(vector01,vector02): "This fuction takes in two vectors and first checks if they are lists. Then it checks if they are of the same dimensions. Then if they are of the same dimensions it multiplies the elements in the same positions and adds them at the end. If they are not of the same dimensions it...
965c77129eb1a90dd20e50fc5e2966c3d63b6971
AahilD/Python-Code
/Snake/Main Screen.py
453
3.640625
4
import tkinter as Tk from graphics import * x = 700 y = 500 def main(): #Creates Screen win = GraphWin("Test Window",x, y) win.setBackground(color_rgb(211, 211, 211)) #Creates Title header = Rectangle(Point(x-25, 25), Point(25, y/2)) header.setFill(color_rgb(100, 100, 100)) ...
0f55e4ee28720bc06ea6e99377368ca456e12866
gmholland/eece583-a1
/priorityq.py
2,590
3.953125
4
import heapq import itertools class PriorityQueue: """Priority queue implementation based on a heapq. Code borrowed from the Python heapq Library Reference which is available from: http://docs.python.org/release/3.2.3/library/heapq.html""" def __init__(self): """init method ...
c5ec95884f690e7d65a5bb4119e8e011b036e8eb
yyan4849/Acorn-Scaffold-v1.3
/run.py
654
3.609375
4
from game import Game import os import sys name = sys.argv[1] # filename no found if len(name) == 0: print("Usage: python3 run.py <filename> [play]") sys.exit() # create game object and set up the string map game = Game(name) game.return_grid() game.set_player() print(game.string()) # Play the game while T...
2525229f09037b8c54e4d7fef66f1436006951fe
kaust-cs249-2020/asaad
/Ch3/Ex2.py
645
3.640625
4
# 3.3 String Reconstruction as a Walk in the Overlap Graph def GenomePath(Path): ''' :param Path: A sequence path of k-mers ''' text = "" prev = "" k = len(Path[0]) for pattern in Path: if(not prev): prev = pattern text = text + pattern else: ...
f7bfaa44fdda792be147c2e2f64656dee75bc58a
harshithaswarup/python
/temperature_2pbm.py
1,689
4.0625
4
import datetime class Temperature: def get_date(self): for x in range(1): x=int(input("enter a year:")) y=int(input("enter a month:")) z=int(input("enter the day:")) date1=datetime.date(x,y,z) date=date1.strftime('%d/%m/%y') print date ...
5eb8e0b24c3f32f17ec1d13c07aee382aeef9a39
himajasricherukuri/python
/src/listfunctions.py
1,949
4.21875
4
lucky_numbers = [4,8,15,16,23,42] friends = ["kevin","karen","jim","oscar","toby"] friends.extend(lucky_numbers) print(friends) # extend function allows you take a list and append it on another list #append- adding individual elements lucky_numbers = [4,8,15,16,23,42] friends = ["kevin","karen","jim","oscar","toby"] f...
b33bd9fe0dffcc22d3f657b10d11d1aff016b5b1
yourpalfranc/tstp
/14challenge-2.py
671
4.21875
4
##Change the Square class so that when you print a square object, a message prints telling you the ##len of each of the four sides of the shape. For example, if you ceate a square with Square(29) ##and print it, Python should print 29 by 29 by 29 by 29. class Square(): square_list = [] def __init__(self, ...
47881bba6924f1b952465ea58f56155ba3fd986a
yourpalfranc/tstp
/6challenge-7.py
267
3.546875
4
#Slice the string "It was a bright cold day in April, and the clocks were striking thirteen." to only #include the characters before the comma. my_quote = """It was a bright cold day in April, and the clocks were striking thirteen.""" r = my_quote[0:33] print(r)
e11bbfad8542019e70e5d4fd21cac8dfe7054f40
yourpalfranc/tstp
/14challenge-3.py
492
3.859375
4
##Write a function that takes two objects as perameters and returns True if they are the same ##object and False if not ##class Dog(): ## pass ## ##class Cat(): ## pass ## ##a = Dog() ##b = Dog() ##c = Cat() ## ##def compare_animals(a1, b1): ## print(a1, " .vs ", b1) ## if a == b: ## return True ## ...
e0208f467d88bae3e99e57a710d34e17945a5a0b
yourpalfranc/tstp
/6challenge-4.py
204
3.984375
4
#Take the string "Where now? Who now? When now?" and call a method that returns a list that looks #like ["Where now?", "Who now?", "When now?"] r = "Where now? Who now? When now?".split("?") print(r)
dd9b59f1e1794c7fafe2f2d8eda2bf6dc4a449d8
yourpalfranc/tstp
/6challenge-5.py
167
4.09375
4
#Replace every instance of "s" in "A screaming comes across the sky." with a dollar sign. r = "A screaming comes across the sky." r = r.replace("s", "$") print(r)
e489a9c6d7e662cd125a74b2f014614bdc861a9f
yourpalfranc/tstp
/13challenge-2.py
937
4.1875
4
##Define a method in your Square class called change_size that allows you to pass in a number ##that increases or decreases (if the number is negative) each side of a Square object by that ##number. class Rectangle(): def __init__(self, width, length): self.width = width self.length = length ...
f01a2ca4bd4433c08579caf1de1316126b882c86
elena-geodata/Class-exercises-github
/Homework_VL4.py
859
3.796875
4
# Create a main script and 1 functions # The function: it should read a precipitation file (path provided as an argument), # extract the data and return only the precipitation data as a list or Numpyarray. # The script: it should call the function and display to the user: # The min precipitation # The max precipitation...
1c680ab5cd05f7593fec9e05d2242a5d3edc08e5
depadiernos/Computer-Architecture
/ls8/cpu.py
4,191
3.671875
4
"""CPU functionality.""" import sys class CPU: """Main CPU class.""" def __init__(self): """Construct a new CPU.""" self.ram = [0] * 256 self.reg = [0] * 8 self.pc = 0 self.sp = 7 self.running = True def ram_read(self, address): return self.ram[add...
c78b29df82ceeb9d852a528170b02d7faa171a5d
Pymeleon/TestAnnoying
/main.py
337
3.984375
4
import random word = input("What would you like to repeat? ") times = int(input("How many times would you like to repeat this? ")) secondary = input("What is your secondary message to repeat? ") i = 0 while i < times: i += 1 print(str(word) + " ", end = '') if random.randint(0,100) == 8: print(str(secondary)...
8998a671e75cd11d0063e4285f0b980411132128
ryanpennings/workshop_swinburne_2021
/examples/118_euler_angles.py
699
4
4
"""Example: Rotations from euler angles, rotate an object based on 3 euler angles. """ from compas.geometry import Rotation # euler angles alpha, beta, gamma = -0.156, -0.274, 0.785 static, axes = True, 'xyz' # Version 1: Create Rotation from angles R1 = Rotation.from_euler_angles([alpha, beta, gamma], static, axes) ...
54c672d04f5c64325426c3058de3c6979659e59e
Tariati/Beadando
/2.feladat.py
1,530
3.5
4
import numpy as np def determinansszamolo(matrix): if matrix.shape == (2, 2): return (matrix[0][0] * matrix[1][1]) - (matrix[0][1] * matrix[1][0]) determinans = 0 for i in range(matrix.shape[1]): kis_matrix = np.delete(np.delete(matrix, 0, 0), i, 1) determinans += (matrix[0]...
ff4e49be222c63ac058d42addfd9e540b67205c7
funnicus/Karmespeli
/game_modules/Obstacle.py
1,962
3.609375
4
""" Obstacle -luokka, jonka avulla piirrämme esteitä peliin. Luokka pitää huolen myös esteisiin liittyvistä laskutoimituksista. Attributes ========= width : int height : int stone : png bush : png corona : png x : int y : int location : coordinate obstacle : Rect ...
3c4aa7722f17646432a8e7dda16fdc96ce21a01d
stradtkt/TheNumberGuessingGame
/guessing_game.py
3,048
4.09375
4
""" Python Web Development Techdegree Project 1 - Number Guessing Game -------------------------------- For this first project we will be using Workspaces. NOTE: If you strongly prefer to work locally on your own computer, you can totally do that by clicking: File -> Download Workspace in the file menu after you for...
2707018788c4bef0ced12ecaf4fb6579cdab06f1
HaydenBourinot/Programming
/PythonOOP/Car.py
857
3.78125
4
class Wheel: def __init__(self, wtype, wspec = "winter"): self.wtype = wtype self.wspec = wspec def toString(self): return ("Wheel Type: {}, Wheel Spec: {}".format(self.wtype, self.wspec)) class Engine: def __init__(self, etype = 2.4): self.etype = etype ...
975e32bdd5ed010f02d56842969746701a3e78c0
20130353/Leetcode
/target_offer/大整数+经典算法/最大公约数.py
492
3.546875
4
# # 最大公约数: # 1. 更损相减法 # 2.辗转相除法 # 更损相减法 # def solution(a, b): # while a != b: # if a > b: # a = a - b # else: # b = b - a # return a # 辗转相除法 def solution(a, b): if a < b: a, b = b, a while b != 0: t = b a = a % b b = t i...
d653ad76c38dc70e783ba9f73e0a0d65a5269641
20130353/Leetcode
/target_offer/大整数+经典算法/最短前缀.py
1,753
3.78125
4
# -*- coding: utf-8 -*- # @File : 最短前缀.py # @Author : smx # @Date : 2019/10/14 # @Desc : # 格式问题没有解决! class Node: def __init__(self): self.data = {} self.is_word = False self.num = 0 # 找前缀树重点是要标记每个字符出现的次数! class Trie: def __init__(self): self.root = Node() def i...
24f423e65a354bbcd43277c047420e484008ed98
20130353/Leetcode
/target_offer/二分+双指针+滑动窗口/和为s的两个数字.py
1,252
3.671875
4
# -*- coding: utf-8 -*- # author: sunmengxin # time: 18-11-25 # file: 和为s的两个数字 # description: # 这个借用和为s的连续最大子数组最方便,时间复杂度比二分合适 class Solution: def binary_search(self, arr, target, left, right): if left > right: return False mid = (left + right) // 2 if arr[mid] == target: ...
576ff61f28fa7e4b40df4fe97034057d6b793bcd
20130353/Leetcode
/target_offer/数组/数字的情绪.py
852
3.671875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 数字的情绪.py # @Author: smx # @Date : 2019/8/15 # @Desc : # 这道题存在的问题是:没有找每一个case,验证每一个if条件 # 请检查是否存在语法错误或者数组越界非法访问等情况, 因为0不能被整除,所以就需要判断 def solution(num, str_num): flag_one = False flag_all = True for i, each in enumerate(str_num): if each == ...
4fdc2ffc18c98861aef67f5912208748a3e3e455
20130353/Leetcode
/target_offer/链表/链表之两数相加.py
2,074
3.921875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 链表之两数相加.py # @Author: smx # @Date : 2020/2/9 # @Desc : # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None # 问题是理解题意出错,直接按照链表顺序相加即可! class Solution: def reversedList(self, head): ...
9822359bd77ada1719ebc3f47ca569670be5f23a
20130353/Leetcode
/target_offer/位运算/其他出现两次找出现一次的数字.py
985
3.765625
4
# -*- coding: utf-8 -*- # author: sunmengxin # time: 18-11-16 # file: 只出现一次的数字 # description: # encoding=utf8 ''' 题目:一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。 要求时间复杂度是O(n),空间复杂度是O(1)。 ''' def find_two_unique_num(num_list): result = 0 for num in num_list: result ^= num lowbit = find_lowest_bi...
15bc8e41e998c3d8cd8434ef0c031d0a7c860af7
20130353/Leetcode
/target_offer/dfs+bfs+动态规划/字符串--区间动规/回文删掉一个字符变成回文串.py
1,897
3.609375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 回文删掉一个字符变成回文串.py # @Author: smx # @Date : 2019/8/13 # @Desc : # 思路:尝试删除每一个字符,判断删除之后的字符串是否是回文 # 判断是否是回文有两种方法:1. 双指针(时间复杂度N,可以判断整体是否是回文) 2. 动态规划(时间复杂度N^2,判断字符串的全部回文) # 删除字符就是找序列问题! class Solution: def judge_double(self, string): new_str = '#'.joi...
406b9c29da479bb10e60d228da5430243f9c5514
20130353/Leetcode
/target_offer/链表/反转链表.py
1,082
3.96875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 反转链表.py # @Author: smx # @Date : 2020/2/8 # @Desc : # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def reverseList(self, head): if not head or not head...
137a5220e06b3bccaa6eed99d15b7cb820d76a4a
20130353/Leetcode
/target_offer/字符串题/验证整数是否是回文数.py
594
3.765625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 验证整数是否是回文数.py # @Author: smx # @Date : 2020/2/8 # @Desc : class Solution: def isPalindrome(self, x): if x < 0: return False if x < 10: return True s = str(x) i, j = 0, len(s) - 1 while i < j: ...
743291ce5222d5ca9b2e11637e74829672fc1de1
20130353/Leetcode
/target_offer/二分+双指针+滑动窗口/二分查找大于target的最小位置.py
489
3.546875
4
# 找最大位置就用low守,找最小位置就用high守 def solution(arr, n, target): left, right = 0, n - 1 while left < right: mid = left + (right - left) // 2 if arr[mid] > target: right = mid else: left = mid + 1 if right < 0 or arr[right] <= target: return -1 return right...
22eee9d2d13b27286d5bbaf67068df7946c82f03
20130353/Leetcode
/target_offer/dfs+bfs+动态规划/DFS+BFS/解数独.py
1,661
3.515625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 解数独.py # @Author: smx # @Date : 2020/2/19 # @Desc : # 暴力搜肯定超时! class Solution: def DFS(self, board): print(board) for i in range(9): for j in range(9): if board[i][j] == '.': col = [board[c][j...
07026bdd5c3e85543e6de32e857f3260cec214b6
20130353/Leetcode
/target_offer/数组/数组拆分.py
411
3.625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 数组拆分.py # @Author: smx # @Date : 2020/2/22 # @Desc : class Solution: def arrayPairSum(self, nums): snums = sorted(nums) asum = 0 for i in range(len(snums)): if i % 2 == 0: asum += snums[i] return asum if __name...
14f3a974f746ca26e49bd23e1005def33009422c
20130353/Leetcode
/target_offer/栈+队列+堆/队列的最小修改.py
527
3.671875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 队列的最小修改.py # @Author: smx # @Date : 2019/8/17 # @Desc : # 这道题存在的问题是:没有想清楚答案的本质,多算了一种情况 def solution(arr, n): if n == 1: return 0 for i in range(n - 1, 0, -1): if arr[i] < arr[i - 1]: return i return 0 if __name__ ==...
53987a897dae31a315ca81b27ef514ec9b4cb8b3
20130353/Leetcode
/target_offer/二叉树/二叉树的镜像.py
2,436
3.546875
4
# -*- coding: utf-8 -*- # Author: sunmengxin # time: 10/14/18 # file: 二叉树的镜像.py # description: class Node: def __init__(self, data): self.data = data self.lchild = None self.rchild = None def mirroring(T): if T == None: return T.lchild = mirroring(T.lchild) T.rchild =...
068e46934298694fd0cca87f00489e0c01a2a699
20130353/Leetcode
/target_offer/dfs+bfs+动态规划/字符串--区间动规/回文字符串.py
430
3.8125
4
def solution(string): i = 0 leng = len(string) while i <= (leng // 2) and string[i] == string[leng - i - 1]: i += 1 if i > (leng // 2): return 'Yes!' else: return 'No!' if __name__ == '__main__': try: while True: string = input().strip() ...
8e87fd8cdabc9fa1226d2811d8da59d2eef5f053
20130353/Leetcode
/target_offer/栈+队列+堆/滑动窗口的最大值.py
1,085
3.6875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 滑动窗口的最大值.py # @Author: smx # @Date : 2020/2/14 # @Desc : # 给定一个数组 nums,有一个大小为k的滑动窗口从数组的最左侧移动到数组的最右侧。 # 你只可以看到在滑动窗口内的 k个数字。滑动窗口每次只向右移动一位。 # 返回滑动窗口中的最大值。 # 双端队列 # 本来应该是只淘汰小的,但是是找滑动窗口内的所以要淘汰失效的 class Solution: def maxSlidingWindow(self, arr, k): win =...
53865bc1c59646cd4b8eadf50c8896a1f2ef92e7
20130353/Leetcode
/target_offer/大整数+经典算法/前缀树.py
1,255
3.921875
4
class Trie: def __init__(self): self.data = {} self.is_word = False class prefixTree: def __init__(self): self.root = Trie() def insert(self, arr): # 最后没有字符的地方标记is_word node = self.root for inx, ch in enumerate(arr): next_node = node.data.get(ch...
546810740ca3788bf99df437e4ec43d78e027b14
20130353/Leetcode
/target_offer/栈+队列+堆/字符串的解压缩
1,447
3.796875
4
#!/usr/bin/python # -*- coding: UTF-8 -*- # 猿辅导面试题 # 1 字符串的压缩和解压缩 # 1. 压缩只能是最简答的不带括号的形式,如果是带括号的形式就存在找不到的找不到之前的压缩的情况 # 2. 解压缩,可以是带括号的情况。用栈保存,遇到字符和括号直接入栈,遇到数字判断栈顶是括号还是字符,如果是字符直接重复数字次,如果是括号就一直找到左括号重复数字次 # 确定数字的时候要向后判断是多少 def solution(string): if not string or len(string) <= 0: return '' i = 0 stack ...
1ebe09641805a4b372dca9450e7e8f7b99f613bb
20130353/Leetcode
/target_offer/链表/从尾到头输出链表.py
1,071
3.90625
4
# -*- coding: utf-8 -*- # author: sunmengxin # time: 18-11-15 # file: 从尾到头输出链表 # description: class Solution: # 返回从尾部到头部的列表值序列,例如[1,2,3] # def printListFromTailToHead(self, listNode): # # write code here # listNode = list(listNode) # if listNode: # return listNode[::-1] ...
b15bf61641fabb5513495ae51bde72729fa89e37
20130353/Leetcode
/target_offer/dfs+bfs+动态规划/DFS+BFS/子集.py
1,046
3.65625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 子集.py # @Author: smx # @Date : 2020/2/19 # @Desc : # 不用copy的方法是每次传递都是新的元素 # 为什么不用这方法? import copy as cp class Solution: def DFS(self, arrs, n, pos, cur, ans): if pos >= n: ans.append(cp.copy(cur)) return cur.append(...
886f952f178f366f20eef1e2e04053bb8e067873
20130353/Leetcode
/target_offer/栈+队列+堆/切金条.py
561
3.546875
4
#每一次切尽可能让两边小,贪心算法 import heapq class Solution: def __init__(self): self.heap = [] def split_gold(self, arr): if not arr: return 0 for each in arr: heapq.heappush(self.heap, each) res = 0 while len(self.heap) > 1: d1 = heapq.heappop...
de2a88a32836df5c550df87da6f26da004672577
20130353/Leetcode
/target_offer/栈+队列+堆/扁平化嵌套列表迭代器.py
801
3.625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 扁平化嵌套列表迭代器.py # @Author: smx # @Date : 2020/2/13 # @Desc : class NestedIterator(object): def __init__(self, nestedList): """ Initialize your data structure here. :type nestedList: List[NestedInteger] """ self.queue ...
c9354d34d0ef95cb4420923cbb868a0d8824dc89
20130353/Leetcode
/target_offer/公司套题/TX/TX_字符移位.py
578
3.75
4
if __name__ == '__main__': try: while True: string = input().strip() chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] new_string = '' new_string1 = ...
2de4ed94239fb49a2b6e1416835e8cefe23def22
20130353/Leetcode
/target_offer/dfs+bfs+动态规划/DFS+BFS/组合总和.py
820
3.625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : 组合.py # @Author: smx # @Date : 2020/2/19 # @Desc : # 完全背包 class Solution: # 被无限抓取使用! def DFS(self, arrs, n, target, cur, cur_sum, ans): if cur_sum == target: if sorted(cur) not in ans: ans.append(sorted(cur)) ...
ca5558fda1fe01bcda756c8fc89c0dbb093324d9
tggithub619/Codewars_Python
/8 kyu Gravity Flip.py
186
3.515625
4
#https://www.codewars.com/kata/5f70c883e10f9e0001c89673/solutions/python/me/best_practice def flip(d, a): return sorted(a, reverse=True) if d=='L' else sorted(a) # Do some magic
d8297406c3330f01a937398497ba2e3bbce30319
tggithub619/Codewars_Python
/7 kyu Regex validate PIN code.py
230
3.78125
4
#https://www.codewars.com/kata/55f8a9c06c018a0d6e000132/solutions/python def validate_pin(pin): return len(pin) in (4, 6) and pin.isdigit() def validate_pin(pin): return pin.isdigit() and (len(pin) == 4 or len(pin) == 6)
9c1e30fb3d9289a8ab3c01e564f5a7dedc524bae
tggithub619/Codewars_Python
/7 kyu Bingo ( Or Not ).py
586
3.59375
4
#https://www.codewars.com/kata/5a1ee4dfffe75f0fcb000145/solutions/python/me/best_practice def bingo(array): bingo = [2,7,9,14,15] return 'WIN' if len([el for el in bingo if el in array])==5 else'LOSE' def bingo(array): return "WIN" if {2, 7, 9, 14, 15}.issubset(set(array)) else "LOSE" def bingo(array): ...
9a3efa1a3c9c7c668f213fb32ce5ab13d36fe09a
tggithub619/Codewars_Python
/7 kyu Drone Fly-By.py
437
3.609375
4
#https://www.codewars.com/kata/58356a94f8358058f30004b5/train/python def fly_by(lamps, drone): return 'o' * len(lamps) if len(lamps) <= len(drone) else 'o' * len(drone) + 'x' * (len(lamps) - len(drone)) def fly_by(lamps, drone): return lamps.replace('x', 'o', drone.count('=') + 1) def fly_by(lamps, drone): ...
4b24c0c238f6a6e67facd9946dc21255ce8e73a2
tggithub619/Codewars_Python
/8 kyu Can we divide it.py
165
3.546875
4
#https://www.codewars.com/kata/5a2b703dc5e2845c0900005a/train/python def is_divide_by(n, a, b): if n % a == 0 and n % b == 0: return True else: return False
fe8a5e1a51530e1b0129d13afae73405b15981f8
tggithub619/Codewars_Python
/8 kyu Grasshopper - Debug.py
326
3.921875
4
#https://www.codewars.com/kata/55cb854deb36f11f130000e1/train/python def weather_info(temp): c = convert_to_celsius(temp) if (c <= 0): return f"{c} is freezing temperature" else: return f"{c} is above freezing temperature" def convert_to_celsius(temp): c = (temp - 32) * (5 / 9) re...
06b75c031540802ba06100844a27802acbddc342
tggithub619/Codewars_Python
/8 kyu Super Duper Easy.py
308
3.53125
4
#https://www.codewars.com/kata/55a5bfaa756cfede78000026/train/python def problem(a): if isinstance(a, str): return "Error" else: return a * 50 + 6 def problem(a): return 'Error' if type(a) is str else a * 50 + 6 def problem(a): return 'Error' if type(a) == str else a*50+6
1113963fe504f4c06310cd094bef2ba605b20965
tggithub619/Codewars_Python
/7 kyu Squares sequence.py
239
3.53125
4
#https://www.codewars.com/kata/5546180ca783b6d2d5000062/train/python def squares(x, n): arr = [] for i in range(n): arr.append(x) x = x*x return arr def squares(x, n): return [x**2**(i) for i in range(n)]
254dc9ed169b487b680dc64822a9b9ae3d639551
tggithub619/Codewars_Python
/5 kyu Simple Pig Latin.py
556
3.578125
4
#https://www.codewars.com/kata/520b9d2ad5c005041100000f def pig_it(text): text=text.split(' ') s = [] for i,el in enumerate(text): if el.isalpha(): rest = el[1:] + el[0]+ 'ay' s.append(rest) else: s.append(el) return ' '.join(s) def pig_it(text): ...
c7576840216aacfd9747ee9b3f87cc4437c92c19
tggithub619/Codewars_Python
/6 kyu Build Tower.py
242
3.6875
4
#https://www.codewars.com/kata/576757b1df89ecf5bd00073b/solutions/python/me/best_practice def tower_builder(n): lst = [] length = n * 2 - 1 for i in range(1, n * 2, 2): lst.append((i * "*").center(length)) return lst
a2a1c82c949679df069000f1a984afd38f3474d3
tggithub619/Codewars_Python
/7 kyu The Baby Years I - Baby Counting.py
894
3.921875
4
#https://www.codewars.com/kata/5bc9951026f1cdc77400011c def baby_count(x): x = x.lower() b = x.count("b") // 2 a = x.count("a") y = x.count("y") return min(b, a, y) if min(b, a, y) > 0 else 'Where\'s the baby?!' # Test.assert_equals(baby_count('baby'), 1) # Test.assert_equals(baby_count('abby'), ...
d3c7efe5546dc38a37ebd19234033c6643e38e68
tggithub619/Codewars_Python
/8 kyu Sum The Strings.py
226
3.640625
4
#https://www.codewars.com/kata/5966e33c4e686b508700002d/train/python def sum_str(a, b): a = int(a) if a else 0 b = int(b) if b else 0 return str(a + b) def sum_str(a, b): return str(int(a or 0) + int(b or 0))
3701469a85a257908088702fc1d6a9705e78a41a
tggithub619/Codewars_Python
/7 kyu Right in the Centre.py
462
3.875
4
#https://www.codewars.com/kata/5f5da7a415fbdc0001ae3c69/train/python def is_in_middle(seq): while len(seq) >= 3: if seq == 'abc' or seq[1:] == 'abc' or seq[:-1] == 'abc': return True seq = seq[1:-1] return False def is_in_middle(seq): while len(seq) > 4: seq = seq[1:-1]...
add744a4b13e34842d101bff946f238d5ff7a04d
tggithub619/Codewars_Python
/7 kyu Put a Letter in a Column.py
352
3.765625
4
#https://www.codewars.com/kata/563d54a7329a7af8f4000059 def build_row_text(ind, ch): s = ['| ']*9 #print(ind, ch, s) s[ind] = '|'+ ch return "".join(s)+'|' def build_row_text(index, character): str = "" for i in range(9): if i == index: str += "|" + character else: ...
f6eedf664ab323e63b01671ae6add8fcb63ac61d
shilad/cartograph-alg
/cartograph/border_graph/Edge.py
326
3.515625
4
class Edge: """ An edge which records two centers and two adjacent corners """ def __init__(self, id, center1, center2, vertex1, vertex2, is_border): self.id = id self.d0 = center1 self.d1 = center2 self.v0 = vertex1 self.v1 = vertex2 self.is_border = is_b...
e992bcbf5affe3d1168f5de2171ddce232684709
dm303102/RetroPie-Shutdown-script
/shutdown_pi.py
2,254
3.546875
4
#!/bin/python # Simple script for shutting down the raspberry Pi at the press of a button. # by Inderpreet Singh import RPi.GPIO as GPIO import os #import webiopi import time import subprocess import datetime from datetime import datetime # Setup the Pin with Internal pullups enabled and PIN in reading...
9c103ad9a956d3bf5ece4a0598c5ebce23e0fedb
Athira-Vijayan/Python
/command_line_arguments/arg.py
197
4.0625
4
#python program to find sum of even numbers using command line arguments import sys args=sys.argv[1:] print(args) sum=0 for a in args: x=int(a) if(x%2==0): sum+=x print('sum=',sum)
99ac4bbad4558ee90b770559b63f7826f287009f
kurbielp/wpk
/p_1_2.py
219
3.546875
4
n = 11 for i in range(0,n): for j in range(0, n): if (j % 2 == 0 and i % 2 ==0) or (j % 2 == 1 and i % 2 ==1): print ('X ', end='') else: print('O ', end='') print('')
1cdbf36cf05b93addd8e5797b82747e5448462f8
druv022/Disease-Normalization-with-Graph-Embeddings
/nerds/util/file.py
1,216
4.21875
4
import shutil from pathlib import Path def mkdir(directory, parents=True): """ Makes a directory after checking whether it already exists. Parameters: directory (str | Path): The name of the directory to be created. parents (boolean): If True, then parent directories are created a...
4f832ab20876d18f87442d16764c9464766a79d8
druv022/Disease-Normalization-with-Graph-Embeddings
/nerds/doc/annotation.py
8,564
3.734375
4
from uuid import uuid4 class Annotation(object): """ A named entity object that has been annotated on a document. Note: The attributes of this class assume a plain text representation of the document, after normalization. For example, `text` will be in lower case, if t...
e5b94f0ba5cadbd496e8bf15318db7ae8f4d31cf
Abhiram-Agina/PythonProjects_Algebra
/CHAPTER10_ExponentsProperties.py
1,776
4.25
4
# Type in an Expression that includes exponents and I will give you an Answer # Negative Exponents: Work in progress SEEquations = input(" Type in a simple expression using exponents, 1 operator, and the same constant (i.e. 3^2 * 3^6) \n ") terms2 = SEEquations.split(" ") ExponentTerms = [] for item in terms2: if...
401c013d540c2a2aaa074a487317d47d97d9b43f
Abhiram-Agina/PythonProjects_Algebra
/CHAPTER5_ConvertStandardToSlope.py
1,124
4
4
# Converts equation from standard to slope intercept form Yequation1 = input("enter the equation in Standard Form, space after each term ( 3x + 4y + 7 = 0 ):\n ") print(Yequation1) terms = Yequation1.split(" ") print(terms) XvarTerms = [] for item in terms: if 'x' in item: XvarTerms.append(item) ...
ae67a75d2e66a5961e20969304f8afade4b5861c
Pheric/Hangman
/Main.py
5,831
4
4
import curses, operator, os # https://docs.python.org/3/howto/curses.html # https://docs.python.org/3/library/curses.html # https://www.ibm.com/developerworks/library/l-python6/ VERSION = 0.4 ALPHABET = "abcdefghijklmnopqrstuvwxyz" players = {} # chr: bool (AVAILABLE) alphabet = {} word = "" progress = 0 penalties =...
ceb34a2e94f0e494c4e15a4986af1c555d8a765a
andrelgp/thcode-ProjSSTMap
/astronomical_methods.py
2,412
3.796875
4
#################################################################### # # A set of astronomical routines. A work in progress... # # Author: Guigue # # Change Record: # - Adapted from the original sst_methods.py # - First routine julian_date - 2017-06-15 # ####################################################...
2ad0bd46b1b52b80975fbfd0023ba86b318cb2b2
carlos-moreno/algorithms
/print_borders.py
533
4.09375
4
""" Given a number n, produce the output with the following pattern. number 5 1 11 1 1 1 1 11111 >>> print_(5) 1 11 1 1 1 1 11111 >>> print_(10) 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1111111111 """ def build_print(number, n): if n < 3 or n == number: s = f'{"1" * n}' else: ...
1e3f2316b049c5fff4bfab0189bb2a492997ed1c
carlos-moreno/algorithms
/hypotenuse.py
512
4
4
def is_hypotenuse(number: int) -> bool: result = False if number < 1: return result for i in range(1, number + 1): for j in range(1, number + 1): if pow(number, 2) == pow(i, 2) + pow(j, 2): result = True break return result def soma_hipotenus...
19bf5d5b4543a4bd66014a795203bc5a1780597e
algometrix/opencv_3_face_detection
/extract_faces.py
9,122
4.375
4
""" This is an example of using the k-nearest-neighbors(knn) algorithm for face recognition. When should I use this example? This example is useful when you whish to recognize a large set of known people, and make a prediction for an unkown person in a feasible computation time. Algorithm Description: The knn classif...
54b4f050c14f09d90fd9f5275f5e7f4a4b6a5600
PriklyGrayp/Noitacude.PY
/Python - Fundamentals/Predicates.py
477
3.8125
4
__author__ = "Prikly Grayp" __license__ = "MIT" __version__ = "1.0.0" __email__ = "priklygrayp@gmail.com" __status__ = "Development" from math import sqrt from pprint import pprint as pp def is_prime(x): if x < 2: return False for i in range(2, int(sqrt(x)) + 1): if x % i == 0: ret...
c62af5d572fb9f5f3c9a5ad7a17b3a84913ed881
Jakub435/LabyPython
/l3/zad1.py
1,899
4.03125
4
class Grade: def __init__(self, grade, weight): self.grade = grade self.weight = weight class Student: grading = [] def __init__(self, firstname, lastname): self.firstName = firstname self.lastName = lastname def addgrade(self, grade, weight): self.grading.ap...
9fbf604768140b0492442807d028f1c7673d54db
jansenhillis/Python
/A001-Python-HelloWorld/hello_world.py
514
4.34375
4
#1. Hello World print("Hello World") #2. Hello Your Name name = "Jansen" print("Hello " + name) print("Hello", name) #3. Hello Num # Convert num to a string so concatenation will work num = "111" print("Hello " + num) print("Hello", num) #4. I love food food1 = "Chinese" food2 = "Sushi" print("I love to eat {} and ...
9e25339de670199da3cab9de8a98cc88c58cb5ca
jansenhillis/Python
/A004-python-functionsBasic2/functionsBasic2.py
2,414
4.40625
4
# 1. Countdown - Create a function that accepts a number as an input. Return a new list that counts down by one, # from the number (as the 0th element) down to 0 (as the last element). # Example: countdown(5) should return [5,4,3,2,1,0] def countdown(seed): seedList = [] for i in range(seed, -1, -1): s...
89dff0084b30181854cec84587a71d328e23df24
mafdele20/TD_ALGO
/python/exo4.py
778
4
4
import math def puissnace(): #version 1 x= -1 while x <= 0 : x = int(input(" entrer un nombre \n")) if(x <= 0 ): print("le nombre saisi doit etre négqtif") else: n =int (input("entre la puissance\n ")) print(str(x)+" a la puissance "+str(n)+" est...
aa2b452ad6dc250ff6af924bacd87a7d864a541f
mafdele20/TD_ALGO
/python/exo6.py
567
4.125
4
from math import sqrt def distance(): x1=int(input(" entrer la premiere coordonnée du point A\n")) y1=int(input(" entrer la deuxieme coordonnée du point A\n")) x2=int(input(" entrer la premiere coordonnée du point B\n")) y2=int(input(" entrer la deuxieme coordonnée du point B\n")) ...
28c32c2e42d6207a40b2eb7116d7015aa2e935ef
DragonBanana/rec_sys_challenge_2020
/Utils/Data/Dictionary/Dictionary.py
595
3.578125
4
from abc import abstractmethod from abc import ABC import RootPath class Dictionary(ABC): ROOT_PATH = RootPath.get_root().joinpath("Dataset/Dictionary/") def __init__(self, dictionary_name: str): self.dictionary_name = dictionary_name @abstractmethod def has_dictionary(self): pass ...
1bae8f4568b6abcda17ce0c7dd092f70963f2b7b
DragonBanana/rec_sys_challenge_2020
/Utils/Eval/ConfMatrix.py
1,338
3.5
4
from sklearn.metrics import confusion_matrix import numpy as np #-------------------------------------------------- # ABOUT CONFUSION MATRIX #-------------------------------------------------- # gt: Ground truth of predictions. # pred: Predicted values. # labels: Labels to index...
6e6564114e106061d92d67a1f6810d08d5e84807
michelle-sepulveda-lavin/todo-list-python
/app.py
2,096
3.765625
4
import csv todos = [] stop = False def get_todos(): global todos return todos def add_one_task(title): # your code here todos.append(title) def print_list(): if len(todos) > 0: for x in range(0, len(todos)): print(str(x + 1) + ". " + todos[x]) else: print("Empty l...
2e129574ad41492e099ab2181717ed8aeb79fb1f
simoonsaiyed/CS303
/Payroll.py
1,620
4.15625
4
# Assignment 3: Payroll.py # A program that prints out the Payroll dependent on inputs. def calculate(worked, pay, fedtax, statetax): worked = float(worked) gross = worked * pay fedwitholding = fedtax * gross statewitholding = statetax * gross total = statewitholding + fedwitholding return worke...
e893b2aea4f7a3d99c750cecfff16bd73a0bfca7
jackwalker64/reflect
/prep/exec/callee.py
238
3.5
4
print("Enter callee") print("x? = {}".format("x" in globals())) x = 21 def main(): print("Main of callee") print("x? = {}".format("x" in globals())) globals()["x"] = 42 if __name__ == "__main__": main() print("Exit callee")
942d7b547cceb5139d24ae87dbd58e532eb71045
Matheusrsm/Graduacao-CC
/Programação 1/Atividades-LP1/Unidade 4/samu/samu.py
384
3.703125
4
# coding: utf-8 # Aluno: Matheus Silva Medeiros # Matrícula: 117110412 # Atendimentos no SAMU lista = [] soma = 0 for mes in range(12): valor_mes = int(input()) soma += valor_mes lista.append(valor_mes) print 'Média mensal de atendimentos: %.2f' % (soma / 12.0) print '----' for x in range(len(lista)): ...
5a42f14af6e57411dd97612302b9ddbe62f45850
Matheusrsm/Graduacao-CC
/Programação 1/Atividades-LP1/Diversas Unidades/area/area.py
231
3.625
4
# coding: utf-8 # Área e perímetro de um Círculo import math diametro == int(raw_input()) raio = diametro/2 area = (math.pi*raio**2) perimetro = (2*math.pi*raio) print "A: ", ("%.5f" % area) print "P: ", ("%.5f" % perimetro)
695ac36d59ae5ada720acd7e3760aec6580cf218
Matheusrsm/Graduacao-CC
/Sistemas Operacionais/Laboratórios - ProjSO/lab-reposicaopaginas/algorithms/aging.py
1,288
3.6875
4
# This is the file where you must implement the Aging algorithm # This file will be imported from the main code. The PhysicalMemory class # will be instantiated with the algorithm received from the input. You may edit # this file as you whish # NOTE: there may be methods you don't need to modify, you must decid...
b6db67918294181d84df03dda2520c3eb5de0832
Anova07/Competitive-programing
/HackerRank/the_time_in_words.py
1,695
4.0625
4
#!/bin/python3 # https://www.hackerrank.com/challenges/the-time-in-words/problem import math import os import random import re import sys # # Complete the 'timeInWords' function below. # # The function is expected to return a STRING. # The function accepts following parameters: # 1. INTEGER h # 2. INTEGER m # def ...
f7454c667d4ce9fb6960a565cd41aa571e208a45
Ajsolanki/Data-Mining
/kmeans_cluster.py
2,603
3.828125
4
import random thres_dis = int(input("Enter the Minimum Threshold distance : ")) cluster_number = int(input("Enter the Number of clustere required : ")) pt_in_cluster = int(input("Enter the Number of Points in a cluster : ")) def generate_random_points(qty, rangeX=100, rangeY=100): i = 0 randpoints = [] ...
b882e5374cb8a356d0e148e674e82fb84ed249b9
christopherjereza/concatenated-words-challenge
/WordsChallengeSolution.py
3,233
4.1875
4
import collections import time """ Finds the longest, second-longest, and total number of words from a text file made up entirely of other words in the file concatenated together. """ def main(): """ MAIN function that opens and reads the file, splits its contents into WORDS, then prints the solution found...
5bed653c66f3e454b9beb6070aa0b7a61c463cfd
hdeters/random-art
/random_art.py
2,827
3.875
4
import random import math # Your job is to create better version of create_expression and # run_expression to create random art. # Your expression should have a __str__() function defined for it. class Gen_expression: def __init__(self): self.func_list = self.generate_list() def generate_list(self): ...
976236b90dc8463b8a83f040ea2d91d8bac8787c
srac1777/learnPython
/CtCI-Python/Arrays and Strings/1p4.py
1,223
3.609375
4
def construct_hash(str): hsh = {} for ch in str: if ch != ' ': if ch in hsh: hsh[ch] += 1 else: hsh[ch] = 1 return hsh def truelen(str): count = 0 for ch in str: if ch != ' ': count +=1 return count def palin...
b23475cb0bf8a1d2808d66906e70a95d95ae9573
srac1777/learnPython
/Data Structures Implementations/node.py
495
3.640625
4
class Node: def __init__(self, data, next_node=None): self.data = data self.next = next_node def get_val(self): return self.data def set_val(self, val): self.data = val return self.data def get_next(self): return self.next def set_next(self, node): self.next = node ...