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
8d8fc5739fa1b95c08a4cbe905fc55d160183af4
andy-shaw/daily_challenges
/flagon_of_flags.py
810
3.921875
4
''' Andy Shaw 11/3/2014 http://www.reddit.com/r/dailyprogrammer/comments/2l6dll/11032014_challenge_187_easy_a_flagon_of_flags/ ''' if __name__ == '__main__': #user enters how many flags to input flags = {} n = int(raw_input("Enter the number of flags being entered.\n")) for i in range(n): fla...
35df200023532f6ba7507e980fc7ca4a74fe0916
chinthaedu/MyWork
/contacts.py
946
3.921875
4
contacts=dict() contacts['ravi']=9090909090 while(True): print("Enter your option : ") print("1\tINSERT\n2\tDISPLAY\n3\tUPDATE\n4\tDELETE\n0\tCLOSE Contacts Book") opt=int(input()) if(opt==1): name=input("Enter the name to add to Contacts Book:") if name in contacts: print(na...
57cc5bfb82b09085eb85988f76ee7894b29a6a07
ferosamachado/python_code
/google.py
1,635
3.875
4
#Funo: Lista do google develop day #Autor: Felipe Rosa e Raphael Ramos #Professor: Fernando Massanori #!/usr/bin/python -tt # Copyright 2010 Google Inc. # Licensed under the Apache License, Version 2.0 # http://www.apache.org/licenses/LICENSE-2.0 # Google's Python Class # http://code.google.com/edu/languages/google...
bf718f5ba9c509045d81e971e753b74a3b613db0
navin-bhaskar/Daily-Interview-Pro
/Python/edit_distance.py
980
3.5
4
""" Shree Krishnaya Namaha """ class Solution(object): """Finding the edit distance between two strings https://leetcode.com/problems/edit-distance/""" def minDistance(self, word1, word2): shorter, longer = (word1, word2) if len(word1) < len(word2) else (word2, word1) e...
cf368f8514d6e295220944879b4694b828e6b105
navin-bhaskar/Daily-Interview-Pro
/Python/06_reverse_linked_list.py
1,588
4.03125
4
" Shree Krishnaya Namaha " class ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next def print(self): node = self out_str = "" while node.next is not None: out_str += str(node.val) + "-...
8e1e3229ef8d16268ec2d757dc10c14b38b265a3
rishabh-bhatnagar/allgo
/tree_sort.py
786
4
4
''' Time Complexity Best : O(n log(n)) Average : O(n log(n)) Worst : O(n ^ 2) ''' class Node: def __init__(self, data): self.left = None self.right = None self.data = data def insert(root, node): if root is None: root = node else: if root.data > node.data: if root.left is None: ...
86766e3bd7beb29bc3662d6da72da3b71560ca79
rishabh-bhatnagar/allgo
/selection_sort.py
339
3.90625
4
''' Time Complexity Best: O(n^2) Average : O(n^2) Worst : O(n^2) ''' def SELECTION_SORT(A): for i in range(len(A)): min_index = i for j in range(i + 1, len(A)): if A[min_index] > A[j]: min_index = j A[i], A[min_index] = A[min_index], A[i] A = [9, 8, 7, 6, 5, 4, 3, 2, 1] SELECTION_SO...
297bdf60d261fe72feb92756edf2befa66e06ebf
mahongkai0/python
/day09/day09.py
7,372
3.515625
4
########序列传参示例: # def ss(a,b,c): # print("a=",a) # print("b=",b) # print("c=",c) # L= [1,2,3] # ###ss(L[0],L[1],L[2]) # ss(*L) # T = (100,200,300) # s = "ABC" ################关键字传参 # def sss(a,b,c): # print("a=",a) # print("b=",b) # print("c=",c) # sss(c = 3,b = 2,a = 1) 可以不按位置 不能多给 # L...
6de2e9c4ae50cdc1823634eaf4b9f0d6db3b8023
mahongkai0/python
/平叠/day14 学生/day14shi.py
4,602
3.734375
4
# def div_apple(n): # print("%d个苹果想分组几个人?"%n) # s = input("请输入人数") # count =int(s) ##可能触发ValueError错误 # result = n / count ### # print("每一个人分了",result,'苹果') # try: # div_apple(10) # print("分苹果成功") # ## except (ValueError,ZeroDivisionError): # ## print("N") # excep...
fe3be2c902c90456bc0ef2360cb770446844704d
mahongkai0/python
/tadelianxi/练习5.py
7,372
3.65625
4
# 首先示例while的嵌套 #  打印1 到20  十行 # s = 1 # while s <= 10: # #print("此行语句会执行10次") # i = 1 # while i <= 20: # print(i, end = ' ') # #if i == 10: # # break 打断 # i += 1 # print() # s = s + 1 # 输入一个整数n 打印指定宽度的正...
8bb8c925697b04f3fe994ffcadd5c144cb637356
awesomezenphoto/awesomeQR
/awe-qr.py
1,916
3.59375
4
''' Functions of awe-qr.py 1. input file for names. one name per line. 2. generate qr code for each name. 3. save qr image to a word document. 'myQRStudents.docx' ex. awesome-qr.exe <names-file> the qr code will be save in myQRStudents.docx file..... For development requirement: 1. python 3.5 2. python qr code 3. py...
43ea03ea1d693d03366841964a2808e64626c414
MihaiRr/Python
/lab11/Recursion.py
1,335
4.46875
4
# The main function that prints all # combinations of size r in arr[] of # size n. This function mainly uses # combinationUtil() def printCombination(arr, n, r): # A temporary array to store # all combination one by one data = [""] * r # Print all combination using # te...
86b6be121a3af8171cf502278d6a7cd974db0533
jshubh19/pythonapps
/bankaccount.py
2,486
4.15625
4
# bank account class BankAccount: ''' this is Janta ka Bank''' def __init__(self,accountname='BankAccount',balance=20000): #for making class method we use __init__ const self.accountname=accountname self.balance=baalance def deposite (self,value): self.balance=self.balance+val...
8a6968d9b1f30be9f2779661a25f45389db5f116
Shreejan-git/DataStructures
/BubbleSort.py
1,543
3.765625
4
class BubbleSort: def __init__(self, array_data): self.data = array_data def sort_num(self): length = len(self.data) for i in range(length-1): swapped = False for j in range(length-1-i): if self.data[j] > self.data[j+1]: self....
d08beb27c9e4f3b8c156026cc67d741ee66b1e08
Shreejan-git/DataStructures
/SelectionSort.py
412
3.71875
4
def selection_sort(data): data_size = len(data) for i in range(data_size-1): min_value_at = i for j in range(min_value_at+1, data_size): if data[j] < data[min_value_at]: min_value_at = j if i != min_value_at: data[i], data[min_value_at] = data[min_...
8cd98019b2a8ab395911ee3af939b7a2d33e2a31
python-programming-1/homework-2b-dsileo
/dominicksileoHW2bRetry.py
2,422
4.09375
4
import random playerScore = 0 computerScore = 0 def getComputerHand(): randomNumber = random.randint(1,3) if randomNumber == 1: computerHand = 's' elif randomNumber == 2: computerHand = 'r' else: computerHand = 'p' return computerHand def getPlayerHand...
49769a5155ff64d9d09227e91ba1a32a9e87cf8e
kalkoen/ru-pythoncursus-2017
/week3/opdracht1e.py
1,964
4.0625
4
__author__ = 'guest148' import turtle import math def getcolor(dutch): if(dutch == "geel"): return "yellow" elif(dutch == "groen"): return "green" elif(dutch == "rood"): return "red" elif(dutch == "blauw"): return "blue" elif(dutch == "paars"): return "purpl...
38dbadb1466e81d4b82a6151135e0b8e021f8760
dom681/GuessNumber
/GuessTheNumber.py
938
4.03125
4
import random print "GUESS THE NUMBER GAME" RangeTruth = True while RangeTruth: NumbRang = (input("Please enter the upper boundary of your guessing range:")) if isinstance(NumbRang, int): list=[] for i in range(1,NumbRang+1): list.append(i) print list cont = Tr...
4d8563d9809ac88bfa0a61cd946d7378ee939513
drodevilosun/Python
/Exercise/Exercise20.py
596
4.09375
4
# This exercise learn about seek() in python # Refs: https://python-reference.readthedocs.io/en/latest/docs/file/seek.html from sys import argv input_file = argv[0] def print_all(f): print(f.read()) def print_a_line(time,f): print(time,f.readline()) def rewind(f): f.seek(2) def close_fi...
6513812ab589a7b46a32b5fa79743748b4b3d195
rizkyfransisca/TugasProclubWeek2
/hw2.py
617
3.609375
4
print("Klub A: ",end="") klubA = input() print("Klub B: ",end="") klubB = input() print("Pertandingan 1 : ",end="") hasil = input().split() i = 1 array = [] while int(hasil[0]) != -1 and int(hasil[1]) != -1: if int(hasil[0]) > int(hasil[1]): array.append(klubA) elif int(hasil[1]) > int(hasi...
ed2fbbbe080b4bffecc71b1aee604213826a0e08
qingDragon/Python_Time
/day01/login.py
1,737
3.765625
4
# 输入用户名密码 # 认证成功后显示欢迎信息 # 连续输错三次后锁定 count = 0 while True: #输入用户名密码 username = input("Username:") password = input("Password:") #打开用户名密码文件 f = open('login_true.txt') #打开锁定用户名文件 f4 = open('login_lock.txt') #判断输入用户名是否存在于锁定文件中 for line in f4: user_name2 = line.strip() ...
099478d9a7100148308ea267dcc3e5cc0095cd67
qingDragon/Python_Time
/day07/属性方法.py
554
3.953125
4
class Dog(object): name = "12" def __init__(self,name): self.name = name self.__food = None #私有属性 @property #把一个方法编程静态属性,不能传参数了 def eat(self): print("%s is eating %s" %(self.name,self.__food)) @eat.setter def eat(self, food): print("set to food", food) ...
03db8cb0753c56ea69c9e69a1c30b8dc11212cad
rfc8367/R1
/L15/Task_3.py
1,028
4.1875
4
import re def password_patterns(): while True: user_password = input('Enter your password: ') length = len(user_password) print(f'Your password length {length}') if len(user_password) <= 8: print('Password must contain at least 8 characters') continue ...
5aa2266a7476cee3ce377a761f942690df268e9c
rfc8367/R1
/L5/Task_7.py
175
3.578125
4
def is_date(day, month, year): import datetime try: datetime.date(year, month, day) except ValueError: return False else: return True
da3d464a8d28500898437462b1f532d303fea411
rfc8367/R1
/L6/Task_1.py
249
3.6875
4
coin = ('Bitcoin', 'Ether', 'Ripple', 'Litecoin') code = ('BTC', 'ETH', 'XRP', 'LTC') def tpl_to_dict(): dict = {coin[i]: code[i] for i in range(len(coin))} print(dict) tpl_to_dict() #Cheat cheat = dict(zip(coin, code)) print(cheat)
6c562dadd0b180b5357b4ce57c73b440cb7c06a3
Mariam-Hemdan/ICS3U-Unit-4-01-Python
/while_loop.py
470
4.1875
4
#!/usr/bin/env python3 # Created by : Mariam Hemdan # Created on : October 2019 # This program uses while loop def main(): # this program uses While loop sum = 0 loop_counter = 0 # input positive_integer = int(input("Enter an integer: ")) print("") # process & output while loop_coun...
27dd3ed26ce0755a6b9ecca507b6bf932bfecae5
arw2019/AlgorithmsDataStructures
/Longest Consecutive Sequence in Binary Tree/LC298.py
876
3.703125
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 __init__(self): self.maxlen=1 def dfs(self, root: TreeNode, cnt: int) -> None: self.maxlen = max(self.m...
9d676d8286b6b6b4bfe646f3dad31eeb1baeb576
arw2019/AlgorithmsDataStructures
/Find Mode in Binary Search Tree/Leetcode_501.py
1,062
3.640625
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 findMode(self, root: TreeNode) -> List[int]: self.modes, self.maxFreq = set(), 0 self.curVal, self.no_occurences = No...
d90cf1df18c532d52507a19ff7d5191f5ea3a2f1
arw2019/AlgorithmsDataStructures
/Create Binary Tree From String/Leetcode_536.py
798
3.71875
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 str2tree(self, s: str, node: TreeNode = TreeNode(0)) -> TreeNode: if not s: return None root, _ = self.helper(s, 0) ...
3c21706e72c5033d3273e32f192d1f16cdd66b56
arw2019/AlgorithmsDataStructures
/Merge Two Sorted Linked Lists/Leetcode_21.py
1,022
3.96875
4
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: # unless both l1 and l2 are non-null there is little to do if not(l1 and l2): ...
4769c0e173635992f7a7e2a2459c5a61436cb911
arw2019/AlgorithmsDataStructures
/Reverse Nodes in a Group/Leetcode_25.py
1,021
3.609375
4
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseKGroup(self, head: ListNode, k: int) -> ListNode: def reverseSubList(start: ListNode, end: ListNode) -> ListNode: cur,...
118a2978aa3d27ccfb3f907cfe8644367a49d707
arw2019/AlgorithmsDataStructures
/Longest Univalue Path/Leetcode_687.py
860
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 longestUnivaluePath(self, root: TreeNode) -> int: self.ans = 0 def dfs(node: TreeNode): ...
75c62232d81e47f9f35aaefa1f62788e95974dcc
arw2019/AlgorithmsDataStructures
/Prefix and Suffix Search/Leetcode_745_trie_solution.py
1,745
3.53125
4
from collections import defaultdict, deque class TrieNode(object): def __init__(self): self.links = defaultdict(TrieNode) self.weight = 0 class WordFilter: def __init__(self, words: List[str]): self.words = words self.preRoot = TrieNode() self.suffRoot = TrieNode() ...
9d1c9370b716d38d8ac844ad215ad62977a04def
arw2019/AlgorithmsDataStructures
/Equal Tree Partition/Leetcode_663.py
1,031
3.84375
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 checkEqualTree(self, root: TreeNode) -> bool: self.cache = {} def dfs(node: TreeNode) -> None: ...
1748aef55824b37c71e6efb27e1ef9e65927e9c1
arw2019/AlgorithmsDataStructures
/Minimum Distance Between BST Nodes/Leetcode_743.py
634
3.703125
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 minDiffInBST(self, root: TreeNode) -> int: self.prev, self.ans = None, float('inf') def inorder(node: TreeNo...
ed138516ab9f6c2d2953868377dd3047f75233cf
arw2019/AlgorithmsDataStructures
/Strobogrammatic Number/Leetcode_246.py
321
3.671875
4
class Solution: def isStrobogrammatic(self, num: str) -> bool: strobo = {'0': '0', '1': '1', '6':'9', '8':'8', '9':'6'} upsideNum = '' for i, digit in enumerate(num): if digit not in strobo: return False upsideNum += strobo[digit] return upsideNum[::-1] == nu...
3059548fd40219eefab933071902331f30745909
Dan0dy/PY
/时间复杂度.py
1,003
4
4
#时间复杂度 #只是个估计 #时间复杂度相等,运行时间不一定相同 print('Hello world') #O(1) for i in range(n): print('Hello world') # 共执行n次 #O(n) for i in range(n): for j in range(n): print('Hello world') #O(n**2) for i in range(n): for j in range(n): for k in range(n): print('Hello world') #共执行 n**3 ...
78eebbec669e95bedd57fb74714c56a8a3705178
Pyabecedarian/Algorithms-and-Data-Structures-using-Python
/Stage_1/Task5_Sorting/bubble_sort.py
729
4.28125
4
""" Bubble Sort Compare adjacent items and exchange those are out of order. Each pass through the list places the next largest value in its proper place. If not exchanges during a pass, then the list has been sorted. [5, 1, 3, 2] ---- 1st pass ----> [1, 3, 2, 5] Complexity: O(n^2) """ def bub...
9a7e025e78313ab6bdbd840ad87b8fcfd2587347
Pyabecedarian/Algorithms-and-Data-Structures-using-Python
/Stage_1/Task2_LinkedList/merge_linkedlists.py
1,014
3.921875
4
""" ★ Task: To merge two ordered linkedlist into a ordered one. ★ """ from datastruct.collections import LinkedList def merge_linkedlists(alist: LinkedList, blist: LinkedList) -> LinkedList: newlist = LinkedList() p1, p2 = alist.head, blist.head k1, k2 = 0, 0 while p1.next and p2.next: v1, v2...
9d072a6807640c94375a15d97eb6c971e0a4d391
Pyabecedarian/Algorithms-and-Data-Structures-using-Python
/Stage_1/Task4_Queue_and_Recursion/fibonacci.py
290
4.09375
4
# Calculate fibonacci number: f(n) = f(n-1) + f(n-2) def fibonacci(n): if n <= 0: raise ValueError('n must be at least 1.') if n in [1, 2]: return 1 else: return fibonacci(n - 1) + fibonacci(n - 2) if __name__ == '__main__': print(fibonacci(7))
d31780d32274383cfb9b841415925734a2ca40fe
Pyabecedarian/Algorithms-and-Data-Structures-using-Python
/Stage_3/Task11_Graph/topological_sort.py
3,818
4.15625
4
""" Topological Sort Problem Solving: decide the steps that stirring up a batch of pancake. Recipe: 1 egg 1 cup of pancake mix 1 tablespoon oil 3/4 cup of milk heap the griddle, mix all the ingredients together and spoon the mix onto a hot griddle...
aa3b58f87df75309310b85bfd2a3fa05bec865ae
Pyabecedarian/Algorithms-and-Data-Structures-using-Python
/Stage_1/Task6_Binary_Search/fuzzy_binary_search.py
845
4.09375
4
""" Reversed from binary_search. Given a item, if the item in the list, return its index. If not in the list, return the index of the first item that is larger than the the given item If all items in the list are less then the given item, return -1 """ def binary_search_fuzzy(a...
37b0f2c86afa65c9fa2860dd2a57aef5d4183055
Pyabecedarian/Algorithms-and-Data-Structures-using-Python
/Stage_2/Task9_Binary_Tree/binary_tree.py
2,158
4.09375
4
""" Tree is either empty or consists of a root and zero or more subtrees, each of which is also a tree. The root of each subtree is connected to the root of the parent tree by an edge. * left right ...
66a7b6d6839b73137352b1c495d2ec705407b439
ttumiel/interpret
/interpret/attr/gradient.py
867
3.875
4
"Basic attribution that uses the gradient as the attribution map" from .attribute import Attribute class Gradient(Attribute): """Uses the gradient of the network with respect to a target class to create an attribution map. """ def __init__(self, model, input_img, target_class): assert input_im...
815de08527d53f7a335e493e117ce0835ec298e1
sigurbjornleo/forritun_verk
/verk2.py
508
4
4
initial_amount = float(input("Enter the initial amount: ")) # Do not change this line interest = float(input("Enter the interest(%): ")) # Do not change this line years = int(input("Enter for how many years: ")) # Do not change this line interest_percent = float(interest * 0.01) current_amount = float(initial_amount) f...
ba826f8e93a5678b0c8908fda1d161817ef431ae
hussain-devpro/Python-Learning
/scripts/my_flask/my_flask_intro.py
3,174
3.640625
4
# Flask is web-development micro framework # It doesn't have many features. Most of the things requires extensions. Following are the two major features # Jinja 2: It is template engine # Werkzeug: It provides HTTP related features from flask import Flask from datetime import datetime count = 0 app = Flask(__name__) ...
620842a2c4783091faf4e250797fe2d8efc54046
hussain-devpro/Python-Learning
/scripts/my_numpy/my_numpy_complex_indexing.py
3,314
4.15625
4
import numpy as np a = np.arange(12) ** 2 print(a) # [ 0 1 4 9 16 25 36 49 64 81 100 121] # simple index print(a[0], a[4], a[7]) # 0 16 49 # complex index, creating 1D numpy array with list or numpy array of index # for creating numpy array we can pass list or another numpy array as index index_1 = [...
7d27113057962045101d28d3b0234164f13539a0
vincesanders/Data-Structures
/binary_search_tree/binary_search_tree.py
5,294
4.28125
4
from queue import Queue from stack import Stack """ Binary search trees are a data structure that enforce an ordering over the data they store. That ordering in turn makes it a lot more efficient at searching for a particular piece of data in the tree. This part of the project comprises two days: 1. Implement the m...
43ffe3c202c52f7974f163667b9a98ae78405e7e
tangkaiyang/python3_laioxuefeng
/chapter03/iterable_test.py
303
3.9375
4
# -*- coding:UTF-8 -*- def findMinAndMax(L): if len(L) < 2: return tuple(L) else: min, max = L[:2] for i in L: if i < min: min = i if i > max: max = i return min, max print(findMinAndMax([1, 2, 3, 4, 5]))
49e847db34b2669c0373fe87cac47385795e288b
tangkaiyang/python3_laioxuefeng
/chapter04/create_counter.py
783
3.796875
4
# -*- coding:UTF-8 -*- # def count(): # def f(j): # def g(): # return j * j # # return g # # fs = [] # for i in range(1, 4): # fs.append(f(i)) # return fs # f1, f2, f3 = count() # print(f1(), f2(), f3()) # # def createCounter(): # s = [0] # def counter(): ...
6e2e7ad4551d535910d58bf7d5c970e32b73828c
Consultingcriminal/Vending_Machine
/client.py
7,829
3.53125
4
import pymongo class Vending_Machine: def __init__(self,db): self.my_db = db self.inventory = self.my_db["Inventory"] self.denominations = self.my_db["Denominations"] def vend(self): print("Welcome To The Vending Machine...") print("--- Currently Offering ---"...
5e3a27d7f44acfc40517e889015a6bc778855ade
EarthBeLost/Learning.Python
/Exercise 3: Numbers and Math.py
1,051
4.59375
5
# This is the 3rd exercise! # This is to demonstrate maths within Python. # This will print out the line "I will now count my chickens:" print "I will now count my chickens:" # These 2 lines will print out their lines and the result of the maths used. print "Hens", 25 + 30 / 6 print "Roosters", 100 - 25 * 3 % 4 # Th...
290c2e9467ee57f977b6a52f2306d49cce9566f8
eusholli/k-anonymity
/l-diversity.py
1,629
3.609375
4
import pandas as pd import numpy as np # new_master_df = pd.read_csv("passenger-trips.csv", dtype=str) new_master_df = pd.read_csv( "cleaned-trips.csv", dtype={"Sex": str}, parse_dates=["Pickup", "Dropoff", "DOB"], ) print(new_master_df.head(3)) new_master_df.info() print("Master Dataset size = ", len(new...
49aaf3a935a252a1b8a820716ea7e7dcc998cb30
kkzxak47/learn_python
/nt_iter.py
75
3.609375
4
x = 0.5 for i in range(100): x = (2*x**3+3)/(3*x**2+5) print(i, x)
5dc3ca4fee0ac6cbb08074cc9db82578aab8ff09
kkzxak47/learn_python
/plantsScore.py
2,296
3.515625
4
# coding: utf-8 import math def bestPlan(quantityList_orig, targetNum, composeNum): quantityList = quantityList_orig[:] length = len(quantityList) # print quantityList quantityListHistory = quantityList[:] for i in range(length-1): quantityList[i+1] += quantityList[i] / composeNum ...
10b176d846fa4b2306d5498f7644a0fe93ec6591
kkzxak47/learn_python
/circular_prime/loop_prime.py
1,098
3.875
4
# coding: utf-8 from math import sqrt, log10 def primes(n): """ Returns a set of primes < n """ sieve = [True] * n for i in xrange(3, int(sqrt(n)) + 1, 2): if sieve[i]: sieve[i * i::2 * i] = [False] * ((n - i * i - 1) / (2 * i) + 1) return set([2]) | set([i for i in xrange(3, n, 2...
292d1fe23077bb0443dc4347231882c5681fbb24
micro-irfan/BScRepo
/data_structure/stack.py
1,262
4.0625
4
class Stack(): def __init__(self, max_size): self.max_size = max_size self.items = [None] * max_size def push(self, item): if self.items[0] == None: self.items.remove(self.items[0]) self.items.append(item) if len(self.items) > self.max_size: print ('List has exceeded and ' + str(item) + '...
3838e7e75e062adeb376ecc566a0fbfdc3714707
stepangorbach/pstu
/2 Half/lab2.5.1.py
414
3.5625
4
f = open("assets/text.txt", 'r') word1 = str(f.read()) f.close() symbol = input("input your symbol: ") n = 0 for i in word1: if i == symbol: n += 1 print(word1) print("длинна текста: ", len(word1), "символов") print("количество повторений символа ", str("'") + str(symbol) + str("'") + str(":"), n) n = round...
9444cc7d857c9a6d779792ccd60dea44e8ae6111
stepangorbach/pstu
/2 Half/lab2.3.py
685
3.59375
4
def task1(symbol): n = 0 word = str("GNALSGKBJIPSBISDJBSNB") word2 = str("") word3 = word[0] print(word) word = word.replace(symbol,"") print(word) for i in range(len(word)): word2 += word[i]*2 print(word2) for i in range(len(word)): for j in range(len(word3)): ...
a3ee6737bc9880a213034cfc71ffd34b3f4d1215
JakeGads/Python-tests
/Prime.py
888
4.1875
4
""" Ask the user for a number and determine whether the number is prime or not. (For those who have forgotten, a prime number is a number that has no divisors.). You can (and should!) use your answer to Exercise 4 to help you. Take this opportunity to practice using functions, described below. """ def main(): run ...
895fcb183dee4c3bdc5f7ea8e45063f8f2d3dd4e
JakeGads/Python-tests
/Challenge.py
351
4
4
""" Given a string and a non-negative int n, return a larger string that is n copies of the original string. """ def Stringy(): string = input("What would you like to print") num = int(input("How many times do you want to print it")) string *= num return string def main(string): print(string) str...
04b820acd855321f00d16f7308c488a9818ccb15
WilliamTheCreator/CIS129-LAB4
/CIS129-WilliamBrown-Lab4-CODE.py
1,329
3.96875
4
#William Brown #Gregory Wagner #CIS129 #4/18/2017 print("Greetings, this program will give desired records for your rent slip information regarding tenants.") #Setting class class Apartment: def __init__(self, aPrice, aRentersName, aApartmentName): self.myPrice=aPrice self.myName=aRentersName ...
89077dd5e4daaac3dfe1cbaeeca1bd63b1d78476
Apoorva161998/learning_python_basics
/010_SortDictionary.py
294
4.03125
4
test_dict = {'gfg': [7, 6, 3], 'is': [2, 10, 3], 'best': [19, 4]} print("The original dictionary is : " + str(test_dict)) res = dict() for key in sorted(test_dict): res[key] = sorted(test_dict[key]) print("The sorted dictionary : " + str(res))
e168484863d576f93935dbf5910c4cf461785238
JordanDekker/ContainR
/app/core/containr/cluster_sequences.py
1,433
3.703125
4
import pandas as pd from Bio import Align from Bio.SubsMat import MatrixInfo from sklearn.cluster import KMeans def cluster_seq(main_df, prefix='', num_clusters=3): """Clusters the sequences to see similair sequences. Args: main_df: The whole pandas dataframe-subset that you want to visualise. ...
9d801833b9f7b6bfd3a10d5c31f8e68603ec8922
juliascript/Python-Challenges
/histogram.py
2,233
3.828125
4
import sys, operator, random, unicodedata def generateHistogramFromFile(textfile): # open text file f = open(textfile, 'r') # read the file fileContent = f.read() # fileContent = fileContent.encode('utf-8', 'ignore') # generate array from file content wordsArray = fileContent.strip().replace('\n', ' ').spli...
4db35a9f6013798b055d578dcc946722c522345d
betapleb/hangman-fun-game-haha
/games.py
3,066
3.90625
4
handle = open("Hangman.py") from random import * from Hangman import * seed() def letterInWord(x, y): indexes = [] for i in range(len(y)): if x == y[i]: indexes.append(i) return indexes class Game(): def __init__(self): self.listing = [] self.secretW...
e6a3862a1cdfea1e5f511e77725a78a85e450591
Monukushwaha/Python_Practice-
/third.py
145
3.765625
4
number=input("enter the number which you wants devisior :- ") list=[] i=1 while i<=number: if number % i==0: list.append(i) i=i+1 print list
0db1576cd8ad3d4fe868bf1b80c4014ba4065203
Monukushwaha/Python_Practice-
/conditional6.py
233
3.9375
4
num=(1,2,3,4,5,6,7,8,9,12,23) count=0 od_count=0 for i in num: if i%2==0: count=count+1 else: od_count=od_count+1 print("total even number in the series " + str(count)) print("total odd number in the series " + str(od_count))
d546a4375fabc0e79a9d7668e12a7d9de2606cc1
Monukushwaha/Python_Practice-
/conditional27.py
215
4.125
4
#Python program to print alphabet pattern 'T'. for i in range(1,8): for j in range(1,8): if (i>1 and (j==1 or j==2 or j==4 or j==5)): print(" ", end="") elif(i<8 and j<=5): print("*", end="") print()
b9c9aa57ee05db88ea9e96b6384bafb91090f188
Monukushwaha/Python_Practice-
/conditional10.py
140
3.84375
4
for i in range(1,50): if i%3 ==0 and i%5==0: print "FizzBuzz" elif i%3==0: print "Fizz" elif i%5==0: print "Buzz" else: print i
e90edc17792d845d68910d53768bbfa22c00bbf3
Monukushwaha/Python_Practice-
/conditional22.py
241
3.84375
4
for i in range(1,8): for j in range(1,8): if ((i==1 or i==2 or i==5 or i==6 or i==7) and (j==2 or j==3 or j==4)) or (i==3 and j==3) or (i==4 and (j==2 or j==4)): print(" ",end="") elif(i<8) and (j<6): print("*",end="") print()
4a153a5f8e233e1949e19bc85b3d59df4b0e02da
Monukushwaha/Python_Practice-
/conditional18.py
305
3.859375
4
for i in range(1,8): for j in range(1,8): if((j==5) and (i==1 or i==7)) or ((j==2 or j==3 or j==4) and (i==2 or i==3 or i==4 or i==5 or i==6 )): print(" ",end="") elif (j<=5) and (i==1 or i>1) : print("*",end="") print(" ")
80d694698b64bc186e077a107a0b8ef604e0da1c
Monukushwaha/Python_Practice-
/coditional2.py
328
4
4
celsius=int(raw_input("enter the temprature in celsius")) feh=int(raw_input("enter the temprature in fehrenhite ")) def conver(c,f): cel = (f-32)*5/9 print str(feh)+'farenhite converted to '+str(cel) + " degree celcius" F = c/5*9+32 print str(celsius)+ " degree celsius have "+ str(F) + " fehrenhite" conver(celsi...
20d1fdd7f784018a37d1e9da5667693db3c58293
nbagiyan/hseminor
/first term/homework/hw5/problem_A.py
243
3.65625
4
def max_index(lst): maxind = 0 for i in range(len(lst)): if lst[i] >= lst[maxind]: maxind = i return maxind lst = [int(x) for x in input().split()] maxind = max_index(lst) print(lst[maxind], maxind, sep = ' ')
0121d3ab7cd94954416003a65dcef56f1f1af6cb
nbagiyan/hseminor
/first term/seminars/sem7/problem_C.py
315
3.859375
4
from math import sqrt def distance(x1, y1, x2, y2): r = sqrt((x1-x2)**2 + (y1-y2)**2) return r x1 = int(input()) y1 = int(input()) x2 = int(input()) y2 = int(input()) x3 = int(input()) y3 = int(input()) p = distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3) print(round(p, 6))
f5b74035998a8e9f017e607593763280f36f1129
nbagiyan/hseminor
/first term/homework/hw5/problem_B.py
951
3.640625
4
def pairwise_product(lst): maxind1 = lst.index(max(lst)) maxind2 = -1 maxind3 = -1 minind1 = lst.index(min(lst)) minind2 = -1 if len(lst) > 3: for i in range(len(lst)): if (lst[maxind2] < lst[i] and maxind1 != i) or (maxind2 == -1 and maxind1 != i): maxind2 = ...
7b5c3684c724000624106ccebb11803e97cf001e
masilvasql/Network-Neural-With-Python
/perceptron2.py
398
3.59375
4
# -*- coding: utf-8 -*- """ Spyder Editor Este é um arquivo de script temporário. """ import numpy as np #biblioteca cientifica entradas = np.array([1, 7, 5]) pesos = np.array([0.8, 0.1, 0]) def soma(e,p): return e.dot(p) #dot product -> produto escalar s = soma(entradas, pesos) def stepFunction(...
6e8f2979c9f9ecdd118fc7882acdfb141ef2642d
green-fox-academy/wenjing-liu
/week-03/day-01/hospital-simulator/hospital.py
588
3.984375
4
from queue import Queue class Hospital: def __init__(self, queue): self.patient_queue = queue def add_patient(self, patient): self.patient_queue.add_patient(patient) def treat_next_patient(self): self.patient_queue.get_next_patient() ''' #### Hospital class Since you have *Queue* class and *Patient*...
54c8d3a2094f4f575acd6ea4ecac7a4dc1746ec8
green-fox-academy/wenjing-liu
/week-01/day-03/data_structure.py/product_db_2.py
1,472
4.53125
5
product_db = { 'milk': 200, 'eggs': 200, 'fish': 400, 'apples': 150, 'bread': 50, 'chicken': 550 } def search_db(db): print('Which products cost less than 201?') smaller_keys = [] for key, value in product_db.items(): if value < 201: smaller_keys.append(key) if smaller_keys: print(f...
fb5ab4b96ce5a55baad82f55246f6904fa0fefc7
green-fox-academy/wenjing-liu
/week-01/day-03/functions/sum.py
194
4
4
# Write a function called `sum` that returns the sum of numbers from zero to the given parameter def sum(num): total = 0 for i in range(num): total += i return total print(sum(20))
e398109fa0a7ef7ec0675f3c854d61d0e0466079
green-fox-academy/wenjing-liu
/week-03/day-01/bank-account/currency.py
1,200
3.96875
4
# import abc class Currency: def __init__(self, value, code, central_bank_name): self.value = value self.code = code self.central_bank_name = central_bank_name def add(self, amount): if amount >= 0: self.value += amount return self.value def sub(self, amount): if amount > 0 and amou...
c874fd86801315b98f608f9011a54ef8299a8b54
green-fox-academy/wenjing-liu
/week-01/day-05/matrix/matrix_rotation.py
952
4.1875
4
""" # Matrix rotation Create a program that can rotate a matrix by 90 degree. Extend your program to work with any multiplication of 90 degree. """ import math def rotate_matrix(matrix, degree): rotate_times = degree//90%4 print(rotate_times) for rotate_time in range(rotate_times): tmp_matrix = [] ...
75194eb550340de1c1ab9a31adc510fec7ef771b
green-fox-academy/wenjing-liu
/week-02/day-01/encapsulation-constructor/counter.py
947
4.125
4
class Counter: def __init__(self, num = 0): self.num = int(num) self._initial_num = self.num def add(self, number = 1): if isinstance(number, (int, float)): self.num += int(number) else: raise Exception('You must input number') def get(self): return self.num def reset(se...
511174a0fa5c03f97f12fffccd02a54c781929f6
green-fox-academy/wenjing-liu
/week-02/day-01/green-fox/sponsor.py
1,347
4
4
from person import Person class Sponsor(Person): def __init__(self, name = 'Jane Doe', age = 30, gender = 'female', company = 'Google'): super().__init__(name, age, gender) self.company = company self.hired_students = 0 def introduce(self): print(f'Hi, I\'m {self.name}, a {self.age} year old {se...
7974c71a874f39efe7ab59076d40798eef4c8d23
green-fox-academy/wenjing-liu
/week-05/day-04/external_libraries.py
3,475
3.75
4
def prettify_graph(graph): """Modify the given graph according to Jimmy's requests: add a title, make the y-axis start at 0, label the y-axis. (And, if you're feeling ambitious, format the tick marks as dollar amounts using the "$" symbol.) """ # Complete steps 2 and 3 here graph.set_title("Resu...
f7e246bf5899b68f6f4143a450501324141ab474
green-fox-academy/wenjing-liu
/week-01/day-02/variables/define_basic_info.py
249
4
4
# Define several things as a variable then print their values # Your name as a string # Your age as an integer # Your height in meters as a float # Whether you are married or not as a boolean name = 'Claire Liu' age = 18 height = 1.5 is_married = True
f9e03f63c9912c197beda92f1123780c7eac7446
green-fox-academy/wenjing-liu
/week-01/day-02/variables/bmi.py
157
3.53125
4
massInKg = 81.2 heightInM = 1.78 #Print the Body mass index (BMI) based on these values bmi = massInKg / (heightInM * heightInM) print(f'The BMI is {bmi}')
ae5c67125729bac8a457a9f5c7bf52d796259c56
green-fox-academy/wenjing-liu
/week-02/day-01/green-fox/mentor.py
1,008
4.09375
4
from person import Person class Mentor(Person): def __init__(self, name = 'Jane Doe', age = 30, gender = 'female', level = 'intermediate'): Person.__init__(self, name, age, gender) self.level = level def get_goal(self): print('Educate brilliant junior software developers.') def introduce(self): ...
12c1001a8ec9759c913683af89a5f8db183d87a7
green-fox-academy/wenjing-liu
/week-02/day-02/decryption/reversed_order.py
510
4.15625
4
# Create a method that decrypts reversed-order.txt def decrypt(file_name, result_file_name): try: with open(file_name, 'r') as source_file: with open(result_file_name, 'a') as result_file: line_list = source_file.readlines() result_file.write(''.join(reverse_order(line_list))) except Exce...
6f8fa5537d1c905be5afa97b890f334fb16fcd43
green-fox-academy/wenjing-liu
/week-01/day-02/loops/guess_the_number.py
634
4.21875
4
# Write a program that stores a number, and the user has to figure it out. # The user can input guesses, after each guess the program would tell one # of the following: # # The stored number is higher # The stried number is lower # You found the number: 8 magic_num = 5 print('Guess the number!') is_found = False whil...
db21cf81a6af83721977c2f7e4b92ebc203a36a7
green-fox-academy/wenjing-liu
/week-03/day-01/animal-protection/animal.py
1,126
4.09375
4
class Animal: def __init__(self, name = 'Animal', health_state = True, heal_cost = 0): self.name = name self.is_healthy = health_state self.heal_cost = heal_cost def heal(self): self.is_healthy = True def is_adoptable(self): return self.is_healthy def to_string(self): if self.is...
afa4fb4bf9720c18b1a94aca2f95488bba69b6f5
green-fox-academy/wenjing-liu
/week-01/day-05/matrix/main_anti_mirror.py
537
4
4
""" # Main anti-diagonal mirroring Create a program that can mirror the given matrix across the main anti-diagonal. """ def main_anti_mirror(matrix): if len(matrix) != len(matrix[0]): raise Exception('The input matrix is not square matrix.') for row in range(len(matrix)): for col in range(len(matrix[0]...
01e271b2fd0fbdd4b16f96d6171e294982bd0674
green-fox-academy/wenjing-liu
/week-01/day-05/matrix/transposition.py
465
4.15625
4
""" # Transposition Create a program that calculates the transposition of a matrix. """ def transposition_matrix(matrix): result = [] for col_num in range(len(matrix[0])): result.append([None]*len(matrix)) print(result) for row_num in range(len(result)): for col_num in range(len(result[row_num])): ...
29031610a8bc863cea296a89d3bc058715762bf3
green-fox-academy/wenjing-liu
/week-01/day-03/functions/bubble.py
575
4.34375
4
# Create a function that takes a list of numbers as parameter # Returns a list where the elements are sorted in ascending numerical order # Make a second boolean parameter, if it's `True` sort that list descending def bubble(arr): return sorted(arr) def advanced_bubble(arr, is_descending = False): sorted_a...
43e1d79557ba5c5adcd9f1a1cc41fa8b226aba64
green-fox-academy/wenjing-liu
/week-02/day-01/complex-architectures.py/petrol_station.py
1,155
3.65625
4
class Station: def __init__(self, gas_amount = 10000): self.gas_amount = gas_amount def refill(self, car, amount): self.gas_amount -= amount result = car.fill(amount) if result > 0: self.gas_amount += result class Car: def __init__(self, gas_amount = 0, capacity = 100): s...
bf77b3c695961043c8efb838a23b40fe150c7362
green-fox-academy/wenjing-liu
/week-05/day-03/string.py
429
4.09375
4
''' # Strings Given a string, compute recursively (no loops) a new string where all the lowercase 'x' chars have been changed to 'y' chars. ''' def replace_x_with_y(string): index = string.find('x') if index == -1: return string else: return string[:index] + 'y' + replace_x_with_y(string[index+1:]) s...
a807532a272e3de24249f69a33cd43ec5dec9ccb
green-fox-academy/wenjing-liu
/week-01/day-03/functions/unique.py
319
3.84375
4
# Create a function that takes a list of numbers as a parameter # Returns a list of numbers where every number in the list occurs only once def unique(arr): arr_set = set() arr_set.update(arr) return list(arr_set) # Example print(unique([1, 11, 34, 11, 52, 61, 1, 34])) # should print: `[1, 11, 34, 52, 61]`
8547a8beec07cffe3d47246adc2d22a53fdca6c5
zischuros/Introduction-To-Computer-Science-JPGITHUB1519
/Challenging Practice Problems/Elementary Cellular Automaton/Elementary Cellular Automaton.py
6,194
3.703125
4
# THREE GOLD STARS # Question 3-star: Elementary Cellular Automaton # Please see the video for additional explanation. # A one-dimensional cellular automata takes in a string, which in our # case, consists of the characters '.' and 'x', and changes it according # to some predetermined rules. The rules consid...
4058c8eece06486930ab5f6e69ee3fb16813f53c
zischuros/Introduction-To-Computer-Science-JPGITHUB1519
/Lesson 1 - How to get Started/String Find with numbers/str find with numbers.py
343
3.796875
4
#we can assing where we are going to begin to look for #<string>.find("<string>", <number>) number = begin s = "I like programming, I love programming, programming is the best..." print s.find("programming") print s.find("programming", 8) begin = 30 print s.find("programming", begin) print s....
c09d3eb3960978a8dd8b7a523e5b23478cab5def
zischuros/Introduction-To-Computer-Science-JPGITHUB1519
/Lesson 3 - Problem Set/Max Depth/reverse.py
44
3.640625
4
lista = [1,2,3,4,5] print lista.reverse()