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
9344f3b882eefda00e93a410640f18ad3c7dca3a
philipdongfei/Think-python-2nd
/Chapter13/analyze_book1.py
1,292
3.75
4
import string def process_file(filename): hist = dict() fp = open(filename) for line in fp: process_line(line, hist) return hist def process_line(line, hist): line = line.replace('-', ' ') for word in line.split(): word = word.strip(string.punctuation + string.whitespace) ...
a88986f44fa30ed06de4ab5076601567d60fbf2d
philipdongfei/Think-python-2nd
/Chapter13/analyze_book2.py
568
3.609375
4
from analyze_book1 import process_file import random def subtract(d1, d2): return set(d1) - set(d2) def random_word(h): t = [] for word, freq in h.items(): t.extend([word] * freq) return random.choice(t) def main(): hist = process_file('emma.txt') words = process_file('words.txt') ...
6b54c4208203b5267976a30e0e90c04174c82d60
philipdongfei/Think-python-2nd
/Chapter10/Ex10_11.py
343
3.96875
4
from Ex10_10 import in_bisect, make_word_list def reverse_pair(word_list, word): rev_word = word[::-1] return in_bisect(word_list, rev_word) def main(): word_list = make_word_list() for word in word_list: if reverse_pair(word_list, word): print(word, word[::-1]) if __name__ == '...
d96c37f39ad1fe8b94876b4d479d9982df2f40a1
philipdongfei/Think-python-2nd
/Chapter06/mycompare.py
189
4.03125
4
def compare(x, y): if x > y: return 1 elif x == y: return 0 else: return -1 x = int(input('Enter x: ')) y = int(input('Enter y: ')) print(compare(x,y))
5c0bc2491eb1d879bc01fcae07fb3daed170dc43
philipdongfei/Think-python-2nd
/Chapter05/Ex5_6.py
588
3.625
4
import turtle def koch(t, x): """ Draws a koch curve with length x. """ if x < 10: t.fd(x) return m = x / 3 koch(t, m) t.lt(60) koch(t, m) t.rt(120) koch(t, m) t.lt(60) koch(t, m) def snowflake(t, x): """ Draws a snowflake (a triangle with a k...
21f5d8b5fe0cf1dbd0042560e963638a26f6fb39
cloped/algorithms
/path-finding/astar.py
3,667
3.515625
4
# Visualization https://qiao.github.io/PathFinding.js/visual/ # Explanation https://www.geeksforgeeks.org/a-search-algorithm/ import sys from random import randint import math def getTargetMaze(randomPos): maze = [ ['.', '.', 'x', '.', '.', 'x'], ['x', '.', '.', 'x', '.', '.'], ['x', '.', '...
d8da7b03f746fc6a280d33bfe4c21914680fdd00
computerscienceioe/Lesson-8
/Challenge 8.py
231
4.03125
4
name = input("Enter your full name, separated by only a space: ") spaceIndex = name.index(" ") firstName = name[:spaceIndex] surname = name[spaceIndex+1:] print("Your first name is", firstName) print("Your surname is", surname)
6afe6f300db5e613ba33c79263d580328322e5d9
computerscienceioe/Lesson-8
/Challenge 4.py
255
3.96875
4
strings = [] for i in range(2): strings.append(input("Please enter a string: ")) for i in range(len(strings)): strings[i] = strings[i].lower() for i in range(len(strings)): print(len(strings[i])) print(strings[i][:2]) print(strings[i][-2:])
b9932d1ed3f81ba55aa4227ab7c03b525c998601
daiyeyue/Test
/Triangle.py
315
3.75
4
def triangle(n): ''' * * * * * * * * * * * * * * * :param n: 等边三角形的行数 :return: ''' if n <= 1: print("一行*无法成为等边三角形") else: for i in range(n,0,-1): print(" " * (i - 1) + "*" + " *" * (n-i)) triangle(20)
de9d39e3a538fff9bc03404a121cbf523ab6e2c0
and92reas/pyspark_tools
/source/Evaluation.py
3,489
3.640625
4
from . import * class Evaluation: ''' contains functions that are responsible for evaluate the predictions of a certain supervised machine learning model ''' def get_precision_of_label(label, labels, predictions): ''' returns the precision associated with the predictions of...
ee7f25aaa1473a38a3d1dd9a77261ce570045166
ggerogery/coursera-python-homework
/Extracting_Data_from_XML.py
864
3.921875
4
import xml.etree.ElementTree as ET import urllib import re ''' Extracting Data from XML In this assignment you will write a Python program somewhat similar to http://www.pythonlearn.com/code/geoxml.py. The program will prompt for a URL, read the XML data from that URL using urllib and then parse and extract the comm...
e769740ed4ab1fd7c608cb3cee0911d28ca986a0
sumeshp99/Hacktoberfest2k20
/Python/bubblesort.py
201
3.96875
4
def bubbleSort(arr): n = len(arr) for i in range(n-1): for j in range(n-i-1): if arr[j]>arr[j+1]: arr[j],arr[j+1] = arr[j+1],arr[j] a = [10,6,15,45,2 ,33] print(a) bubbleSort(a) print(a)
cdd9abb27a49f4ae4f0db3da56808656c9ab2e38
junge2018/mygithub
/sinaspider/for_test.py
286
3.5625
4
# -*- coding:utf-8 -*- a = [1,3] b = [4,7] def main(): for i in range(0,3): print '第%d次' % i hea() def hea(): for i in a: for j in b: c = i+j if c == 7: return print c main()
553b21ccb38330b16c42d385083c51b1ce78bdb9
gori-san/Atcoder
/until_July_2020_ABC/ABC_132/A-Fifty_Fifty.py
293
3.640625
4
s = input() ss = list(set([s[0], s[1], s[2], s[3]])) flag = True if len(ss) != 2: flag = False else: for i in range(len(ss)): if s.count(ss[i]) == 2: continue else: flag = False break if flag: print('Yes') else: print('No')
d5034574179f0aea863fa2a69e62b1f0e71754f5
webalorn/competitive_snippets
/snippets/python/algo/general/algo_merge_sort.py
372
3.53125
4
def merge_sort(seq): if len(seq)<2: return seq n = len(seq)//2 left, right = merge_sort(seq[:n]), merge_sort(seq[n:]) i, j, n, m, seq = 0, 0, len(left), len(right), [] while i < n and j < m: if left[i] < right[j]: # <Comparison> seq.append(left[i]) i += 1 else: seq.append(right[j]) j += 1 seq.ext...
315e47a3d80ac5835bb40dcc890b7bc924c08c1e
martyav/algoReview
/pythonSolutions/most_frequent_character.py
878
4.1875
4
# Frequency tables, frequency hashes, frequency dictionaries... # # Tomayto, tomahto, we're tracking a character alongside how many times it appears in a string. # # One small optimization is to update the most-frequently-seen character at the same time as # we update the dictionary. # # Otherwise, we'd have to write ...
07482b5f7f8b1ba25dbedc9a1f4398bb66ebd04a
SamuelNgundi/programming-challenges-with-python
/3.11. Book Club Points.py
1,264
4.21875
4
""" 11. Book Club Points Serendipity Booksellers has a book club that awards points to its customers based on the number of books purchased each month. The points are awarded as follows: - If a customer purchases 0 books, he or she earns 0 points - If a customer purchases 2 books, he or she earns 5 points - If a cust...
1c9b73ede9f9a71680b0285d498781be70a3b076
SamuelNgundi/programming-challenges-with-python
/2.4. Total Purchase.py
1,229
3.890625
4
""" 4. Total Purchase A customer in a store is purchasing five items. Write a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 7 percent. Reference: (1) Starting out with Python, Third Edition, Tony Gaddis (2) https...
bb5d1cdeede1ec0a878ad5ee0f023e331f75d2dd
SamuelNgundi/programming-challenges-with-python
/3.2. Areas of Rectangles.py
1,179
4.46875
4
""" 2. Areas of Rectangles The area of a rectangle is the rectangles length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same. Reference: (1) Starting out with Python, Third Editi...
afe32f4de9c73b431f8e20694a975a45ae993b34
SamuelNgundi/programming-challenges-with-python
/3.1. Day of the Week.py
1,136
4.46875
4
""" 1. Day of the Week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the u...
0b84527ca6bc8a1a48133fdc2faabab294d4eef6
truemanD/basic_dao_layer
/part03/db_functions.py
6,278
4.03125
4
import sqlite3 DB_NAME = '../sandbox.db' def get_connection(): """ The method to obtain the connection with the database and the cursor to operate with the database. In the method the connection uses a row factory to obtain records instead of tupples. Then this records are transform in list of dic...
18ae215b164a1bac149421c60eaa0b9ac7ad2d9c
MarcoFaccani/Autocomplete-Text
/Autocomplete-Text.py
2,664
3.640625
4
# Helper function def find_suffixes(node, output, word=""): # note: "and len(word)"" is needed so to not add an empty string when input is same as a single word if node is None or len(node.children) == 0 and len(word) > 0: output.append(word) return elif node.is_word and len(word) > 0:...
b1ff0a179282e419c43a226096b15b1afbf8d684
marlep-pi314/AdventOfCode2020
/12-01/aoc01.py
875
3.59375
4
global fn_calls f = open("input", "r") fn_calls = 0 lines = sorted( [int(l) for l in f.readlines()] ) f.close() index = len(lines)-1 def search_sum(left=0, right=index, total=2020): global fn_calls fn_calls += 1 if left==right: return False sum = lines[left] + lines[right] if sum == tot...
ed7ce6642999b51d2b3c1c0e8087a6f99c61b4e7
imurchie/projecteuler
/problem33.py
1,110
3.53125
4
#!/usr/bin/python # -*- coding: utf-8 -*- def isCuriousFraction(numerator, denomiator): for digit in str(numerator): if digit in str(denomiator): for i, j in [(i,j) for i in range(0,2) for j in range(0,2)]: if str(numerator)[i] == digit == str(denomiator)[j]: ...
e995d89bfbac35e1d4bce604314c173f4337e941
max180643/PSIT-IT
/Week-14/OTP.py
570
3.5
4
""" OTP Author : Chanwit Settavongsin """ def main(number): """ OTP Check """ while number != '0': number_count = [number.count(str(i)) for i in range(10)] if len(number) == 4 and number_count.count(2) == 1: print("Valid") elif len(number) == 6 and (number_count.count(2) == 2...
bfb7e4ddccd757dd11d0ac58246890f1582994f9
max180643/PSIT-IT
/Week-12/Safe.py
375
3.828125
4
""" Safe Author : Chanwit Settavongsin """ def main(display, password, answer): """ Counts the number of times the code is rotated. """ for i in range(len(display)): different = abs(ord(display[i]) - ord(password[i])) if different > 13: answer += 26 - different else: ...
017828d58bb0a2ca191f20ddee19d19d1415b948
max180643/PSIT-IT
/Week-2/Timing II.py
595
3.65625
4
""" Timing II Author : Chanwit Settavongsin """ def main(): """ Convert input number to day, hour, minute, second and check if day digit > 5 : print ("ERR_:__:__:__") else: print day, hour, minute, second """ second = int(input()) if second >= 0: minute, second = divmod(second,...
b2c5550b82bfc05ce8ebab1419e08f17334871d8
max180643/PSIT-IT
/Week-13/BreakPassword.py
330
3.5625
4
""" BreakPassword Author : Chanwit Settavongsin """ import hashlib def main(text): """ Hashing SHA512 """ for number in range(0, 100000): value = str("%05d" % (number)) hashing = hashlib.sha512(value.encode()) if str(hashing.hexdigest()).upper() == text: print(str("%05d" % (n...
b36b4c141bcabdc97dd89df3b1dcf93943fad199
max180643/PSIT-IT
/Week-6/Bill.py
473
3.53125
4
""" Bill Author : Chanwit Settavongsin """ def main(price, service, vat): """ find price + service + vat Service 10% of price if Service < 50: Service = 50 Service > 1000: Service = 1000 Vat 7% of price + service """ service = (price * 10)/100 if service < 50: service = 50...
3f906be52e2fe2629af5428f6aa652c8e582daef
max180643/PSIT-IT
/Week-7/RuleofThree.py
649
3.765625
4
""" RuleofThree Author : Chanwit Settavongsin """ def main(number, price_temp, weight_temp): """ find best value to buy snack """ avg_temp = weight_temp / price_temp for _ in range(number - 1): price = float(input()) weight = float(input()) avg = weight / price if avg == avg_...
bf4c1092c42c8100ed36481a860ad580fec1fb5f
max180643/PSIT-IT
/Week-10/PickThem.py
305
3.796875
4
""" PickThem Author : Chanwit Settavongsin """ import json def main(number, answer): """ find even number in list """ number = json.loads(number) _ = [answer.append(i) for i in number if i % 2 == 0] if len(answer) > 0: print(*answer, sep="\n") else: print("Nope") main(input(), [])
619389bad2bc36ffcd573fa9c1c25d7a1a405028
max180643/PSIT-IT
/Week-10/Difference.py
374
3.671875
4
""" Difference Author : Chanwit Settavongsin """ def main(set_a, set_b, member_a, member_b): """ Print member of set_a - set_b """ _ = [set_a.add(int(input())) for _ in range(member_a)] _ = [set_b.add(int(input())) for _ in range(member_b)] answer = [number for number in set_a - set_b] answer.sort()...
89c913f11c01d75aae573bfac11eae69a14937b0
max180643/PSIT-IT
/Week-11/VerticalHistogram 1.0.py
1,350
3.6875
4
""" VerticalHistogram Author : Chanwit Settavongsin """ def main(text, char_lower, char_upper, total_lower, total_upper): """ Print histogram of number's character """ answer_char, answer_total, answer = [], [], {} _ = [char_lower.append(i) for i in text if i not in char_lower and i.islower()] _ = [char...
233f5a3b48ac9d82722259fe1aef4787d50f3741
max180643/PSIT-IT
/Week-12/CaesarV1.py
610
3.84375
4
""" CaesarV1 Author : Chanwit Settavongsin """ def main(number, text, answer): """ Caesar Cipher decode """ for i in text: char = ord(i) char += number % 26 if i.isupper(): if char < ord("A"): char += 26 elif char > ord("Z"): char -...
a9c6d96cfe1a0e6b87816c3023465fc6efc2828d
max180643/PSIT-IT
/Week-9/Missing Numbers 1.0.py
428
3.546875
4
""" Missing Numbers Author : Chanwit Settavongsin """ def main(number, temp): """ find missing number from 1 to number """ check = [] value = [] for i in range(1, number + 1): check.append(i) while temp != 0: temp = int(input()) value.append(temp) for i in value: ...
0338b6e61050005cbfb3f8bb2f41992466d57143
max180643/PSIT-IT
/Week-2/FoodGrade I 2.0.py
325
3.703125
4
""" FoodGrade I Author : Chanwit Settavongsin """ def main(weight, total, count): """ Find number of chicken weight between 50 - 70 """ if count < 24: main(int(input()), total + (1 if 50 <= weight <= 70 else 0), count + 1) else: print(total + (1 if 50 <= weight <= 70 else 0)) main(i...
c4d76bf921cba72fec4175a2f569a8967079eed6
max180643/PSIT-IT
/Week-13/3nPlus1.py
495
3.78125
4
""" 3nPlus1 Author : Chanwit Settavongsin """ def main(answer): """ input value and value != 0 """ while True: number = int(input()) if number == 0: break else: answer.append(check(number, 1)) print(*answer, sep="\n") def check(number, total): """ Check n...
dc86bf231db78bf6b756519f29596b73e52f8e7e
max180643/PSIT-IT
/Week-7/FOR!F-Ball.py
615
3.875
4
""" FOR!F-Ball Author : Chanwit Settavongsin """ def main(text, position): """ Find the last position of the glass. """ for i in text: if i == "A" and position == 1: # A -> B position = 2 elif i == "C" and position == 1: # A -> C position = 3 elif i == "B" and pos...
4cab0feff0c4d54db9649f020795da0456a6552e
max180643/PSIT-IT
/Week-12/Gram_v1.py
338
3.953125
4
""" Gram_v1 Author : Chanwit Settavongsin """ def main(text, count): """ Find the most 2-gram """ word_list = [text[i:i+2] for i in range(len(text) - 1)] for word in word_list: if word_list.count(word) > count: answer = word count = word_list.count(word) print(answer, cou...
15a39945cd43f88446a2e36356f551328a4d6040
max180643/PSIT-IT
/Week-4/Inflation.py
273
3.765625
4
""" Inflation Author : Chanwit Settavongsin """ def main(price, year): """ Find Price in Future """ price = int(price * 100) for _ in range(year): price += int((price * 381) // 10000) print("%i.%02i" % (price//100, price%100)) main(float(input()), int(input()))
5147bce786c56071d7a08b39672afe92652c02f5
WoodlandGeoEng/DataScy
/GradingSystem.py
549
3.984375
4
# -*- coding: utf-8 -*- """ Created on Tue Apr 30 10:33:06 2019 @author: woodl """ #A program to grade scores that are input from the user newGrade = 0 sum = 0 for x in range(5): newGrade = (input('Enter grade between 0 and 20')) newGrade=int(newGrade) print('You entered ',newGrade) sum = sum +...
1256c2d4fc5644cf2ad6d5a27fb38dd8ec824c75
Edcorp844/Neural-Networks
/nueral_net2.py
1,877
3.6875
4
# Neural Network for solving XOR Problem # 1 1 --> 0 # 1 0 --> 1 # 0 1 --> 1 # 0 0 --> 0 import matplotlib.pyplot as plt import numpy as np # Activation function : sigmoid def sigmoid(x): return 1 / (1 + np.exp(-x)) # Sigmoid derivative for back propagation def sigmoid_deriv(x): return sigmoid(x...
a283b2f7608022684993f09fab3fcc49cfaf1d0e
enchoi/adventofcode
/day3.py
6,443
3.53125
4
# def the initial place class Wire: def __init__(self): self.x = 0 self.y = 0 self.wire = set() self.step = 0 self.step_location = {} def move(self, code): to = code[0] step = int(code[1:]) getattr(self, "to_{to}".format(to=to.lower()))(step) ...
cefdef2bbaa7fdb18608054f27718d8ed96ab2e6
Mahendra-Chouhan/image_accelerator
/Image_Segmentation/imgSegmentation_info.py
1,743
3.9375
4
""" @Author : TeJas.Lotankar """ import streamlit as st def get_info_segment(): st.header("Description:") st.info("Image segmentation is a commonly used technique in digital image processing and \ analysis to partition an image into multiple parts or regions, often based on the \ characteristics of the pixel...
d3ebe2fefeec1daac50257869a2b2525b82cb3df
LuciusK/algorithm011-class02
/Week_04/126.word-ladder-ii.py
5,464
3.515625
4
# # @lc app=leetcode id=126 lang=python3 # # [126] Word Ladder II # # @lc code=start from collections import defaultdict, deque from typing import List import string class Solution: def findLadders(self, beginWord: str, endWord: str, wordList: List[str]) -> List[List[str]]: word_set = set(wordList) ...
30c453c8b14dd6b5b147a27111649dac08eabe7c
LuciusK/algorithm011-class02
/Week_02/189.rotate-array.py
1,836
3.5625
4
# # @lc app=leetcode id=189 lang=python3 # # [189] Rotate Array # # @lc code=start class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ n = len(nums) k %= n for _ in range(k): nu...
7c3eef6b28c352a4941f644308fda1c46315dc98
LuciusK/algorithm011-class02
/Week_07/1091.shortest-path-in-binary-matrix.py
1,946
3.609375
4
# # @lc app=leetcode id=1091 lang=python3 # # [1091] Shortest Path in Binary Matrix # # @lc code=start class Solution: def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int: n = len(grid) if not gird or grid[0][0] == 1 or grid[n - 1][n - 1] == 1: return -1 elif n <= 2...
698b80d3efa440cfce0cd35ff76fdb8f5094a4db
dksshddl/DataStructuresWithPython
/Tree/MyBinaryTree.py
1,384
3.53125
4
class Node: def __init__(self, item, left, right): self.item = item self.left = left self.right = right class MyBinaryTree: def __init__(self): self.root = None def is_empty(self): return self.root is None def preorder(self, n): if n is not None: ...
28b032719465336a7c9d5ac0c030026091b54c42
ishansohony/LeetCode
/257. Binary Tree Paths.py
924
3.9375
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 binaryTreePaths(self, root): """ :type root: TreeNode :rtype: List[str] """ if root == None: ...
68abd278ddf44a6537d86a8fcc568ae13392635d
dadiletta/HelloWorld-PythonB
/ETQuiz.py
249
3.546875
4
import random students = [] def askStudents(): i = 0 con = "something" for con: con = input() students[i] = input("Enter a student name") i += 1 def makePairs(): for i in students: askStudents() makePairs()
07717668812d892cab316cb026d930e5274f126f
songkwangho/winter_vac
/HS_IntroducePython/plain.py
414
3.671875
4
# -*- coding: utf-8 -*- """ Created on Thu Dec 27 15:40:32 2018 @author: INHA """ plain = {'a':1, 'b':2, 'c':3} print(plain) from collections import OrderedDict fancy = dict() for key, value in plain.items(): fancy[key] = value fancy = OrderedDict(fancy) print(fancy) from collections import defaultdict dic...
8a5d6c2d4ab6cf294dca19dadfe08d77bb650d97
obick/basic_exercises
/for_dict_challenges.py
4,699
3.84375
4
from collections import Counter print('Задание 1\n') # Дан список учеников, нужно посчитать количество повторений каждого имени ученика # Пример вывода: # Вася: 1 # Маша: 2 # Петя: 2 students = [ {'first_name': 'Вася'}, {'first_name': 'Петя'}, {'first_name': 'Маша'}, {'first_name': 'Маша'}, {'first...
3d7d7c627eca834200203dc773eb4015e7bee134
adigreg/practiceprobs
/isroute.py
784
3.984375
4
#given a directed graph, design a function to determine if there is a path between two nodes def BFS(root,end,graph): nodeq = [] visited = [] nodeq.append(root) visited.append(root) while nodeq != []: n = nodeq.pop(0) if n == end: return True for child in graph[n]: if child not in visi...
32282d6155c30851d332f2b8ae5c2a395c4f3241
jin-hao-chen/pypytorch
/pypytorch/nn/functions/linear.py
518
3.5625
4
# -*- coding: utf-8 -*- import numpy as np from pypytorch.functions import Function class Linear(Function): def forward(self, a, b, c): return a @ b + c def backward_0(self, grad): a, b, c = self.inputs return grad @ b.T def backward_1(self, grad): a, b, c = self.i...
f1cd3dd83897d77c8829c6a1b46c391fe27427d7
abhijeetknayak/Algorithms
/Algorithms-1/heaps.py
889
3.90625
4
class heaps: def __init__(self): self.heap = [] def insert(self, k): self.heap.append(k) pos = len(self.heap) - 1 while pos > 0: parent_pos = (pos - 1) // 2 if self.heap[parent_pos] > self.heap[pos]: # Swap parent and child ...
9a4c9ce1689c571ec7659c4ea90b03b9e1909fab
abhijeetknayak/Algorithms
/Algorithms-1/inversions.py
1,320
3.609375
4
num = open('numbers.txt', 'r') lines = num.readlines() counter = 0 numbers = [] for line in lines: numbers.append(int(line)) counter = counter + 1 count = 0 def sort_and_count(a, n): global count if n == 1: return a elif n == 2: if a[0] > a[1]: temp = ...
7e1205f5489688438da50bb992c737eaaf9504fa
rickydhanota/Powerset_py
/powerset_med.py
1,006
4.15625
4
#Powerset #Write a function that takes in an array of unique integers and returns its powerset. #The powerset P(X) of a set X is the set of all the subsets of X. for example, the powerset of [1, 2] is [[], [1], [2], [1, 2]] #Note that the power sets do not need to be in any particular order #Array = [1, 2, 3] #[[], [...
9b010ff1877e1ef42db1fe2f8d630dff72b2c544
JakobHavtorn/algorithms-and-data-structures
/data_structures/stack.py
1,975
4.1875
4
class Stack(object): def __init__(self, max_size): """Initializes a Stack with a specified maximum size. A Stack incorporates the LIFO (Last In First Out) principle. Args: max_size (int): The maximum size of the Stack. """ assert type(max_size) is int and max_si...
95cf7203c3f7c9b9d4030c6a7ac157afd9230bf2
cosah/Project-Euler-SPOILERS
/prob1.py
98
4
4
sum = 0 for num in range(1000): if (num%3 is 0) or (num%5 is 0): sum += num print(sum)
f3c37ecf2134afd276545e868623b150dcf22d82
Vincent105/ML
/E02_python_data_science_handbook/02_Numpy/020201_basic_attribute.py
615
3.640625
4
import numpy as np ''' NumPy数组的属性 ''' np.random.seed(0) x1 = np.random.randint(10,size=6) x2 = np.random.randint(10,size=(3,4)) x3 = np.random.randint(10,size=(3,4,5)) print("一緯陣列") print(x1) print("二緯陣列") print(x2) print("三緯陣列") print(x3) print("x3 ndim-陣列的緯度:",x3.ndim) print("x3 shape-陣列的大小:",x3.shape) print("x3 ...
56c12c5cb844f25c9e05e8352c73b4a35905415a
Utkarsh016/fsdk2019
/day3/digit_letter_counter.py
634
3.828125
4
""" Code Challenge Name: Digit Letter Counter Filename: digit_letter_counter.py Problem Statement: Write a Python program that accepts a string from User and calculate the number of digits and letters. Hint: Store the letters and Digits as keys in the dictionary Input: Python 3.2 O...
9a1c1e12061cb7dae1dc8dfb1dfa140c833497ea
Utkarsh016/fsdk2019
/day2/pallendromic.py
256
3.921875
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 8 17:59:17 2019 @author: root """ list=[10,101,11011,122] for num1 in list: num=str(num1) b=num[::-1] if b==num: flag=true else: flag=false print(flag)
f57c0bd00593f49be3b507c3fcaee6b4e75ed403
Utkarsh016/fsdk2019
/day3/read_file.py
187
4.375
4
""" Challenge 3 Read the words from a file """ filename=input("Enter the name of the file") file_object= open(“filename.__path__”, “r”) for line in file_object: print(line)
eb5e861df88d12213d8baae82dab6ec9c7ef2f03
Utkarsh016/fsdk2019
/day 5/imgprocess.py
560
3.703125
4
# -*- coding: utf-8 -*- """ Created on Sat May 11 09:21:37 2019 @author: Tarun Joshi """ #Image Processing using PIL import os from PIL import Image str1=input("enter file name") try: img=Image.open(str1) img=img.convert(mode='L').save('a.jpg') img=Image.open("a.jpg") img=img.transpose(Image.ROTATE_2...
0cac7a90f5b2e66b12400a09cb98a0028eda2883
Utkarsh016/fsdk2019
/day4/code/latline.py
426
4.15625
4
""" Code Challenge Name: Last Line Filename: lastline.py Problem Statement: Ask the user for the name of a text file. Display the final line of that file. Think of ways in which you can solve this problem, and how it might relate to your daily work with Python. """ file_name=input("ent...
19c61a5c4411c1f50679cfd82b3817e9dbded021
lvhanh270597/correct_vietnamese_sentence
/vicorrect/datastructures/specialdict.py
421
3.703125
4
class SpecialDict(): def __init__(self): self.d = dict() def add(self, key, value=1): if key not in self.d: self.d[key] = value return True else: self.d[key] += value return False def set(self, key, value=0): self.d[key] = value def len(self): return len(self.d) def get(self, key): if ke...
fe4257918eceda15ac359290335a8f3fbb89c12b
vitbelik/Python_
/classes.py
385
3.515625
4
#encoding = 'utf-8' class Summation: def __init__(self, a, b): self.a = a self.b = b self.list_ = [] def summ(self): return self.a + self.b def cr_dict(self): self.list_.append([self.a, self.b]) return self.list_ def return_list(self): print...
d1b9968f5d4a24480ecc78be69d1d82c1ee001aa
lcharleux/turbo_turtle
/turboTurtle/classe.py
310
3.5625
4
class Parser: def __init__(self, sep): self.sep = sep self.parsed_line = [] def parse(self, line): self.parsed_line = [i.strip() for i in line.split(self.sep) if i.strip().isdigit()] def __str__(self): return ' '.join(self.parsed_line)
284acf0a8fa6b6e34efb5cd76a3f7e651f1f1e37
maginist/Snow-Crash
/level09/Ressources/decrypt.py
311
3.75
4
# coding: utf-8 import argparse if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("str", help="file to decrypt") args = parser.parse_args() args.str = args.str.encode("utf-8", "surrogateescape") for i in range(len(args.str)): print(chr(args.str[i] - i), end="") print()
a618c019c1837bb7b2dd6d9e17e2d7d5f11a1691
Intangible-pg18/KnowledgeBank
/programming_notes/Python/18_PySpark.py
16,133
4.59375
5
# Intro to Spark ------------------------------------------------------------------------------------------------------- # Spark is a platform for cluster computing. Spark lets you spread data and computations over clusters with multiple # nodes (think of each node as a separate computer). Splitting up your data makes...
9944725f07c02f76ddfcc781f03a81970b0264a2
Intangible-pg18/KnowledgeBank
/programming_notes/Python/flask/test_flask.py
808
3.78125
4
from flask import Flask # Create an instance of the Flask class and pass in the "name" variable (which is filled by Python itself). # This variable will be "main", if this file is being directly run through Python as a script. If you imported the file # instead, the value of "name" would be the name of the file which ...
1bd3d7a98a5008c7d9ffe205143bf86d335dddf4
Nephasis/euler_python
/problem7.py
268
3.578125
4
a = 2 b = 30 primes = [] i = 2 lgth = 0 # for i in range(a, b): while i >= 2 and lgth < 10001: for z in range(2, i): if (i % z) == 0 or i == 1: break else: lgth += 1 print (i, 'is prime and it is', lgth, 'prime') i += 1
7cbd357fc52fa195c9328595cecb9b4885a2ac49
erdemgencoglu/Kriptoloji-dersi-projesi
/karmasiklastir.py
2,393
3.609375
4
# -*- coding: utf-8 -*- # Karmasiklastirmada Rail fence algoritmasini kullandim. # Cit uzunlugunu 3 sectim.Normalde yukaridan asagiya dogru yazilir. # Burada zigzag deseninde olusturucaz def main(): # dosyadan okuyup dosyaya yazma islemi with open("girdi.txt", "r") as fileRead: with open("cikti.txt", "...
e5a23142c19ef32b8bd5afc36370fc733be83284
gagande90/Simple-Gui-Programs-Python
/Simple/2_adding_widgets.py
789
4.34375
4
import tkinter as tk # alias tkinter as "tk" from tkinter import ttk # ttk == "themed tk" gui = tk.Tk() # create Tk() instance and assign to variable ttk.Label(gui, text="Hello Label").\ ...
ecaab41e4abeb0f02741eac8cf6781d77160ee74
sjstalin/Secure_Password-Using-Lambda-function
/main.py
688
3.71875
4
'''Python Programming Lab4- Lambda Functions. Joshua Stalin S 2147118 04/09/2021''' import pass_test as pt i = 0 while i == 0: password = input("\t\t\t\t\t\t\tEnter the password: ") if pt.pass_test(password) < 8: print("\t\t\t\t\t\t\tPassword is too short\n") if pt.pass_strength(password...
ecc15d256abdfeb022efc8d72b267b370b3f231c
hunterlougheed/project
/hunter.py
311
3.921875
4
for x in range (0,14): print (x) for x in range (11,0, -1): print (x) for x in range(100,600,27): print(x) y = int(input("please input number")) for x in range(0, y): print("are we there yet") y = 0 for x in range (0,5): y = y+int(input("please input number")) print(x) print(y/5)
473e0f461700ca07acb148c5d45ff767542b3d55
Arthur-Lucifer/Python
/控制.py
1,002
3.59375
4
arr_old = [10 , 23 , 35 , 46 , 57 , 68 , 79 , 80 , 92 , 103 ] print("原始数组是:") print(arr_old) arr = int(input("请输入一个新的数:")) ind = 0 ans = arr_old.copy() for i in range(0,len(arr_old)): if arr < arr_old [i]: ans.insert(i,arr) break print("插入新数后的数组是:") print(ans) # num=input("请输入一个 5 位的数:") # num2 = n...
426f9857430fcd4b2c54ea9fb40b15c568b56529
sagarwal08/Taylor-Series-Expansion
/Taylor Series Visualization for Cosine Function.py
589
4.03125
4
#!/usr/bin/env python # coding: utf-8 # In[ ]: import numpy as np import matplotlib.pyplot as plt import math def fact(n): if n==0: return 1 else: return n*fact(n-1) # Taylor series for cosine function x = np.arange(-5*math.pi, 5*math.pi, 0.0001) y1 = np.cos(x) k = int(input('Enter th...
a6f1e8c1e027a47c15cd3560c93a6078f79810d3
nakayumc0278/NetworkProgramming_1
/renlist01.py
1,068
3.84375
4
#renlist01.py #coding: utf-8 #area1の値追加 area1 = [] print("area1の入力") area1.append(int(input("1つめの値を入力"))) area1.append(int(input("2つめの値を入力"))) area1.append(int(input("3つめの値を入力"))) print("現在のarea1の状態",area1) #area2の値追加 area2 = [] print("area2の入力") area2.append(int(input("1つめの値を入力"))) area2.append(int(input("2つめの値を入力")...
78c6903fe9a1d87115fb6f9435d7b857a153f8f2
nakayumc0278/NetworkProgramming_1
/renfunc02.py
608
3.65625
4
#renfunc02.py #coding: utf-8 def vote(): vote_num = 0 print("投票開始") val = 0 while True: vote_num = int(input("選択してください(1-投票 2-票数 0-箱を空 9-終了)")) if vote_num == 1: val +=1 print("投票します") elif vote_num == 2: print("票の数は",val) elif vote_nu...
f5256512e1439650f75c52ebe391e1480434859b
nakayumc0278/NetworkProgramming_1
/sample36.py
579
4.09375
4
#sample36.py #coding: utf-8 city = {"東京","名古屋","京都","大阪","福岡"} print("現在のデータは",city) k = input("追加するデータを入力してください") if k in city: print(k,"のデータは既に存在しています") else: city.add(k) print(k,"を追加しました") print("現在のデータは",city) k = input("削除するデータを入力してください") if k in city: city.remove(k) print(k,"を削除しました") else:...
3eeb1bdd49cf84d793e632f1987d8b34e631ff00
AalauraaA/Speciale
/Python_kode/GradientDescent.py
4,387
3.78125
4
# -*- coding: utf-8 -*- """ Created on Sun Mar 1 18:31:16 2020 @author: Laura URL: https://towardsdatascience.com/gradient-descent-in-python-a0d07285742f """ import numpy as np import matplotlib.pyplot as plt import data_generation #x = 2 * np.random.rand(100,1) # Gaussian Noise #y = 4 + 3 * x + np.rando...
f79a626a65a108f0c93511b153f336c5e3977e1e
salamaa21-meet/meet2019y1lab6
/turtlecooldesign.py
313
3.515625
4
import turtle turtle.tracer(1) rounds = 10 size = 10 mike = turtle.clone() steve = turtle.clone() turtle.bgcolor("white") turtle.hideturtle() mike.color("gold") steve.color("blue") steve.goto(5,5) while True: mike.forward(size) mike.left(90) steve.forward(-size) steve.left(-90) size += 10 turtle.mainloop()
926c38e3185562329c135c8287aba17284ca32e9
beshup/leetcode
/98/sol.py
807
3.796875
4
# 98. Validate Binary Search Tree # https://leetcode.com/problems/validate-binary-search-tree/ class Node(object): def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution(object): def isValidBST(self, root): """ ...
f089ef0e6f38a641390eb7a2da05510301a40c4d
desaid64/ProgLang
/ProgLangChallenge/Python/driver.py
1,514
4
4
import csv fileName = '../Input/input3.csv' def readInput(fileName): with open(fileName, 'r') as csvfile: readCSV = csv.reader(csvfile,delimiter=',') rows = [] for row in readCSV: rows.append(row) return rows[0],rows[1:] def calculateNamesAndScores(voter,Candidates): ...
058652937d9f9746b9903ad94d502c648a49a0cc
123p10/Programming-Projects
/Python and Web/Hangman/Hangman.py
416
3.640625
4
TotalPoints = 0 Life = 5 LettersGuessed = "" Answer = raw_input(' Well now Player 1 what is your choice ') AnswerNum = len(Answer) print 'Player 2 it is a',AnswerNum,'letter word including spaces.' print 'Now Guess' Guess = raw_input(' Now choose a letter ') if Guess in Answer: TotalPoints += 1 newAnswer = Answer.re...
0a0d6fbe5826c8a3bbbd47a7efbadb77af450374
kharyal/leetcode
/product_except_self/product_except_self.py
771
3.9375
4
from copy import deepcopy class Solution(object): def productExceptSelf(self, nums): """ :type nums: List[int] :rtype: List[int] """ p1 = deepcopy(nums) p2 = deepcopy(nums) for i in range(1,len(nums)): p1[i] = p1[i-1]*nums[i] p2[0...
6b5c3f5368865cc5ab5ad11dbd3b21b80f810a43
kharyal/leetcode
/rotated_binary_search/rotated_bin_search.py
1,797
3.5
4
class Solution(object): def binary_search(self, arr, num, start, end): if len(arr)==0: return -1 if end == start and arr[start]==num: return start elif end == start: return -1 if end<start: return -1 mid = (start+en...
37069c7259a0332adb8190346866d31af770627f
kharyal/leetcode
/max_subarray/max_sum_subarray.py
738
3.65625
4
from copy import deepcopy class Solution(object): def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ max_sum = 0 max_ending_here = 0 for i in range(len(nums)): max_ending_here = max_ending_here + nums[i] ...
72bbba98c41b9ce73cf97c5ca4aa0357014bd550
kharyal/leetcode
/3sum/3sumSoln.py
772
3.578125
4
def threeSum(nums): """ :type nums: List[int] :rtype: List[List[int]] """ nums = sorted(nums) ret = [] k = len(nums)-1 while k > 0: num = nums[k] i = 0; j = k-1 while i<j: if nums[i]+nums[j] > -num: j = j-1 elif nums[i]+nums...
b5457f046da0c39259b0289b1987d8e85af87066
kharyal/leetcode
/reverse_tree/tem.py
1,315
3.890625
4
class node(): def __init__(self, num): self.num = num self.left = None self.right = None def dfs(self, _node, target_node): if _node == None: return False if _node.num == target_node: return True r1 = False; r2 = False ...
1bc14cdb6ad30a131a56e6046c06f883ac9c624d
killstyles/my_love
/7-13/test1.py
269
3.734375
4
# a-->A A-->a others = '' user = input('please input somethings:') for i in user: if ord('a') <= ord(i) <= ord('z'): others += chr(ord(i)-32) elif ord('A') <= ord(i) <= ord('Z'): others += chr(ord(i)+32) else: others += i print(others) #print(user.swapcase())
6fc3e0ebab17273863874b99118bde3c7f7bf2a7
killstyles/my_love
/7-17/mytask3.py
122
3.5625
4
# 9 * 9 for i in range(1,10): for j in range(1,i + 1): print('{} * {} = {:2.0f}'.format(i,j,i * j),end = ' ') print()
441c5120a2000aa2ffdb8721c8b6ac6c0cce0303
killstyles/my_love
/7-17/mytask5.py
82
3.5
4
def fact(n): if n == 1: return 1 return (fact(n - 1) + 1) * 2 print(fact(11))
38d029b33508d77bfe12181a91e3ec1a14e14e18
lumafragoso/Loops_Desenho_Escala
/main.py
619
3.6875
4
import turtle t = turtle.Turtle() valor = int(input('Digite um valor para o lado do triângulo: ')) for i in range(5): if i >= 1: # escolhi a escala de 5 t.pendown() t.left(60) t.forward(valor * 5 * i) for j in range(2) : t.right(120) t.forward(valor * ...
48c895854171036db0edca9dc6f4e8ffe9745837
Harguna/Python
/classes.py
768
4.0625
4
""" class Boy: gender = "male" def __init__(self): print("Inside Boy Block") def eats(self): self.food = "burger" print("I ate",self.food) """ #a =Boy() #a.eats() #a.eats() class Car(): tyres = 4 windows = 6 name = 'pqr' #def __init__(self): ...
4ae14d3387204ba8fefca0e5644173c9236f6d85
Harguna/Python
/max_no.py
344
4.0625
4
num= int(input("Enter total number of elements: ")) arr= [] for i in range(0,num): arr.append(int(input("Enter element number %d: " %(i+1)))) #arr.sort() # or def max_no(arr): for i in range(0,num-1): if arr[i]>arr[i+1]: temp=arr[i] arr[i]=arr[i+1] arr[i+1]=temp print("Maximum value is...
1afcc2281ee5a21f3fc4b7327582d5fb96dd4dcb
Harguna/Python
/calc.py
1,335
4.21875
4
print("Press: 1 for even-odd ") print("Press: 2 for prime number ") print("Press: 3 for factorial ") print("Press: 4 for average ") print("\n") opt= int( input ("Enter your option: ")) def even_odd(num1): if num1==0: print("Number is neither even nor odd") if num1%2==0: print("Number is even") e...
ec6882cda7fa37f5c84a90e67f294eb82b2ddbdc
Harguna/Python
/rev_no.py
330
3.609375
4
num= int( input("Enter a number: ")) def rev_no(num): temp= num count=1 while (temp//10) != 0: temp= int(temp/10) count= count + 1 temp= num rev=0 for i in range(0,count): temp2= divmod(temp,10) temp= temp2[0] rem= temp2[1] rev= rev+(10**(count-i-1))*rem print(str(rev)) rev...
49ea236a9410aab9edcb0ee95325c3127465c252
abdullahwaqar/house_price_predictor
/visualize/plot.py
497
3.59375
4
import numpy as np import matplotlib.pyplot as plt def plot_predictions(actual, prediction, title='Sales Price vs Prediction', y_label='Price USD', x_label='Number of Samples'): fig = plt.figure() ax = fig.add_subplot(111) #* Add labels plt.ylabel(y_label) plt.xlabel(x_label) plt.plot(actual,...