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
be7153ddb5a48d67fdc16b5b4999fba05849e72f
dimamik/AGH_Algorithms_and_data_structures
/Bit_Algo/04_21_Sortowania do Kolosa/Zad_6.py
378
3.59375
4
def zad6(tab,l=0,r=-1): """ binary search """ if r == -1: r = len(tab) if l >= r: return -1 """ zamiast -1 return l or r """ mid = (l+r)//2 if tab[mid] == mid: return 1 elif tab[mid] > mid: return zad6(tab, l, mid) elif tab[mid] < mid: ...
e67e1570746f3d4d06674d560da8167e36e8ce76
dimamik/AGH_Algorithms_and_data_structures
/Graphs_new/DFS/Euler_Cycle.py
8,012
4.15625
4
class graph: def __init__(self, repr,is_Matrix,is_weighted=False ): """ A graph class to represent graph using known structures\n is_Matrix==True: We have A Matrix n*n with a M[i][j] - weight of edge from i to j, or 0 in case of no vertex For Example...
e2d9a143360d1ac3d6d4827b7fd5500b86fed49b
dimamik/AGH_Algorithms_and_data_structures
/Sorting arrays/n/Counting_Sort_For_Alphabet.py
1,436
3.609375
4
""" Od konca porownujemy tylko jesli istniejz istniejącymi literami """ def CountingSort(tab, pozition): """ Counting sort for string via alphabetic liters and same lenghth all """ tab_of_liters = [0]*(32) for i in range(len(tab)): index = ord(tab[i][pozition])-97 tab_of_li...
e364017a16deba054ba269d1222f99b178df5258
dimamik/AGH_Algorithms_and_data_structures
/Trees/BST_average.py
1,665
3.859375
4
""" Left Node<=root<Right Node Without parrent """ class Node: """ Should predefine value """ def __init__(self, val): self.left = None self.right = None self.val = val self.parent=None def PrintBST(root): """ Function to print BST tree as a sorted array ...
8576c1302fc165f5ed519958c0fc8de892c2689d
dimamik/AGH_Algorithms_and_data_structures
/Linked_lists/Quick_sort.py
1,157
3.75
4
from lists_lib import * def ConcatenateLinkedLists(arrayOfLinkedLists): """ Bit Algo Function """ result = LinkedList() foundBegining = False for i in arrayOfLinkedLists: if not i.isEmpty(): i.last.next = None for i in arrayOfLinkedLists: if not foundBegining a...
b147a0551b284c8e3abaa1b5e14e9a152da87cea
dimamik/AGH_Algorithms_and_data_structures
/Sorting arrays/nlogn/Merge_sort_garek_not_working.py
839
3.859375
4
""" NOT WORKING """ def merge(tab,p,sr,k): # Uwaga, sr is included in left_tab i=p j=sr+1 tab_to_ret = [0] * (k-p+1) curr_index=0 while i<=sr and j<=k: if tab[i]<=tab[j]: tab_to_ret[curr_index] = tab[i] curr_index+=1 i+=1 else: ...
2d2440fdde70f131d93a0ae888ee462e09e04bba
dimamik/AGH_Algorithms_and_data_structures
/PRACTISE/CWICZENIA/03_26_Dynamic/tmp.knapsack.py
883
3.53125
4
def KnapSack(weight,val,MaxWeight): tab=[None]*len(val) for i in range(len(val)): tab[i]=[0]*(MaxWeight+1) for i in range(weight[0],MaxWeight+1): tab[0][i]=val[0] for i in range(1,len(val)): for j in range(1,MaxWeight+1): tab[i][j]=tab[i-1][j] if j>=weigh...
3262a39d3e37578f908531700a48532ea0497290
dimamik/AGH_Algorithms_and_data_structures
/Bit_Algo/04_21_Sortowania do Kolosa/Zad_5.py
1,600
3.546875
4
def BiSearch(tab, el_searching, start=0, end=-1): if end == -1: end = len(tab) if start >= end: return -1 mid = (start+end)//2 if tab[mid] == el_searching: return mid if mid==0: return -1 elif tab[mid]==None or tab[mid] > el_searching: return BiSearch(tab,...
d804c0c1967ccb424ec1f7ab7a38659b41b89f2a
dimamik/AGH_Algorithms_and_data_structures
/PRACTISE/Dynamic_Programming/ALL/Fibbonachi.py
174
3.734375
4
def Fibb(n): last=1 prev=1 print(last,prev) for _ in range(n-2): print(last+prev) tmp=last+prev last=prev prev=tmp Fibb(10)
4d20a237a1b8b806e5eea64c7c635dff54b4e8c2
dimamik/AGH_Algorithms_and_data_structures
/PRACTISE/FOR EXAM/Wyklady/W2_QUEUE_STACK.py
2,898
4.15625
4
class Node(): def __init__(self,val=None,next=None): self.val=val self.next=next class stack_lists(): def __init__(self,size=0): first=Node() self.first=first self.size=size def pop(self): if self.size==0:return self.size-=1 tmp=self.first.nex...
1d3f0c5690bae08e0a2f6dd1c749e5d63df62275
StanislavMakhrov/OneLayerPerceptron
/pure_python/vector_.py
308
3.5625
4
import numpy as np class Vector: def __init__(self, x, d): if len(x.shape) > 2: self.__x = list(np.asarray(x).reshape(-2)) else: self.__x = list(x) self.__d = d def get_x(self): return self.__x def get_d(self): return self.__d
4e9b9da28608efcd69df0f7706a82d16461dd7d2
JulieBoberg/Learn-Python-3-the-Hard-Way
/ex8.py
931
4.3125
4
# declare variable formatter and set it equal to a string with four sets of brackets. formatter = "{} {} {} {}" # prints the string in the variable formatter with the arguments in format in place of the brackets print(formatter.format(1, 2, 3, 4)) # prints the string in the variable formatter with the arguments in ...
5d32181fdadd2ab1ca9b672617a612e03216259e
JulieBoberg/Learn-Python-3-the-Hard-Way
/ex20.py
1,617
4.1875
4
from sys import argv script, input_file = argv # define function print_all that accepts parameter f(a file) def print_all(f): # read the file(f) and print it print(f.read()) # define function rewind which accepts parameter f def rewind(f): # find the (0) start of the file(f) f.seek(0) # de...
6dec848d558c2dc4dc7ef4b5586e2c8515a38b39
NielXu/AI-algo
/tictactoe/game.py
2,821
3.9375
4
""" Classic tic tac toe game, does not handle any kinds of errors. """ from copy import deepcopy import minimax ENABLE_AI = True def init_board(): "Initializing a board and return it as a nested list" return [["-" for x in range(3)] for x in range(3)] def make_move(board, x, y, p): "Make move, set O i...
e4aa13754705fac578028197968c19b7ec7d21ef
wjwaters/problem-Euler
/PE12/PE#12_triangle_num.py
743
3.765625
4
# -*- coding: utf-8 -*- """ Created on Fri Jun 2 13:03:51 2017 @author: Jon """ "Special triangle numbers" n=int(input("Find the first triangle number with n factors? n= ")) tri_num=0 #Generic large number in range, break stops when condition is met so not important. Could use while loop instead, it wo...
57cbe9b4846215dba5b4c8649f22fb282790eaad
guerra28/Proyectos_python
/triqui.py
923
3.9375
4
import numpy as np def displayInicialTriqui(): for i in range(0,3): for j in range(0,3): print("|_",end="") print("|") def displayTriqui(x,y,turno): for i in range(0,3): for j in range(0,3): if x==i and y==j and turno: print("|X", end="") ...
97e2e4f4914f8666b812f17e2fc5f868e0b165e6
bernieyangmh/little-case-of-python
/SortMethods/select.py
563
3.734375
4
""" 选择排序 思想: 共重复元素的数量-1次 每次挑选最小的数放在对应的索引上,然后考虑之后的元素 例如对于[3,5,2,1,0,8] 挑选0放在第一个,然后挑选1放在第二个,2放在第三个...... repeat (numOfElements - 1) times set the first unsorted element as the minimum for each of the unsorted elements if element < currentMinimum set element as new minimum swap minimum with first un...
19950b75c3e05c325dfcdcdf43fc8639517fb604
bernieyangmh/little-case-of-python
/CaesarCipher.py
3,670
4.53125
5
# -*- coding: utf-8 -*- """ """ Insertion_Sort_instruction = """ We start with the first element in the array. One element by itself is already sorted. Then we consider the next element in the array. If it is smaller than the first, we swap them. Next we consider the third element in the array. We swap it leftwar...
f6618468e5577cd8df9a79e7c1615d3cbd2a694e
bernieyangmh/little-case-of-python
/SortMethods/radix.py
491
3.515625
4
""" 桶/基数排序 思想: 待排数组成员在有限区间内 构建在区间一次排序的空桶 将每个成员放在对应的桶内 去掉空桶,已排序 for each digit placing for each element in list move element into respective bucket for each bucket, starting from smallest digit while bucket is non-empty restore element to list 平均时间O(d(r+n)) 最短时间O(d(rd+n)) 最长时间O(d(r+n)) 空间O(rd+...
68816c45d32df6a9ba31999f462d81cc1a3b9782
NorthcoteHS/10MCOD-Daniel-MANDY
/user/Hello world.py
353
4.0625
4
''' Program: Hello world.py Name: Daniel Mandy Date: 28/2/2018 desc: says hello your name and then my name. PLEASE NOTE: The date is wrong because i only added this doc string when i learnt how to. ''' #asks user for their name aa = input('Whats your name? ') #prints users name and other print...
795ba841a724b31cc3f2963b9bd15b9a4f5346fd
natalialovkis/MyFirstPythonProject_Math
/math_project1.py
2,321
4.3125
4
# -*- coding: utf-8 -*- # Math learning program import random import math import turtle print("Hello Dear User!") name = input("Please, enter your name: ") print() print("Hello %s! Let`s learn the Math!" % name) print() num_of_ex = 0 while True: try: num_of_ex = int(input("How many exercises are you goi...
5a3a2da5f8e25a0dbb3b2c1bdbd1fee7c7efac21
metatab-packages/cde.ca.gov
/cde.ca.gov-reimbursements/pylib/__init__.py
1,545
3.8125
4
""" Example pylib functions""" def currency_float(v, row, row_n, i_s, i_d, header_s, header_d,scratch, errors, accumulator): """ An example column transform. This is an example of a column transform with all of the arguments listed. An real transform can omit any ( or all ) of these, and can supply them...
30f7e7671a9c003688c80f6433f5a95b266a5a4a
2mohammad/Python_Prac
/11_flip_case/flip_case.py
791
4.28125
4
def flip_case(phrase, to_swap): """Flip [to_swap] case each time it appears in phrase. >>> flip_case('Aaaahhh', 'a') 'aAAAhhh' >>> flip_case('Aaaahhh', 'A') 'aAAAhhh' >>> flip_case('Aaaahhh', 'h') 'AaaaHHH' """ """ split string to list via list c...
2b9bebf80b385ff85f7bce499c685d002e188035
thejqs/empty_scraper
/scraper.py
808
3.515625
4
#!usr/bin/env python import urllib import urllib2 from lxml import etree import StringIO import re def open_url(url): ''' checks the url to make sure it's valid and, if so, reads in the html ''' click = urllib.urlopen(url) if click.getcode() == 200: html = click.read() return ...
bb36efd1df3edf317fb9a8ba21309202e4582e33
TrilochanSati/exp
/daysInDob.py
832
4.3125
4
#Program to return days from birth of date. from datetime import date def daysInMonth(month:int,year:int)->int: months=[31,28,31,30,31,30,31,31,30,31,30,31] if(year%4==0 and month==2): return 29 else: month-=1 return months[month] def daysInDob(dobDay,dobMonth,dobYear)->int: ...
3037756c5750eb9dfa54156926ff08f6acbfb15c
iKingsly/iKYLeetCode
/Other/151. Reverse Words in a String1.py
231
3.640625
4
#!/usr/bin/python class Solution(object): def reverseWords(self, s): s = s.strip().split() if not s: return "" a = s[0] for i in range(1,len(s)): a = s[i] + ' ' + a return a a = Solution().reverseWords(" ") print(a)
6b4e96bf623fc9e617e90e6f0f9b02b2a91240a4
CMiro13/cs110finalproject
/finaltime.py
193
3.9375
4
import time def main(): seconds = 0 runtime = True while runtime == True: print(seconds) # Sleep for a second time.sleep(1) # Increment the seconds total seconds += 1 main()
01743e708236f93042dfbd9c7416cb301b75e7e7
wookoo/Bawekjoon-Online-Judge
/2000번대/2400~2499/2441.py
81
3.5
4
a = input() a = int(a) for i in range(a,0,-1): print(str(" "*(a-i))+str("*"*i))
0df6bf9496679d8f79600ad1701ca2ed0e90272f
wookoo/Bawekjoon-Online-Judge
/10000번대/10800~10899/10845.py
1,123
3.671875
4
class queue(): last = 0 array = [None]*10000 index = -1 def push(self,n): self.array[self.last] = n self.last += 1 def getSize(self): return (self.last - (self.index+1) ) def empty(self): if(self.last == self.index+1): return 1 ...
70ea98a11277f6952f820a964970988a9cfff0aa
VictCM/X-Serv-Python-Multiplica
/Ej13-3.py
204
3.859375
4
#!/usr/bin/python3 #Tabla Multiplicar Numbers = list(range(1,11)) for number1 in Numbers: for number2 in Numbers: mult = number1 * number2 print(number1, "por", number2, "=", mult)
1b15d92fbd5d19b138b1f7e84f3654b607fff090
tatumakseli/suomi
/suomi.py
3,306
3.78125
4
class Translate: def __init__(self, number): Translate.convert(self) self.string = str(number) self.decimals = False if "." in self.string or "," in self.string: self.decimals = True if "." in self.string: self.whole_int, self.dec_int = int(self.string.split(".")) elif "," in self.string: self...
a79fb9735b175390ed58b44e3be64ef4f529dcad
damiano96/PythonCourseStudy
/lession_10/z10_8.py
1,858
3.734375
4
import unittest import random as rnd class RandomQueue: def __init__(self, size=10): self.n = size + 1 # faktyczny rozmiar tablicy self.items = self.n * [None] self.head = 0 # pierwszy do pobrania self.tail = 0 def insert(self, item): if self.is_full(): ...
5176f7b68c0ee9dbe8c2d156cfed9f889b018b4c
damiano96/PythonCourseStudy
/lession_3/z_3-4.py
264
3.875
4
# rozwiazanie zadania z LEKCJI 3 # zadanie 3.4 # DAMIAN PORADYLO while True: x = input() if x == "stop": break if x.isnumeric(): x = int(x) print(x, x ** 3) else: print("ERROR! Only numbers.") continue
8efa22b333947e06b21f4e5d567ffae8b3992516
damiano96/PythonCourseStudy
/lession_4/z_4-4.py
163
3.796875
4
def fibonacci(n): result = [0, 1] for i in range(0, n): result.append(result[i] + result[i+1]) return result[n] print(fibonacci(15))
b10230d0c45681dbd4a2f4bb8ff7e9e75e2f1823
lmb633/leetcode
/102levelOrder.py
764
3.75
4
import queue class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def levelOrder(self, root): if root is None: return [] result = [] q1 = queue.Queue() q1.put...
5ec0c37c0515fd8259971de82060d3dab855fef9
lmb633/leetcode
/148sortList.py
1,262
4
4
# Definition for singly-linked list. class ListNode(object): def __init__(self, x): self.val = x self.next = None class Solution(object): def sortList(self, head): if head is None or head.next is None: return head fast = head.next low = head ...
b8012582ed4f71a8fb36c2f250484519b766933d
lmb633/leetcode
/80removeDuplicates2.py
655
3.609375
4
class Solution(object): def removeDuplicates(self, nums): j = 1 sum_ = 1 flag = True for i in range(len(nums) - 1): if nums[i] != nums[i + 1]: nums[j] = nums[i + 1] j += 1 sum_ += 1 flag = True ...
dd09c64d19d7b926d57d34ddfa6512c6c5603d58
lmb633/leetcode
/47permuteUnique.py
719
3.59375
4
class Solution(object): def permute(self, nums): result = [] self.process([], nums, result) return result def process(self, prefex, left, result): print(left) if len(left) <= 1: result.append(prefex + left) # print(result) r...
2d389f996b692b22b5084ed2cb896a6cd7a35872
lmb633/leetcode
/155minstack.py
701
3.921875
4
class MinStack(object): def __init__(self): self.data = [] self.minval = [] """ initialize your data structure here. """ def push(self, x): self.data.append(x) self.minval.append(x if not self.minval else min(self.minval[-1], x)) """ ...
8c172297723b17d46ebb4641304df36fce521ab6
lmb633/leetcode
/33search.py
1,127
3.734375
4
class Solution(object): def search(self, nums, target): def helper(nums, low, high, target): if low > high: return -1 mid = (low + high) // 2 # print(mid) if nums[mid] == target: return mid elif nums[mid] < ...
7f3eefce0e58e39b5f7ad60a1ebc6f3e19266e36
lmb633/leetcode
/37solveSudoku.py
3,315
3.640625
4
class Solution: def __init__(self): self.flag = True def solveSudoku(self, board): self.solve(board, 0, 0) def solve(self, board, i, j): while board[i][j] != '.': if j < 8: j += 1 elif i < 8: i += 1 ...
9c22084de4e02a2ded3d1fc192d5318456973496
lmb633/leetcode
/032-2levelOrder.py
774
3.921875
4
# Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def levelOrder(self, root): result = [] queue = [] queue.append(root) while queue: ...
e6cc11298f2984629db97ec7e7c4dd6e08c06e3f
lmb633/leetcode
/21mergeTwoLists.py
749
3.84375
4
# Definition for singly-linked list. class ListNode(object): def __init__(self, x): self.val = x self.next = None class Solution(object): def mergeTwoLists(self, l1, l2): result0 = ListNode(0) result = result0 while l1 is not None and l2 is not None: ...
01f312bf0765947118818d215e4d2a7bd3786935
lmb633/leetcode
/interview35copyRandomList.py
731
3.59375
4
# Definition for a Node. class Node: def __init__(self, x, next=None, random=None): self.val = int(x) self.next = next self.random = random class Solution(object): def copyRandomList(self, head): head0 = head node_map = {} node_map[None] = None ...
18868c724ba1655e0b9fc82014dd7e5453380822
lmb633/leetcode
/98isValidBST.py
2,001
3.84375
4
# Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def isValidBST(self, root): result, _, _ = self.isvalid(root) return result def isvalid(self, ro...
073255e849b8d17597c2156d2c228d5ce11693db
lmb633/leetcode
/90subsetsWithDup.py
829
3.515625
4
class Solution(object): def subsetsWithDup(self, nums): nums_set = {} for num in nums: if num not in nums_set: nums_set[num] = 1 else: nums_set[num] = nums_set[num] + 1 result = [[]] print(nums_set) for num in ...
458b0ddbf435b84a7fe3b7cc81e6ab4f8b256935
jesussantana/Advanced-Machine-Learning
/scripts/tydy.py
562
3.734375
4
# Correlation between numeric columns # ============================================================================== import numpy as np def corr_matrix(corr_mat): # Function to convert a pandas correlation matrix to tidy format corr_mat = corr_mat.stack().reset_index() corr_mat.columns = ['va...
20ead027159a007aafcaa2e9c3410fea56270e39
josenava/katas
/cracking_the_code_interview/python/chapter_2/06.py
989
3.984375
4
from typing import Optional from chapter_2.linked_list import LinkedList, Node def reverse_and_clone(n: Node) -> Node: head: Optional[Node] = None while n is not None: node = Node(n.value) node.next = head head = node n = n.next return head def is_palindrome(ll: LinkedL...
61dc1ba0aa708ed8f95e3f7c81451067087725f5
josenava/katas
/elements_of_programming_interviews_in_python/04/01.py
225
3.5625
4
def word_parity(x: str) -> int: result = 0 while x: result ^= x & 1 x >>= 1 return result if __name__ == "__main__": assert 1 == word_parity(0b1011) assert 0 == word_parity(0b10001000)
9db0188c3c5c0801b9575103226cd190019c5f26
josenava/katas
/algorithms/python/bubble_sort.py
479
3.953125
4
def bubble_sort(l: list[int]) -> list[int]: sorted = False unsorted_until_idx = len(l) - 1 while not sorted: sorted = True for i in range(unsorted_until_idx): if l[i] > l[i+1]: print(f"Swap! {l[i]} <-> {l[i+1]}") l[i+1], l[i] = l[i], l[i+1] ...
096c4efee6c484cc8a161d2f4c48827c2e502c2f
lemonade512/CodeSnippets
/Python/Decorators/lazy_thunkify.py
2,169
3.609375
4
#!/usr/bin/env python """ This decorator will cause any function to, instead of running its code, start a thread to run the code, returning a thunk (function with no args) that waits for the function's completion and returns the value (or raises the exception). Useful if you have Computation A that takes x seconds and ...
45971d9756dbb11d7b5c583de74c9c5fcd71fab5
lemonade512/CodeSnippets
/Python/make_args_strings.py
866
4.4375
4
#!/usr/bin/python ''' make_args_strings.py This snippet is an example of a decorator. The decorator in this case takes a functions arguments and turns them into strings. Author: Phillip Lemons Date Modified: 2/16/2014 ''' def _make_arguments_strings(fn): def wrapped(*args, **kwargs): new_args = [str(arg) for ar...
216c61180633ec8692f95639fea2a01207f5bf7d
lemonade512/CodeSnippets
/Python/Decorators/disable_function.py
600
3.640625
4
#!/usr/bin/env python def unchanged(func): """ This decorator doesn't add any behavior. """ return func def disabled(func): """ This decorator disables the provided function, and does nothing. """ def empty_func(*args, **kwargs): pass return empty_func # define this as equivalent to unch...
3c1d4af2a43bcf76c415665b6a11329fa071d824
bunedin81/coding_test
/Programmers/크레인 인형뽑기 게임.py
718
3.59375
4
def solution(board, moves): answer = 0 stack = [] #for moves # 변수 = 해당의 가장 위의것(없을 때 예외처리) # if 이전 요소가 있고, 현재요소와 같으면 # answer++, 제거처리 # else # 스택에 넣기 for move in moves: pick = 0 for row in board: if row[(move-1)] != 0: ...
f181a419f00951bb974d68585f161ab9fb64323d
bunedin81/coding_test
/LeetCode/905. Sort Array By Parity.py
471
3.515625
4
class Solution: def sortArrayByParity(self, nums: List[int]) -> List[int]: rtn = [] for i in range(len(nums)): if nums[i]%2 == 0: rtn.insert(0, nums[i]) else: rtn.append(nums[i]) return rtn #Runtime: 88 ms, faster than 24.63% of Py...
21a3f139974a8944d4fd6469fe6af6a895caf549
bunedin81/coding_test
/LeetCode/406. Queue Reconstruction by Height.py
542
3.703125
4
class Solution: def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: new_list = [] people.sort(key=lambda x:[x[0], -x[1]], reverse=True) #print(people) for i in people: new_list.insert(i[1], i) #print(new_list) retu...
9b6ef61ab894aea3c67173636c288ab70a3d81f2
JosuaKugler/bible_by_heart
/lib/backend/texttodb.py
1,536
3.65625
4
# -*- coding: utf8 -*- import sqlite3 import codecs conn = sqlite3.connect('bible.db') c = conn.cursor() c.execute("DROP TABLE IF EXISTS bible") c.execute( "CREATE TABLE bible (id INTEGER PRIMARY KEY,book TEXT NOT NULL,chapter INTEGER NOT NULL,verse INTEGER NOT NULL,text TEXT NOT NULL, learnStatus INTEGER NOT NUL...
8b673316e846f739f569f9272520601544043612
kroff666/Lesson_2
/ДЗ_4.py
251
3.796875
4
word = input('Введите слова через пробел: ') word_2 = word.split() # for word_2 in enumerate (word_2, 1): # print(word_2[:10]) res = dict(list(enumerate(word_2, 1))) for k, v in res.items(): print(f'{k} - {v[:10]}')
36a954927598fadbe00363fc790d92d29459d821
thewassermann/crypto109
/crypto_object.py
786
3.6875
4
import numpy as np import pandas as pd class Coin(): """ Class to store all data related to a particular cryptocurrency Parameters ---------- name : str name of coin object data_path : str file path for data object """ def __init__(self, name, data_path): self.name = name self.full_data = pd...
801049515490b092daac7d4caf323436c361b312
duongvuhong/alien-invasion
/alien.py
551
3.765625
4
"""alien.py""" import pygame ALIEN_IMAGE = 'images/alien.png' class Alien(pygame.sprite.Sprite): """A class to represent a single alien in the fleet.""" def __init__(self, screen): """Initialize the alien, and set its starting position.""" super().__init__() self.__screen = screen ...
6b96859704f7887af9d04055de6fddf73e17b205
v1233c/color
/ColorCircle.py
547
3.546875
4
#Initialization import turtle vicky = turtle.Turtle() import random turtle.colormode(255) vicky.speed(100) #Functions def randomDot(): r = random.randint(0,255) g = random.randint(0,255) b = random.randint(0,255) c = random.randint(0,100) vicky.color(r,g,b) vicky.begin_fill() ...
4bf064116e04752825bccdcf679b829eaa32afc7
aws/sagemaker-rl-container
/src/vw-serving/src/vw_serving/utils.py
867
3.515625
4
import importlib import random import string def dynamic_import(path): """Dynamically import a class from a python module. Arguments: path (str) -- "module.submodule.MyClass" Returns: The corresponding class object if the import was successful. Raises: ModuleNotFound...
0b8818ec7b289a1b63b9f8bcb6bb34c4ca038e92
BeeMan3/CS_372
/Program1/chatserve.py
1,950
3.703125
4
#John Behman #chatserve.py #This program is a chat server that allows a client to connect to it and communicate back and forth with the client #CS 372 Project 1 #7/28/2019 from socket import * import sys if __name__ == "__main__": if len(sys.argv) != 2: #verify that the correct # of arguments were entered ...
ef40c99d5ca25b2a02e456a86d90a8e3373eee02
mhowlader/SoftdevSpring
/20_anon-reduce/listcomp.py
278
3.5
4
# Team Papaya (Mohtasim Howlader and Johnny Wong) # SoftDev1 pd8 # K20 -- Reductio ad Absurdem # 2019-04-18 file = open('romeo.txt', 'r').read().split() newfile = [x.strip() for x in file ] def freq(word): return [x for x in newfile if word in x] print(freq("Romeo")) def totalfreq()
3197055f59b4c124056f33e3e6c3f7a70aca12a5
JosephKeogh/VTRCODPathAnalysis
/VDOTStaff/PythonFiles/ODIdentification/breakApart.py
1,167
3.5
4
import csv fileCount = 0 for d in range(0, 5): originalFileName = "trips" + str(d) + ".csv" '''needs to be outside of file loop''' '''need to have separate smaller files for each of larger trip files''' with open(originalFileName, 'r', newline='') as original: print("Reading file: " + orig...
f24668bb58f719fc3cf0ce6ee1c0de91caaf5605
JosephKeogh/VTRCODPathAnalysis
/VDOTStaff/PythonFiles/ODIdentification/CreateShortData.py
534
3.640625
4
import csv # open the data file data = [] with open("trips.csv", "r", newline='') as inputFile: inputData = csv.reader(inputFile) print('finished reading input file') count = 0 for inputLine in inputData: data.append(inputLine) count = count + 1 if count >= 1000: br...
52da418e27564c12bd5ab6c12f8ecd9a90efc188
caguilarcr/AIND-Isolation
/heuristics.py
6,084
3.703125
4
""" This file contains all the heuristics implemented for this project. """ def weighted_improved_score(game, player): """ Same as the improved_score heuristic but prioritizing the amount of moves the player has over the opponent's remaining moves. Parameters ---------- game : `isolation.B...
73130fa5ed1b117cd54ae2276a96cd3cbe883f05
yangyichen5246/python_learning
/daily_pragram/09-27.py
621
3.65625
4
import random secretNumber = random.randint(1,20) print('来,咋们玩一个游戏,猜一个1-20间的数值.') for guessesTaken in range(1,8): print('游戏开始,请在下方输入一个数字:') guess = int(input()) if guess < secretNumber: print('你猜的太小了') elif guess > secretNumber: print('你猜的太大了') else: break if guess == sec...
4fb205c1d05d96e37d8b07e08d21247ac9baf140
dPaliura/PNN_attacks_recognition
/neurons/neuronsLayer.py
1,361
3.640625
4
from neurons.neuron import Neuron from neurons.inputNeuron import InputNeuron class NeuronsLayer: def __init__(self, neurons): self._set_neurons(neurons) self._size = len(self._neurons) if not self._size: raise Exception("It expected at least 1 object of class Neuron in 'neurons...
45a9973d25c27760180fdcb98109e8a4e931c00e
ishaanshah/paddle-ball
/ball.py
4,841
3.625
4
import config import math from object import Object from typing import List class Ball(Object): def __init__(self, x: int, y: int, speed: List[int], strength: int, screen): super().__init__( x, y, *config.ball["dim"], config.ball["color"], screen ) self.paused = Tr...
ba196419c75e6af1a4a0b2235cd9db21e41bab6b
rebekaheh/Python_Challenge
/Minis/ARCHIVE!/Udemy_Zip.py
2,344
3.6875
4
# -*- coding: utf-8 -*- """ Created on Tue Oct 13 21:50:02 2020 @author: RebekahDSK """ # Import to Pandas import pandas as pd import csv # Find the path to the file # Navigate to the source CSV file # Shift + Right Click # Copy as path # Paste the path after r # Name of file = pd.read_csc(r'path of file') udemy = p...
7c514984988fa1dd67b6db96eb4b2f01a1370a91
CodecoolMSC2016/python-pair-programming-exercises-2nd-tw-bpekar_gugyan
/passwordgen/passwordgen_module.py
833
3.515625
4
import string import random def passwordgen(): password = "" for i in range(0, random.randint(8, 15)): x = random.randint(1, 4) if x == 1: password += str(get_lowerc()) elif x == 2: password += str(get_upperc()) elif x == 3: password += str(g...
5a45019f49664ea235b6db3354f3b7f808b81f2c
Dimon0014/Decor_27
/23_arg_dec_and_arg_func.py
2,782
3.578125
4
# coding=utf-8 def decorator_maker_with_arguments(decorator_arg1, decorator_arg2): print "Я создаю декораторы! И я получил следующие аргументы:", decorator_arg1, decorator_arg2 def my_decorator(func): print "(Ака декоратор)Я - декоратор. И ты всё же смог передать мне(декоратору) эти аргументы:", decorator_arg1, d...
3657d26b26caf4875ed8a0e3478843e2bd0d0209
alzheimeer/holbertonschool-higher_level_programming
/0x04-python-more_data_structures/100-weight_average.py
195
3.609375
4
#!/usr/bin/python3 def weight_average(my_list=[]): z, y = 0, 0 if my_list == []: return 0 for x, m in my_list: z += (x * m) y += (m) z /= y return (z)
a6a4767836bc3f32ab976e194390e783fe8fb8f5
alzheimeer/holbertonschool-higher_level_programming
/0x0B-python-input_output/1-number_of_lines.py
213
3.734375
4
#!/usr/bin/python3 def number_of_lines(filename=""): '''returns the number of lines of a text file''' with open(filename, 'r', encoding="utf-8") as f: readf = len(f.readlines()) return readf
c829a7f379119a3e735a4a9b20de160faa4c3776
alzheimeer/holbertonschool-higher_level_programming
/0x07-python-test_driven_development/3-say_my_name.py
543
4.40625
4
#!/usr/bin/python3 def say_my_name(first_name, last_name=""): """ Args: first_name (str): the first name last_name (str, optional): the last name Raises: TypeError: if the first_name or last_name are not strings """ if first_name is None or type(first_name) is not str: ...
ee6467cd217130056000e3c469b216fbed9c4acc
jd-harris/python-snake-games
/curses/snake_curses.py
4,967
3.96875
4
import random import curses s = curses.initscr() # initialize the screen curses.curs_set(0) # set the cursor to zero, so that it does not show up on screen # nopep8 sh, sw = s.getmaxyx() # get the height and the width w = curses.newwin(sh, sw, 0, 0) # create a new window from the height and width, and start it at ...
f894ebfd8adf584907398e3d5270dfabd2f82fd9
ShivamSainier/Competitive-programming
/Element.py
238
3.703125
4
def element(x,y): r=0 for i in range(0,len(x)-1): if x[i]==y[i]: continue else: r=r+i return r+1 x=[12,23,5,34,45,67,78] y=[12,23,34,45,67,78] result=element(x,y) print(result)
c11c32bf1bbac5f17a81d5a4019a6b8b37e98421
ShivamSainier/Competitive-programming
/linear.py
185
3.734375
4
def search(li,n): for i in li: if i==n: return True return False li=[4,5,6,21,3,4,5,6] n=6 if search(li,n): print("Found") else: print("Not Found")
5ef62bc2bf63e3029faacc02eca3b3b11793161c
chenjiahui1991/LeetCode
/P0009.py
497
3.6875
4
class Solution: def isPalindrome(self, x): """ :type x: int :rtype: bool """ if x < 0: return False result = 0 origin = x while x > 0: result = result * 10 + x % 10 x = x // 10 if result == origin: ...
3c09f0181b157f6eb955f3e8ab36c73ce0214183
chenjiahui1991/LeetCode
/P0160.py
1,165
3.765625
4
# Definition for singly-linked list. class ListNode(object): def __init__(self, x): self.val = x self.next = None class Solution(object): def getIntersectionNode(self, headA, headB): """ :type head1, head1: ListNode :rtype: ListNode """ def getSize(node):...
b05f442731c35397679eeb875833cac15a1704ba
chenjiahui1991/LeetCode
/P0097.py
906
3.703125
4
class Solution: def isInterleave(self, s1, s2, s3): """ :type s1: str :type s2: str :type s3: str :rtype: bool """ m = len(s1) n = len(s2) if m + n != len(s3): return False f = [[False for _ in range(n + 1)] for _ in range(m...
47140adee8e24c62bc4ec96c431ec37a4ec6aa64
chenjiahui1991/LeetCode
/P0112.py
1,068
3.828125
4
# Definition for a binary tree node. class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def existsSum(self, root, sum, target): if root.left == None and root.right == None: if sum + root.val == target: ...
6c0b2f0889fc33e4a8175796e2542c9b4e3b53a1
chenjiahui1991/LeetCode
/P0083.py
932
3.78125
4
# Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ if head == None: return None resu...
a5a4cbf930908febbacb596d6ede60503185b05c
chenjiahui1991/LeetCode
/P0234.py
1,047
3.78125
4
# Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def isPalindrome(self, head): """ :type head: ListNode :rtype: bool """ if head is None: return True length = 1 ...
5b0ad789d2a1fec46441b5808217e7a02062b1dd
chenjiahui1991/LeetCode
/P0167.py
690
3.515625
4
class Solution: def twoSum(self, numbers, target): """ :type numbers: List[int] :type target: int :rtype: List[int] """ def binary_search(nums, val): left, right = 0, len(nums) - 1 while left <= right: mid = (left + right) >> 1 ...
46aabe5d00fbc6b9ec25b8b67604c6af44b5a64d
chenjiahui1991/LeetCode
/P0258.py
323
3.78125
4
class Solution: def addDigits(self, num): """ :type num: int :rtype: int """ while num > 9: tmp = num num = 0 while tmp > 0: num += tmp % 10 tmp //= 10 return num s = Solution() print(s.addDigits(38...
ec203f285d321139dbb421950975c889b2ea3324
chenjiahui1991/LeetCode
/P0026.py
440
3.546875
4
class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums) == 0: return 0 point = 0 for val in nums[1 :]: if val != nums[point]: point = point + 1 nums[point]...
d65d22f6a7e69c886203c873e3870359b74f2eed
chenjiahui1991/LeetCode
/P0225.py
1,053
4.1875
4
class MyStack: def __init__(self): """ Initialize your data structure here. """ self.line = [] def push(self, x): """ Push element x onto stack. :type x: int :rtype: void """ self.line.append(0) for i in range(len(self.li...
d25038849b269001b45df625d807bdd15b3fad0f
jvanvugt/advent-of-code-2019
/start_day.py
609
3.734375
4
#! /usr/bin/env python from pathlib import Path import sys TEMPLATE = """ def a(): ... def b(): ... def main(): open("input{day}.txt") print(a(...)) if __name__ == "__main__": main() """.lstrip("\n") def main(): day = f"{int(sys.argv[1]):02d}" code = TEMPLATE.format(day=day) co...
5186b425900ac703a3ca8deeb89fbc28dbc7fbab
Amine-HADJEMI/python-code-katas
/src/katas/roman_numerals.py
579
3.78125
4
class RomanNumerals: numerals = { 'M': 1000, 'CM': 900, 'D': 500, 'CD': 400, 'C': 100, 'XC': 90, 'L': 50, 'XL': 40, 'X': 10, 'IX': 9, 'V': 5, 'IV': 4, 'I': 1, } def generate(self, number): if (n...
1b09b5d56c8cb1f3085d871b4190be0152e37d93
Amine-HADJEMI/python-code-katas
/tests/chain_adding_test.py
298
3.5625
4
from src.katas.chain_adding import Add import unittest class ChainAddingTest(unittest.TestCase): def test_it_adds_numbers_together_when_called_in_succession(self): self.assertEqual(3, Add(1)(2)) self.assertEqual(6, Add(1)(2)(3)) self.assertEqual(10, Add(1)(2)(3)(4))
48812ca06447cb3e6b6ac90a44022bd211a7c4e0
jaehui327/pythonAlgorithm
/programming#01/problem01.py
1,176
3.84375
4
# 이진 탐색을 수행하는 함수 # a[mid] = key인 인덱스 mid를 반환하는 함수 def binarySearch(a, key, left, right): # 전역변수 times를 사용한다고 명시 global times while left <= right: mid = (left + right) // 2 if key == a[mid]: times += 1 return mid elif key < a[mid]: times += 1 ...
f583742335aa485571f9dfaeed080ebe60eae61a
OskarBreach/advent-of-code-2019
/day02.py
3,902
3.5625
4
import itertools from collections import defaultdict class Computer: def __init__(self, memory, input = []): #self.memory = memory self.memory = defaultdict(int) for i in range(0, len(memory)): self.memory[i] = memory[i] self.ip = 0 self.output = [] self....
3990fd7ab3b945533c44f73bde831ea5ae9d238b
OskarBreach/advent-of-code-2019
/day11.py
1,749
3.625
4
from day02 import Computer from collections import defaultdict def paint_grid(computer, grid): pos_x = 0 pos_y = 0 directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] direction_symbol = ['^', '>', 'V', '<'] direction = 0 while not computer.halted: computer.add_input([grid[pos_x][pos_y]])...
e87655c78990045d30529d8879755caa3e9f1b27
zkeshtkar/Algorithm
/Sorting/CorrectnessAndTheLoopInvariant.py
382
3.765625
4
def insertion_sort(arr): for i in range(1, len(arr)): index = i while arr[index - 1] > arr[index] and index > 0: temp = arr[index - 1] arr[index - 1] = arr[index] arr[index] = temp index -= 1 m = int(input().strip()) ar = [int(i) for i in input().st...
7436f8bdb27e1e4c01855274f6f5909f50501e35
zkeshtkar/Algorithm
/Recursion/CrosswordPuzzle.py
1,210
3.71875
4
#!/bin/python3 import math import os import random import re import sys # # Complete the 'crosswordPuzzle' function below. # # The function is expected to return a STRING_ARRAY. # The function accepts following parameters: # 1. STRING_ARRAY crossword # 2. STRING words # def crosswordPuzzle(crossword, words): ...
c3b8e4b4bdcb86ef3f5c9fc8d2894cae5958ed41
pybootcamp/pybootcamp.github.io
/examples/count_words.py
765
3.984375
4
#!/usr/bin/env python """Create a wordlist from multiple files.""" import sys from collections import Counter def gen_tokens(filenames): """Generate tokens from each file.""" for filename in filenames: input_file = open(filename, "U") for line in input_file: for token in line.spli...
e665cc9dec5c024761fb8fab21673bcf680786e4
Skylerliutian/unsw-2019-t1
/unsw-it-9021/python-code/challenges_1/home4/mean_median_standard_deviation.py
2,355
3.90625
4
# Written by Eric Martin for COMP9021 ''' Prompts the user for a strictly positive integer, nb_of_elements, generates a list of nb_of_elements random integers between -50 and 50, prints out the list, computes the mean, the median and the standard deviation in two ways, that is, using or not the functions from the sta...
2a5ae33d06e71067e4a2aea31876fda402ab00aa
Skylerliutian/unsw-2019-t1
/unsw-it-9021/python-code/challenges_1/celsius_to_fahrenheit.py
566
3.640625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019-02-23 16:10 # @Author : ZD Liu def celsius_to_fahrenheit(): import os print('TEST 1 BEGIN') print('$ python3 '+ os.path.basename(__file__)) min_temperature = 0 max_temperature = 100 step = 10 print('Celsius\tFahrenheit') f...