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
16a1f392386632e3a208ee371b8dd7343b7736cb
rushirg/practice-problems
/GeeksforGeeks/Placement-Preparation-Course/Mathematics/Problems/digits-in-factorial.py
340
3.546875
4
""" Digits In Factorial https://practice.geeksforgeeks.org/problems/digits-in-factorial/1/?track=ppc-mathematics&batchId=221 """ ## Complete this function def digitsInFactorial(N): # Your code here if N == 0 or N == 1: return 1 fact = 1 for i in range(1, N + 1): fact = fact * i ret...
3f224b45e198e248d90be7c07c912f00a34eda6c
angelosalatino/cso-classifier
/cso_classifier/syntacticmodule.py
6,671
3.578125
4
from nltk import ngrams from nltk.tokenize import word_tokenize from rapidfuzz.distance import Levenshtein class Syntactic: """ A simple abstraction layer for using the Syntactic module of the CSO classifier """ def __init__(self, cso = None, paper = None): """Function that initialises an object of c...
4a0989e726ccdea9ec4b69028dd3f5b1c5e54312
ccchao/2018Spring
/Software Engineering/hw1/good.py
858
4.34375
4
""" 1. pick a list of 100 random integers in the range -500 to 500 2. find the largest and smallest values in the list 3. find the second-largest and second-smallest values in the list 4. calculate the median value of the elements in the list """ import random #Generate a list containing 100 randomly generated intege...
bcaef426e752fde98f9f1427f1297af8c7cdcb31
ccchao/2018Spring
/Software Engineering/warmup/codecheck.py
1,504
3.984375
4
""" File name: codecheck.py Students: Junxiao Chen Deadline: Thursday, Feb. 15th Warm-up Project Simulation of the board game Mastermind """ def random_code(random_times = 4, random_limit = 5): """ :type random_times: int :type random_limit: int :rtype answer_code: list """ answer_code = [] ...
71c4e46a03be6e8be0793a8f638b58945859a732
ccchao/2018Spring
/Software Engineering/warmup/computerguess.py
6,453
4.15625
4
""" File name: computerguess.py Students: Junxiao Chen Deadline: Thursday, Feb. 15th Warm-up Project Simulation of the board game Mastermind """ from codecheck import code_check import datetime import json colorToNum = {'R': 0, 'RED': 0, '0': 0, 'B': 1, 'BLUE': 1, '1': 1, 'P'...
428dfd9dc8b082c3200c42cc0733dad29ab962e3
pumalcn/BFDjango
/week1/Hackerrank/swap_case.py
336
3.890625
4
def swap_case(s): res = '' for i in s: n = ord(i) if n >= 65 and n <= 90: res += i.lower() elif n >= 97 and n <= 122: res += i.upper() else: res += i return res if __name__ == '__main__': s = raw_input() result = swap_case(s) ...
4864229bf26fd6efb47ac44a08bee2c1ab473cf6
ppbox/leetcode_solutions
/0033_Search_in_Rotated_Sorted_Array/Solution1.py
1,112
3.875
4
from typing import List class Solution: def search(self, nums: List[int], target: int) -> int: left = 0 right = len(nums) - 1 while left <= right: mid = left + (right - left) // 2 if nums[mid] == target: return mid if nums[left] <= nums[mi...
bd0d3a2a3a553a25cfae6681f44a160a5518b450
ppbox/leetcode_solutions
/0001_Two_Sum/Solution1.py
708
3.609375
4
from typing import List class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: d = dict() for idx, num in enumerate(nums): num_to_find = target - num if num_to_find in d.keys(): return [idx, d[num_to_find]] d[num] = idx def ...
44cf7e71d1322138d0c89fa3a358669b4221a4e8
j4anderson/gitplayground
/Envs/Rpi/Python_Projects/binclock3.py
6,103
3.703125
4
#!/usr/bin/python3.2 # # binclock3.py # # Gets the system time and displays it in binary format # This version also shows a standard clock at the bottom # import import time # Get the system time: thetime=time.strftime("%H%M%S") #Now try to display it in a graphical way import sys, pygame pygame.init() # display d...
4258974c75ff3ee066c972ad433990354c34478a
finiteautomata/contrastes
/contrastes/information_value.py
1,349
3.578125
4
#! coding: utf-8 """Helpers para las notebooks de Information Value.""" import nltk import json import random import numpy as np from scipy.stats import entropy from nltk.corpus import stopwords, gutenberg from numpy.random import multinomial from nltk import word_tokenize def shuffle(balls, bins): """ Retur...
1d57f022a51cc2ac59d092b029a27e38c4eda60c
nyu-cds/mch529_assignment3
/mandelbrot_gpu.py
2,701
3.765625
4
# # Simple Python program to calculate elements in the Mandelbrot set. # import numpy as np from numba import cuda from pylab import imshow, show import math xvals =[] @cuda.jit(device=True) def mandel(x, y, max_iters): ''' Given the real and imaginary parts of a complex number, determine if it is...
91a23fd6ec43d3e901fa3a57984ad9e3e72c858e
masko101/ml-with-py-and-r
/Part 2 - Regression/Section 6 - Polynomial Regression/Python/polynomial_regression_mine.py
1,708
3.578125
4
import numpy as np import pandas as pd import matplotlib.pyplot as plt dataset = pd.read_csv("Position_Salaries.csv") X = dataset.iloc[:, 1:-1].values y = dataset.iloc[:, -1].values from sklearn.linear_model import LinearRegression lin_reg = LinearRegression() lin_reg.fit(X, y) from sklearn.preprocessing import Pol...
b69e56d6b5e3a15ef09392a3b7480dbea473c247
anand102/GUI
/GUI/tkinter/4.pushbutton1.py
589
3.875
4
# Creating a working push button def display(event): print("Hey, You Clikced the button") from tkinter import * root=Tk() root.geometry('750x500') root.title("Push Button inside Frame") f=Frame(root, height=300, width=400, bg="lightblue") f.propagate(0) f.pack() b=Button(f, text="Click Me!", width=20, height=2...
1a5decdca960e40d6c0bd1939d4461176a7fee70
parastooveisi/CtCI-6th-Edition-Python
/Linked Lists/palindrome.py
1,202
4.1875
4
# Implement a function to check if a linked list is a palindrome class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def printList(self): curr = self.head while curr: print(cur...
5a66ebded3dc052fd815e775c2ec404ab29668ab
parastooveisi/CtCI-6th-Edition-Python
/Trees and Graphs/validate_BST.py
586
3.75
4
class Node: def __init__(self, data): self.data = data self.left = None self.right = None def validate_BST(node, prev=None): if not node: return True if not validate_BST(node.left, prev): return False if prev and prev >= node.data: return False pr...
6721b297d1b77c9f18760cc1d6cf7b87d5036a1b
parastooveisi/CtCI-6th-Edition-Python
/Stack/stack_of_plates.py
789
3.65625
4
class setOfStacks: def __init__(self, capacity): self.capacity = capacity self.stacks = [[]] def push(self, value): if len(self.stacks[-1]) == 0 or len(self.stacks[-1]) < self.capacity: self.stacks[-1].append(value) else: self.stacks.append([value]) ...
7cc709ace8f52fc0077fbd9f1a73f25907a2c974
parastooveisi/CtCI-6th-Edition-Python
/Stack/reverseStr.py
245
3.609375
4
from stack import Stack def reverseStr(inputStr): s = Stack() result = "" for char in inputStr: s.push(char) while not s.isEmpty(): last = s.pop() result += last print(result) reverseStr("hello")
28d9e4f8593aad49f91e29b3793e7a52f9fe9314
parastooveisi/CtCI-6th-Edition-Python
/Trees and Graphs/is_balanced.py
738
3.8125
4
class Node: def __init__(self, data): self.data = data self.left = None self.right = None def is_balanced(node): if node is None: return 0 left_height = is_balanced(node.left) if left_height == "NOT BALANCED": return "NOT BALANCED" right_height = is_balanced...
83c1d1c375b3e9da9cdcbee1e1db474501bbb3a8
parastooveisi/CtCI-6th-Edition-Python
/Trees and Graphs/route_between_nodes.py
628
3.9375
4
def is_route(graph, start, end, visited): for node in graph[start]: if node not in visited: visited.append(node) if node == end or is_route(graph, node, end, visited): return True return False graph = { "A": ["B", "C"], "B": ["D"], "C": ["D", "E"], ...
a553504e445bc6465aa218200b44f3a6dbbeac2d
TaumarT/Sistema_Tkinter_Sqlite3
/Tela_de_Login.py
725
3.65625
4
#Tela_de_Login.py from tkinter import * janela = Tk() janela.title("Sistema Loja") def logar(): login = ed1.get() senha = ed2.get() if (login == "taian") and (senha == "taumar"): import menu #menu.Tela_de_Login() else: lb["text"] = "Valores Invalidos" lb1 = La...
47522cafdf70f29dc4716a423bf75128a5710945
CaveSheep/Backup
/check.py
1,020
3.90625
4
# Review # Teylon Pace # Period 1 myVar = "hello" myNum = 5 x = 10 while x > 0: print(x) x = x - 1 Teylon = 100 while Teylon > 0: print("Teylon") Teylon = Teylon - 1 name = "Teylon" print("Hello " + name) movie = "Cargo" print("My favorite movie is " + movie) myName = input("What is...
c24b3966ebfbcad86cd8b9523fe4836e3349abc1
BilalAli181999/Task1
/question1sol.py
152
4.09375
4
def result(n): sum=0 for i in range(3): sum+=n**(i+1) return sum n=int(input("Enter a number: ")) print(result(n))
afd1ad16c3bf0a6faa039052468a61d1b37fbcf3
dhananjaykaushik/AI_ML
/Stanford CS221: AI/Lecture 1/GradientDescent.py
396
3.75
4
points = [(2, 4), (4, 2)] def F(w): return sum((w * x - y) ** 2 for x, y in points) def dF(w): # Calculating derivative return sum(2 * (w * x - y) * x for x, y in points) # Gradient Descent w = 0 eta = 0.01 # Step size for t in range(100): value = F(w) gradient = dF(w) w = w - (eta * ...
dcc6441b4f35dbf2962552d305fd7212c561ae3b
Brody-Liston/Pracs-by-Brody-Liston
/Prac 5/Colours.py
783
4.28125
4
hex_colour = {"f0f8ff": "AliceBlue", "f5f5dc": "Beige", "000000": "Black", "ffebcd": "BlanchedAlmond", "8a2be2": "BlueViolet", "5f9ea0": "CadetBlue", "d2691e": "Chocolate", "ff7f50": "Coral", "6495ed": "CornflowerBlue", "b8860b": "DarkGoldenrod"} def main(): hexadecimal = input(...
d27472a80fda6909ec7e3838ce0892e3e4c2920f
matitaweb/mumet2017_deep_learning
/tensorflow_01_neural_nets/lab_utils.py
2,168
3.5625
4
import csv import numpy as np from tensorflow.examples.tutorials.mnist import input_data EPS = np.finfo('float32').eps def get_mnist_data(download_data_path, one_hot=True, verbose=False): """ Parameters ---------- download_data_path : string Directory where MNIST data are downloaded and...
77bb845e520339ae6007f857bacc24094cd6e579
marckraw/python_eduweb_learning
/skijumpers.py
1,014
3.828125
4
ski_jumpers = [ { "Ryoyo Kubayashi": "Jpn" }, { "piotr zytla": "PL" }, { "Robert johanson": "NOR" }, { "someone": "NOR" }, { "Kamil Stoch": "PL" }, { "Jakis ziomek": "PL" } ] # for loop for jumper in ski_jumpers: print(...
fa91483627088436939881d74ef7d06aecbebcf6
ash/python-tut
/59.py
225
4.0625
4
# n! = 1 * 2 * 3 * ... (n - 1) * n # n! = (n - 1)! * n def factorial(n): print("calling a function with argument " + str(n)) if n <= 1: return 1 f = factorial(n - 1) * n return f print(factorial(5))
a6ba104cebd23e52565485acf39baccfabca3d95
ash/python-tut
/reference/14-class.py
391
3.96875
4
class Person: '''Represents a person''' def __init__(self, name, age = 19): self.name = name self.age = age def say(self): print('My name is %s, I am %i years old.' % (self.name, self.age)) p1 = Person('John', 20) p2 = Person('Jessica') p1.say() p2.say() print(p1) print(p...
340331b14bf41f5506910c933de17cd72a9d510c
ash/python-tut
/reference/51-yield.py
209
3.828125
4
def f(): for i in range(10): print("returning %i**2" % i) yield i ** 2 g1 = f() g2 = f() print(next(g1)) print(next(g1)) print(next(g1)) print(next(g2)) print(next(g2)) print(next(g1))
04229618cfcd1a1d69e3da28b9ca8f3ea03cc199
ash/python-tut
/41.py
241
4.1875
4
name = "John" print("Hello, " + name + '!') print("Hello, %s!" % name) print("Hello, {0}!".format(name)) print("{0}, {1}!".format('Hi', name)) print("{1}, {0}!".format(name, 'Hi')) print('My name is {0}. {0} {1}.'.format('James', 'Bond'))
dd559ec5ca3227b23146d979d4a526f758fa72fb
ash/python-tut
/reference/18-overloading-operators.py
166
3.796875
4
class X: def __init__(self, x): self.x = x def __add__(self, other): return X(self.x + other.x) x1 = X(5) x2 = X(6) x3 = x1 + x2 print(x3.x)
967c41a45b1733efcd1317e2ef24e3aed17747a4
ash/python-tut
/49.py
225
3.671875
4
def area_of_rectangle(width, height): print('width=' + str(width)) print('height=' + str(height)) return width * height print(area_of_rectangle(height=20, width=10)) print(area_of_rectangle(width=10, height=20))
197874f4b99dcf786c6762b59bbaf52a53ecd344
ash/python-tut
/course/tasks/credit-calculator.py
326
3.875
4
amount = int(input('Amount, €: ')) years = int(input('Years: ')) rate = float(input('Interest rate, %: ')) p = rate / 100.0 monthly = (amount * p * ((1 + p) ** years)) / (12 * (((1 + p) ** years) - 1)) print('Monthly payment = %.02f' % monthly) total = monthly * 12 * years print('Total amount to be paid %.02f ' % tot...
18d468f7ea76c007fd0d3aefb4a69b00a5bad4f8
ash/python-tut
/course/tasks/max2.py
182
3.875
4
max = None for i in range(1, 11): n = int(input('Value ' + str(i) + ': ')) if max == None: max = n elif n > max: max = n print('Maximum is ' + str(max))
19c98e32ae9bb33727ebeb711694908d67a56add
ash/python-tut
/course/tasks/sum-of-digits2.py
111
3.828125
4
n = input('Your number: ') s = 0 for c in n: v = int(c) s = s + v print('Sum of digits = ' + str(s))
29c63daceadc0c9d56543474796b1519d5494a9b
ash/python-tut
/course/tasks/quadrant.py
402
3.96875
4
x = float(input('x: ')) y = float(input('y: ')) if x > 0: if y > 0: print('I') elif y < 0: print('II') else: print('Axis X') elif x < 0: if y > 0: print('IV') elif y < 0: print('III') else: print('Axis -X') else: if y > 0: print('Axis ...
037fc984aad2c55bacbebe75a64085681fbcbb4e
ash/python-tut
/reference/46-dotted-name.py
135
3.53125
4
import math #from math import sqrt import time t0 = time.time(); for i in range(10_000_000): math.sqrt(i) print(time.time() - t0)
10ca3dd42b21d9c6b6c785b52a4abdd423ab802d
ash/python-tut
/course/list-mul-vs-compreh.py
157
3.78125
4
list1 = [[10, 20, 30]] * 3 list2 = [[10, 20, 30] for _ in range(3)] print(list1) print(list2) list1[1][1] = 99 list2[1][1] = 99 print(list1) print(list2)
5e95c72c5dd1bf880df055a1027f7de10b94b62a
ash/python-tut
/course/tasks/number-of-unique-elements.py
178
4.03125
4
sentence = input('Your string: ') words = sentence.split() unique = set(words) print(str(len(unique)) + ' unique words') # Your string: hello here hello there # 3 unique words
1922f14e27907d4b02f0e55c64e007fe8b7eebf3
ash/python-tut
/course/tasks/count-words-in-file.py
197
3.9375
4
filename = input('File name: ') content = '' for line in open(filename): content += line #print(content.split()) words_count = len(content.split()) print('%d words in the file' % words_count)
c7f35e0aafb86b55869a34bf114272190b80359b
ash/python-tut
/course/tasks/sum-of-digits.py
153
3.90625
4
n = int(input('Your number between 100 and 999: ')) s = n // 100 n = n % 100 s = s + n // 10 n = n % 10 s = s + n print('Sum of digits = ' + str(s))
4c0bb0a050b6c8dcbb2f82beda0b1a37a736db22
ash/python-tut
/14.py
52
3.6875
4
s1 = "abc" + "def" print(s1) s2 = s1 * 3 print(s2)
281125fe06d27ba45b16d21ddc47781078c3d1fd
ash/python-tut
/course/tasks/filter-odd-even.py
188
3.921875
4
odd = [] even = [] for i in range(1, 11): n = int(input('Number %i: ' % i)) if n % 2: odd.append(n) else: even.append(n) all = odd all.extend(even) print(all)
4dc53b7340c3b86c3f148780b1e0379e35e99833
ash/python-tut
/course/tasks/find-numbers.py
99
3.875
4
import re str = input('Your string: ') nums = re.findall(r'\d+', str) for x in nums: print(x)
d4ee5cc40bdd86eaf7d485075a404913027bc52d
ash/python-tut
/course/tasks/number-property.py
275
4.03125
4
n = int(input('Enter number: ')) if n < 0: print('Negative number') elif n > 0: print('Positive number') else: print('Zero') n = abs(n) if n < 10: print('One-digit number') elif n < 100: print('Two-digit number') else: print('Three digits or more')
83435ccde625b8e500239d13f41c2ddae1c7079d
AntAndr83/PytonLessons
/Anton_Andrienko_HW_1.2.py
183
3.59375
4
n = input("Введите трехзначное число:") n = int(n) s = str(n) a = int(s[0]) b = int(s[1]) c = int(s[2]) print("Сумма цифр числа:", a + b + c)
40ca306cbada2ede92affdbc5525d82151939335
Mustafa-Ali1011/epsilon
/Ass_6/my_packages/Transformers/stringtransformers.py
198
4.125
4
def string_reverse(): string=input("enter any string :") print(string[::-1]) def string_captalize(): string=input("enter any string :") print(string.capitalize())
1498d8eb37e0724d2e1f52cf2588e52ea87a28bd
tianlanshidai/leetcode
/zxq/0003-longest-substring-without-repeating-characters.py
943
3.875
4
# # 问题描述: # 3. Longest Substring Without Repeating Characters1. Two Sum # Given a string, find the length of the longest substring without repeating characters. # 其他人的解法 def lengthOfLongestSubstring(self, s): dct = {} max_so_far = curr_max = start = 0 for index, i in enumerate(s): if i in dct and ...
57b3e11af652ee1c29ffe33daaa966199a4fcfae
lauralyeinc/Intro-Python-I
/src/15_classes.py
1,962
3.9375
4
# Make a class LatLon that can be passed parameters `lat` and `lon` to the # constructor # YOUR CODE HERE class LatLon: def __init__(self, lat, lon): self.lat = lat self.lon = lon # my_location = LatLon(25, 87) # print(my_location.lat) # print(my_location.lon) # Make a class Waypoint that can be ...
ba1aec394dd8eccee56e2e7aa6a1f556e9e40272
abstractlyZach/CardGames
/tests/test_cards/test_rank.py
1,426
3.640625
4
from cards import ranks ORDERED_RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'] def test_get_all_ranks(): all_ranks = ranks.get_all_ranks() assert len(all_ranks) == 13 for rank in all_ranks: assert rank in ORDERED_RANKS def test_get_smaller_ranks_single_ran...
aa04ff7e07dd71f0c67f193afc9b21a047215ed4
abstractlyZach/CardGames
/holdem/player.py
2,939
3.703125
4
from . import exceptions from . import wager class Player(object): def __init__(self, name): self._name = name self._cards = [] self._chip_count = 0 self._bet_set = False self._reset_wager() def deal_hole_card(self, card): """Deal a hole card to the player.""" ...
bdf6182e46af370c4643c41deade2aa87298223a
VkaZas/CS1420
/hw3/kmeans.py
3,102
3.625
4
""" This is a file you will have to fill in. It contains helper functions required by K-means method via iterative improvement """ import numpy as np from kneighbors import euclidean_distance def init_centroids(k, inputs): """ Selects k random rows from inputs and returns them as the chosen centroid...
069cb501f459b4dfdbe7dbeb3cd0aa400d78b09c
marcos-mpc/CursoEmVideo-Mundo-2
/ex069.py
737
3.71875
4
print(25*'=') cont1 = cont2 = cont3 = 0 while True: idade = int(input('digite sua idade: ')) if idade >= 18: cont1 += 1 while True: sexo = input('digite seu sexo: [M/F] ').strip().upper()[0] if sexo in 'MF': break if sexo == 'M': cont2 += 1 if sexo == 'F':...
6339229f2346256d9628a9d40d61eb3fcf8a0b9c
marcos-mpc/CursoEmVideo-Mundo-2
/ex071a.py
423
3.734375
4
n = int(input('digite quanto a ser sacado: ')) total = n ced = 50 cont = 0 while True: if total >= ced: total -= ced cont += 1 else: if cont > 0: print(f'total de {cont} cedulas de {ced}') if ced == 50: ced = 20 elif ced == 20: ced = 10...
25489b54b0129d9e2b7b5ab765552678b366775f
marcos-mpc/CursoEmVideo-Mundo-2
/ex060.py
148
3.96875
4
n = int(input('digite um numero: ')) m = n for c in range(n - 1, 0, -1): mult = m * c m = mult print('o fatorial de {}! = {}'.format(n, m))
8b84df841eb094d895ef9d884a79c53b22b45fab
marcos-mpc/CursoEmVideo-Mundo-2
/ex53a.py
283
4.03125
4
frase = input('digite uma frase: ').strip().upper() separado = frase.split() junto = ''.join(separado) inverso = junto[::-1] print('a frase {} invertida fica {}'.format(junto, inverso)) if junto == inverso: print('temos um palindromo') else: print('nao temos um palindromo')
478992022b803846a308642e19c96f88d3346355
irfansha/knights_tour
/graph_network/knight_moves.py
722
3.625
4
#append the value in the desired list or creates new one in the dictonary #Generates a list of legal moves for the knight knight_moves = [[]] def generate_legal_moves(x,y,N): possible_pos = [] move_offsets = [(1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1)] for move in move_offsets: new...
f975c1c03e402bdeb50b10fc7fd5639151009f85
epandurski/python-course
/examples/tic_tac_toe_classes.py
1,849
3.625
4
X = 'X' O = 'O' E = ' ' LINES = [ # horizontal lines [0, 1, 2], [3, 4, 5], [6, 7, 8], # vertical lines [0, 3, 6], [1, 4, 7], [2, 5, 8], # diagonals [0, 4, 8], [2, 4, 6], ] FIELDS = ['a3', 'b3', 'c3', 'a2', 'b2', 'c2', 'a1', 'b1', 'c1'] class TicTacToeGame: de...
36a7f9d82c36b7ce1fa0b873983d37e4dfda5302
epandurski/python-course
/examples/06_exceptions.py
746
4.03125
4
import math class NotANumberError(Exception): pass class NonPositiveNumberError(Exception): """The number is not positive""" def get_integer(prompt='Enter a number: '): s = input(prompt) try: return int(s) except ValueError: raise NotANumberError(s) def get_positive_integer()...
d32473985584487a233d89367225c658950cf3cc
manimanis/LeetCode
/April2021/sol_22.py
959
3.53125
4
"""Brick Wall https://leetcode.com/explore/challenge/card/april-leetcoding-challenge-2021/596/week-4-april-22nd-april-28th/3717/ """ from typing import List def wall(t): tset = {0: 0} for st in t: s = 0 tset[0] += 1 for v in st: s += v if s not in tset: ...
67da44d910c411c31135a5148014c1baa02b2eac
manimanis/LeetCode
/April2021/sol_15.py
484
3.6875
4
"""Fibonacci Number. https://leetcode.com/explore/featured/card/april-leetcoding-challenge-2021/595/week-3-april-15th-april-21st/3709/ """ class Solution: def fib(self, n: int) -> int: t = 0, 1 if n < 2: return t[n] a, b = t for _ in range(n-1): a, b = b, a+...
41ca07aed679c4f8d79e86dbdbbde675e6380b16
manimanis/LeetCode
/May2021/sol_13.py
3,747
4.0625
4
"""816. Ambiguous Coordinates Medium We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)". Then, we removed all commas, decimal points, and spaces, and ended up with the string s. Return a list of strings representing all possibilities for what our original coordinates could have been. Our original re...
557298550ca855eb96803e8f22bcb2be05a1f4b9
sengeiou/data_science
/conf/top_bad_list.py
305
3.578125
4
def get_bad_list(): with open('bad_list.txt') as file: lines = file.readlines() res_list = [] for string in lines[:-1]: string_new = string[:-1] res_list.append(string_new) res_list.append(lines[-1]) return res_list print(get_bad_list())
caa80b81f8d87956540d0690481ae903055531b2
mbaigorria/AA-TP2
/src/FourInALine.py
17,181
3.640625
4
import random import matplotlib.pyplot as plt # I need a board representation that is: # - hashable # - compact under sparsity # - unique representation of every board (else Q as dictionary wont work) # - remark: the representation must ONLY be efficient to hash on Players, # not for the overall game class FourInAL...
6afc6ea913b8abfa80f8fa26fe24655e2e59cde7
slaily/deep-learning-bits
/recurrent_neural_network/simple_rnn.py
1,247
3.90625
4
""" Numpy implementation of a simple RNN """ import numpy as np # Number of timesteps in the input sequence timesteps = 100 # Dimensionality of the input feature space input_features = 32 # Dimensionality of the output feature space output_features = 64 # Input data: random noise for the sake of the example inputs = ...
67e52c643c046dc68c0a090418ffce2b94906a63
tommyle128/leminhtu-fundamentals-c4e20
/Session01/hello_world.py
137
3.75
4
yob = int(input("What's your birth year?")) import datetime yearnow = int(datetime.datetime.now().year) age = yearnow - yob print(age)
5088233e47d32267680fdbd14ca229b54b7cb6e7
tommyle128/leminhtu-fundamentals-c4e20
/Session05/homework/2.py
618
3.640625
4
numbers = [1, 6, 8, 1, 2, 1, 5, 6] print(numbers) ans = int(input("Enter a number? ")) # Cach 1: su dung count() print() print("Cach 1: su dung count()") total_times = numbers.count(ans) print(ans, "appear(s)", total_times,"times in my list") # Cach 2: khong su dung count() print() print("Cach 2: khong su dung coun...
71b9dded95de6a2595c9c5f59663722abe5e0d04
tommyle128/leminhtu-fundamentals-c4e20
/Session02/test.py
173
4
4
# yob = int(input("Your year of birth: ")) # age = 2018 - yob # if age < 10: # print ("baby") # elif age < 18: # print ("teenager") # else: # print ("adult")
82279939c7246d27d65daf2b456a65c53d929141
mahbeg/us-states-game
/main.py
1,298
3.984375
4
from turtle import Turtle, Screen import pandas data = pandas.read_csv("50_states.csv") name_of_state = data["state"] screen = Screen() screen.setup(800, 800) screen.title("U.S States game") image = "blank_states_img.gif" screen.addshape(image) turtle = Turtle(image) moving_name = Turtle() moving_name.penup...
2c19fba5dc45534cb6c160b6926397377a552026
neetukumari4858/dictionory-in-python
/doc9.py
177
4.125
4
d = {'Red': 1, 'Green': 2, 'Blue': 3} for value in d.items(): print(value) # d = {'Red': 1, 'Green': 2, 'Blue': 3} # for key,value in d.items(): # print(key,value)
3a4100406b9e43b8ea5ef2da2611f7b4796a46a1
neetukumari4858/dictionory-in-python
/doc50.py
247
4
4
d={1: 'red', 2: 'green', 3: 'black', 4: 'white', 5: 'black'} # Convert the said dictionary into a list of lists: # [[1, 'red'], [2, 'green'], [3, 'black'], [4, 'white'], [5, 'black']] l=[] for i,j in d.items(): m=[i,j] l.append(m) print(l)
d23944e83b40e38e057dea09e0b2c07f532c0ded
neetukumari4858/dictionory-in-python
/main .py
704
3.953125
4
# a=3 # b=6 # def cal(a,b): # return a+b,a-b # print(cal(3,7)) # i=0 # def m(): # i=5 # print(i) # m() # why it takes local var if var is same # i=0 # def m(): # i=i+1 # print(i) # m() # global var # def s(x,y): # l=x+y # print(l) # k=s(3,2) # print(k) # o/p==5 none # def s(x,y): ...
c6699a3775d86f23edc97ab0090ed95de086450c
neetukumari4858/dictionory-in-python
/doc.7.py
128
3.609375
4
dict={} dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60} dict.update(dic1) dict.update(dic2) dict.update(dic3) print(dict)
929ee5d4f136e9aa510bb163d06782e734803f13
neetukumari4858/dictionory-in-python
/doc.8.py
121
4.125
4
key=int(input("enter key :-")) dic={1:"a",2:"b",3:"c"} if key in dic : print("exist") else: print("not exist")
8fa9261e029d87d16684a32bc3a201b262be410c
neetukumari4858/dictionory-in-python
/doc39.py
226
3.578125
4
d={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190} # Marks greater than 170: # {'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190} n=int(input("enter no:-")) k={} for i in d: if d[i]>n: k[i]=d[i] print(k)
2e4298d139af7ed022ba22cb7fe0fb215b8ec011
grubino/segmentation
/anneal/__init__.py
1,720
3.8125
4
from random import randint import segment from score import evaluate_lexicon, evaluate_specificity def flip(segs, pos): """ flip the segmentation bit at :pos: :param segs: segmentation string '0001010000100' :param pos: position to flip :return: the new segmentation string """ return seg...
661bf8065e6b2e07c0e7b39413a617682a9ee8a1
JakubTutka/ASAP-Score
/logic/validate_data.py
599
3.703125
4
import re class Validate: password_pattern = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$" # ^ upper patern means: Minimum eight characters, # at least one uppercase letter, one lowercase letter and one number: email_pattern = "[a-zA-Z0-9]+@[a-zA-Z]+\.(com|pl|net|edu)" def checkPassword(self,...
20530a9e78efe2af9867cdf80d739972872cf821
bbanothu/Python
/test.py
114
3.75
4
print("Hello World") a = True b = True if a == b: print("true") b = False if a != b: print("false")
da92889e38a1dab2bb525328e86bc66c0a4faf25
shankarkrishnamurthy/problem-solving
/occurrences-after-bigram.py
663
3.703125
4
class Solution(object): def findOcurrences(self, text, first, second): """ :type text: str :type first: str :type second: str :rtype: List[str] """ res, l = [],text.split(' ') for i in xrange(1,len(l)): if l[i-1] == first and l[i] == second...
df631a2c6755f4ceeee7e12f0fa54e0ded1117e0
shankarkrishnamurthy/problem-solving
/finddup.py
695
3.640625
4
class Solution(object): def findDuplicate(self, nums): """ :type nums: List[int] :rtype: int """ l = len(nums) if l < 3: return nums[0] L, R = 1, l while True: mid = (L + R) / 2 lt = 0 for v in nums: ...
486958e94f5964b8e9eae646da293381743aca4e
shankarkrishnamurthy/problem-solving
/longest-arithmetic-sequence.py
764
3.546875
4
class Solution(object): def longestArithSeqLength(self, A): """ :type A: List[int] :rtype: int """ lh,msf=[{}],0 for i in xrange(1,len(A)): cd = A[i] - A[i-1] h = {} h[cd] = h.get(cd,0) + 1 msf = max(msf, h[cd]) ...
725e8a9b84dbb7e6a7079e9765b964f633d28e61
shankarkrishnamurthy/problem-solving
/mergeksortedlist.py
1,574
3.78125
4
# Definition for singly-linked list. class ListNode(object): def __init__(self, x): self.val = x self.next = None @staticmethod def println(ln): print('['), while ln: print ln.val, ln = ln.next print(']') class Solution(object): def merge...
845f5bcc194c036302fac6177b041efda8e01c48
shankarkrishnamurthy/problem-solving
/top-view-of-tree.py
876
3.703125
4
class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def __init__(self): self.hs = dict() def do_preorder_dfs(self,root,h): if not root: return None if h not in self.hs: ...
cff2249cfcd511b00ea819e8cefae5184afc8e59
shankarkrishnamurthy/problem-solving
/height-checker.py
378
3.703125
4
class Solution(object): def heightChecker(self, heights): """ :type heights: List[int] :rtype: int """ hs,res = sorted(heights),0 for i,v in enumerate(heights): if v != hs[i]: res+=1 return res print Solution().heightChecker([1,1,4,2,...
8b828ef3f9e19b099c2675fdd6a8f8fa32c850ae
shankarkrishnamurthy/problem-solving
/construct-tree-from-prepost-order.py
1,716
3.8125
4
# Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None @staticmethod def printtn(root): print "[", q = [root] while True: nq = [] for n in q: i...
38bf4d298cee6887156d5d81a36cd9705f3ebc17
shankarkrishnamurthy/problem-solving
/permutation.py
511
3.640625
4
def do_permute(prim, e): nlist = [] for i in prim: tmp = list(i) for j in range(0,len(i)+1): nlist.append(tmp[:j]+[e]+tmp[j:]) return nlist def permute(nums): """ :type nums: List[int] :rtype: List[List[int]] """ l1 = [] for e in nums: if not ...
bc083227569855c48fcec1910dda5528ae4129e6
shankarkrishnamurthy/problem-solving
/path-sum-iii.py
1,310
3.859375
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 pathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: int """ ...
724ab4499820acb09fd335abc6852f9f93176f52
shankarkrishnamurthy/problem-solving
/maxhistogram-work.py
1,452
3.546875
4
class Solution(object): def largestRectangleArea(self, heights): """ :type heights: List[int] :rtype: int """ print heights, s = [] maxarea, i, val = 0, 0, 0 for i,v in enumerate(heights): #print "Adding: ", (i,v) if not s or (s...
ea520c29eb3334a43819fbe6e1af61b0e35a041f
shankarkrishnamurthy/problem-solving
/uniqpath.py
408
3.5
4
class Solution(object): def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ val = [[1 for j in range(n)] for i in range(m)] print val for i in range(1, m): for j in range(1,n): val[i][j] = val[i-1][j] ...
874027c9e130c73bb6a3fdb5790471516e75ec1c
shankarkrishnamurthy/problem-solving
/backspace-str-cmp.py
1,025
3.578125
4
class Solution(object): def backspaceCompare(self, S, T): """ :type S: str :type T: str :rtype: bool """ sl = 0 for i,v in enumerate(S): if v == '#': if sl > 0: sl -= 1 else: S = S[:sl] + v + S[sl+1:] ...
c51eb4133e3f2ec68f956a48307dfdab6b93b49a
shankarkrishnamurthy/problem-solving
/prune-bin-tree.py
1,483
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 @staticmethod def printtn(root): print "[", q = [root] while True: nq = [] for n in q: i...
95e21bc5da37aad2ecd1458db9d6f6ec01e3ab25
shankarkrishnamurthy/problem-solving
/check-if-word-is-valid-after-substitutions.py
798
3.828125
4
class Solution(object): def isValid(self, S): """ :type S: str :rtype: bool """ s = [] for i in S: if i == 'c': if len(s) > 1 and s[-1] == 'b' and s[-2] == 'a': s.pop() s.pop() else:...
56003c2a4f9cad60facbda49a5e4da04d269bb3c
shankarkrishnamurthy/problem-solving
/min-add-make-paranthesis-valid.py
558
3.609375
4
class Solution(object): def minAddToMakeValid(self, S): """ :type S: str :rtype: int """ stack = [] for i in range(len(S)): if S[i] == ')' and len(stack) > 0: if stack[-1] == '(': stack.pop() ...
7648d0b868786a2800f67357e9daac1e03b0553b
shankarkrishnamurthy/problem-solving
/perm.py
675
3.53125
4
class Solution(object): def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ self.nlist = [] def do_permute(e): clist=[] for i in list(self.nlist): for j in xrange(len(i)+1): tmp = l...
8aab6c80145af28059c84e09adba4403ce0d66b9
shankarkrishnamurthy/problem-solving
/smallest-subsequence-of-distinct-characters.py
751
3.578125
4
class Solution(object): def smallestSubsequence(self, t): """ :type t: str :rtype: str """ h,ans,s={},[],set() for i,v in enumerate(t): h[v] = i for i,c in enumerate(t): if c in s: continue while ans and ans[-1] > c and h[ans[-1]] > i: ...
8403e3ec4290768cb06a033821186a47e940ddf8
shankarkrishnamurthy/problem-solving
/rect-overlap.py
471
4.0625
4
class Solution(object): def isRectangleOverlap(self, rec1, rec2): """ :type rec1: List[int] :type rec2: List[int] :rtype: bool """ x1,y1,x2,y2 = rec1 a1,b1,a2,b2 = rec2 if x2 <= a1 or a2 <= x1 or y2 <= b1 or b2 <= y1: #rect up or down retur...
7c2771107761498e9b5248ac0d08bcb04969605d
shankarkrishnamurthy/problem-solving
/smallest-string-starting-from-leaf.py
1,565
3.75
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 smallestFromLeaf(self, root): """ :type root: TreeNode :rtype: str """ ha = {} ...
d3978d5999f1f8e3c1c6c2137db2c6867fa23ef6
shankarkrishnamurthy/problem-solving
/judge-robo-circle.py
546
3.546875
4
class Solution(object): def judgeCircle(self, moves): """ :type moves: str :rtype: bool """ h = { 'U': (0,-1), 'D': (0,1), 'L':(-1,0),'R':(1,0) } n=init = (0,0) for m in moves: n = tuple(map(sum, zip(n, h[m]))) print m,n if (0,0...
4e2bae57262cd80d88de18f008530aa2f33427b3
shankarkrishnamurthy/problem-solving
/preorder-inorder-construct.py
1,470
3.953125
4
# Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None @staticmethod def printtn(root): print "[", q = [root] while True: nq = [] for n in q: i...
30f5171ec3422e2075d14a7931c04cca5430a41b
aniksen0/pythonScriptsAndProject
/autoInc.py
237
3.5
4
#this script will input number (serially) in the form! import pyautogui i=int(input("enter")) for x in range(14,i): print(x) d=str(x) pyautogui.typewrite(d) pyautogui.press('enter') pyautogui.sleep(0.200)