blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
bdaa49896325cec69c72473727c1670c5d93fceb
igobarros/Curso-Udemy-Machine-Learning-A-Z
/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/Python/random_selection.py
677
3.75
4
# -*- coding: utf-8 -*- # Importing the libraries import pandas as pd import numpy as np import matplotlib.pyplot as plt # Importing the dataset df = pd.read_csv('Ads_CTR_Optimisation.csv') # Importing random selection import random N = 10000 d = 10 ads_selected = [] total_selected = 0 for n in ran...
3ead8c3b079902fb0698adde642973c39e8268a1
juanhurtado4/cs3
/searching_algorithms/linear_binary_search.py
3,672
4.15625
4
from binary_search_helper import * def linear_search(array, item): """return the first index of item in array or None if item is not found""" # implement linear_search_iterative and linear_search_recursive below, then # change this to call your implementation to verify it passes all tests # return line...
ab0c133caf4fbcca3f75162ed6b89952af26aced
omerlavian20/eeb-c177-project
/python-scripting/multiple_corrs_excel.py
1,828
4.3125
4
#!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt import pandas as pd #input file to analyze, column that want to compare other columns to, and list of columns that want to compare to the original column def multiple_corrs_excel(filename, colx, coly): ''' Computes correlation coefficie...
7a3c0f8ea003d428b223c5d891ba5544aa5398a7
hannody/TicTacToe
/data/gamedata.py
586
3.6875
4
from dataclasses import dataclass @dataclass class GameData: """ GameData class holds data for a game. """ screen_dim: int = 600 game_title: str = 'Tic Tac Toe' board_dim: int = 3 square_size : int = 200 line_width : int = 15 rows: int = 3 columns: int = 3 win_line_width: i...
602c70abddbda9318912942cfcbb8ba8b6f4ad1d
thunderbump/euler
/012/012.py
1,578
3.625
4
#!/usr/bin/python """Computes the lowest triangle number who has at least X divisors.""" import sys argc = len(sys.argv) prime_file_loc = "../util/primes" max_divisors = 500 usage = """012.py [X] Computes the lowest triangle number who has at least X divisors. If no X is provided, 500 is used.""" if argc > 2: pr...
ec31de243edfef7c5c2823ccc17a5e08fc44c7d7
thunderbump/euler
/003/003.py
1,190
3.8125
4
#!/usr/bin/python """Prints all prime factors of X using local list of primes "primes" """ import sys argc = len(sys.argv) prime_file_loc = "primes" usage = """003.py X Prints all prime factors of X using local list of primes "primes" """ if argc != 2: print(usage) sys.exit(1) try: factee = long(sys.argv...
e4d6d03a345bc9f98b79f01e2738b1a71a2c2ef3
thunderbump/euler
/020/020.py
396
3.8125
4
#!/usr/bin/python """Computes the sum of the digits in X!""" import sys from math import factorial argc = len(sys.argv) usage = """020.py X Computes the sum of the digits in X!""" if argc != 2: print(usage) sys.exit(1) try: X = int(sys.argv[1]) except ValueError: print(usage) print("X must be num...
9b7519968b2d58083f471ef7584d3385a1542a8f
thunderbump/euler
/011/011.py
2,236
3.546875
4
#!/usr/bin/python """Calculates the max product of 4 consecutive numbers found horizontally, vertically, or diagonally in a grid.""" import sys argc = len(sys.argv) data_file_loc = "grid" usage = """011.py [data_file] Calculates the max product of 4 consecutive numbers found horizontally, vertically, or diagonally ...
13dc72c5afaf103fad32665db14d28ecf4c46012
CathySoMcK/python-data-science
/2018-01-09/from_jenn/baseball_analysis.py
474
3.578125
4
import pandas as import pd import morestats as m df = pd.read_csv('baseball.csv') #find average height, weight, age for all players using morestats avg_height = m.mean(df.Height) avg_weight = m.mean(df.Weight) avg_age = m.mean(df.Age) #group by team name and show mean height, weight, ages teams = df.groupby(['Te...
22a164b9f92b63f5be1b26ae4395c8e1ba741178
CathySoMcK/python-data-science
/2018-01-08/from_jenn/basics.py
1,793
3.890625
4
#1. lists when order is important and you need to be able to change them odds = [5,7,9] sum(odds) # will total up this list total = 0 #variable set up to hold a value for num in odds: #another way to get the total total = total + num #same as total=+num total2 = 0 for i, num in enumerate(odds): total2 = tot...
d966b118d340da85e517038967b9965179aa7d45
asmeza/parcial_python
/parcial.py
4,408
3.828125
4
import os class Student(): def __init__(self): self.__student = {} self.__period_1 = {} self.__period_2 = {} self.__period_3 = {} self.__period_4 = {} self.__list_student = [] def addStudent(self): print() print("Hola, por favor llena todos los da...
69447ec4042fd6dd543d2fe4ddedcef7bf56e350
superMC5657/leetcode-py
/array/119.py
1,003
3.8125
4
# -*- coding: utf-8 -*- # !@time: 2021-02-12 00:29:41 # !@author: superMC @email: 18758266469@163.com # !@fileName: pascals-triangle-ii.py # 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。 # # # # 在杨辉三角中,每个数是它左上方和右上方的数的和。 # # 示例: # # 输入: 3 # 输出: [1,3,3,1] # # # 进阶: # # 你可以优化你的算法到 O(k) 空间复杂度吗? # Related Topics...
30a801d7f04277bccfdfdaf1e14dd595cfc51fec
superMC5657/leetcode-py
/dfs/113.py
1,818
3.5625
4
# -*- coding: utf-8 -*- # !@time: 2020-11-01 20:43:40 # !@author: superMC @email: 18758266469@163.com # !@question title: path-sum-ii # 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径。 # # 说明: 叶子节点是指没有子节点的节点。 # # 示例: # 给定如下二叉树,以及目标和 sum = 22, # # 5 # / \ # 4 8 # ...
12b9a22ac70ff9ba499772da12576d5703c08d71
superMC5657/leetcode-py
/back_track/46.py
1,106
3.734375
4
# -*- coding: utf-8 -*- # !@time: 2021-03-01 17:15:13 # !@author: superMC @email: 18758266469@163.com # !@question title: permutations # 给定一个 没有重复 数字的序列,返回其所有可能的全排列。 # # 示例: # # 输入: [1,2,3] # 输出: # [ # [1,2,3], # [1,3,2], # [2,1,3], # [2,3,1], # [3,1,2], # [3,2,1] # ] # Related Topics 回溯算法 # 👍 1...
caa4725b2125867d4feac1ca6e1c323df7aa9a3a
superMC5657/leetcode-py
/dichotomy/34.py
2,031
3.78125
4
# -*- coding: utf-8 -*- # !@time: 2020-12-01 16:35:46 # !@author: superMC @email: 18758266469@163.com # !@question title: find-first-and-last-position-of-element-in-sorted-array # 给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。 # # 如果数组中不存在目标值 target,返回 [-1, -1]。 # # 进阶: # # # 你可以设计并实现时间复杂度为 O(log...
4e61b8ecf78ae26bede1a201c75bfccad2529e00
superMC5657/leetcode-py
/listnode/82.py
1,406
3.625
4
# -*- coding: utf-8 -*- # !@time: 2021-03-25 04:14:03 # !@author: superMC @email: 18758266469@163.com # !@question title: remove-duplicates-from-sorted-list-ii # 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字。 # # 示例 1: # # 输入: 1->2->3->3->4->4->5 # 输出: 1->2->5 # # # 示例 2: # # 输入: 1->1->1->2->3 # 输出: 2->3 # ...
a52dd34395ca2e39da0d40f5f15cca3250bf92c5
superMC5657/leetcode-py
/back_track/47.py
1,431
3.53125
4
# -*- coding: utf-8 -*- # !@time: 2021-03-04 15:11:41 # !@author: superMC @email: 18758266469@163.com # !@fileName: permutations-ii.py # 给定一个可包含重复数字的序列 nums ,按任意顺序 返回所有不重复的全排列。 # # # # 示例 1: # # # 输入:nums = [1,1,2] # 输出: # [[1,1,2], # [1,2,1], # [2,1,1]] # # # 示例 2: # # # 输入:nums = [1,2,3] # 输出:[[...
df2c646e1fe7de73c877dc6a93928e1f26df2ff3
superMC5657/leetcode-py
/stack/227.py
1,839
3.78125
4
# -*- coding: utf-8 -*- # !@time: 2021-03-11 14:05:41 # !@author: superMC @email: 18758266469@163.com # !@question title: basic-calculator-ii # 给你一个字符串表达式 s ,请你实现一个基本计算器来计算并返回它的值。 # # 整数除法仅保留整数部分。 # # # # # # 示例 1: # # # 输入:s = "3+2*2" # 输出:7 # # # 示例 2: # # # 输入:s = " 3/2 " # 输出:1 # # # 示...
748809dbed54a744bbbfd8aeb06e491655417a1a
superMC5657/leetcode-py
/dfs/547.py
2,024
3.625
4
# -*- coding: utf-8 -*- # !@author: superMC @email: 18758266469@163.com # 班上有 N 名学生。其中有些人是朋友,有些则不是。他们的友谊具有是传递性。如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C # 的朋友。所谓的朋友圈,是指所有朋友的集合。 # # 给定一个 N * N 的矩阵 M,表示班级中学生之间的朋友关系。如果M[i][j] = 1,表示已知第 i 个和 j 个学生互为朋友关系,否则为不知道。你 # 必须输出所有学生中的已知的朋友圈总数。 # # # # 示例 1: # # 输入: # [...
0de2d8746175602ddbf2520d862eebc6be8e1acc
superMC5657/leetcode-py
/greedy/45.py
1,666
3.515625
4
# -*- coding: utf-8 -*- # !@time: 2021-04-05 05:11:22 # !@author: superMC @email: 18758266469@163.com # !@fileName: jump-game-ii.py # 给定一个非负整数数组,你最初位于数组的第一个位置。 # # 数组中的每个元素代表你在该位置可以跳跃的最大长度。 # # 你的目标是使用最少的跳跃次数到达数组的最后一个位置。 # # 示例: # # 输入: [2,3,1,1,4] # 输出: 2 # 解释: 跳到最后一个位置的最小跳跃数是 2。 #   从下标为 0 跳到下标为 1 的位...
fb2bc325e3375d08b2ff4ecf9f254a4599831c76
superMC5657/leetcode-py
/double-pointer/287.py
1,613
3.734375
4
# -*- coding: utf-8 -*- # !@time: 2020-11-03 21:20:36 # !@author: superMC @email: 18758266469@163.com # !@question title: find-the-duplicate-number # 给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和 n),可知至少存在一个重复的整数。假设只有一个重复的整数,找出 # 这个重复的数。 # # 示例 1: # # 输入: [1,3,4,2,2] # 输出: 2 # # # 示例 2: # # 输入: [3,1,3,4,...
091d18b1fc856286c44e1dc06dc8f969b465d642
Shouraya/Computatuional-Statistics-Lab-Assignment
/Assignment 1/4.py
1,552
3.90625
4
#Pass Array as an argument in class and implement element wise calculator using Classes #CLASS class calci(): def __init__(self,a,b): self.a = a self.b = b def add(self): self.add = [] for i in range(len(self.a)): self.add.append(a[i]+b[i]) print(self.add) ...
638e05f14ffb430bc4c3133a4c7fd70c90f2956f
anurzhanuly/EPI
/first_task_opt.py
489
3.6875
4
def author_h_index(book_titles: list, book_citations: list)-> int: book_citations = sorted(book_citations) books_count: int = len(book_citations) result: int for i, value in enumerate(book_citations): if value <= books_count - i: result = value return result print(author_h_in...
3f1a1f2b87dcdc04a7778d5cff02d213fd61a75d
Guangxingtianxia/numpy_study
/Broadcast/触发广播机制.py
373
3.703125
4
''' 运算形状不同的数组时,就会触发广播机制 ''' import numpy as np a = np.array([[0, 0, 0], [10, 10, 10], [20, 20, 20], [30, 30, 30]]) b = np.array([1, 2, 3]) c = a * b d = a + b print('a * b=', c, '\n') print('a + b=', d, '\n') bb = np.tile(b, (4, 1)) print('bb=', bb, '\n') print('a+bb=',...
09eb9e553cfe1772d84daa9e9881a8f1e992a429
pzy636588/wodedaima
/逻辑运算符.py
555
3.890625
4
'''print("\n手机点打折,活动进行中.......") strWeek=input("请输入中文星期(如星期一):") intTime=int(input("请输入时间中的小时(范围:0~23):")) if (strWeek=="星期二"and (intTime>=9 and intTime<=11)) or (strWeek=="星期五"and (intTime>=13 and intTime<=16)): print("恭喜您,获得了折扣活动,快快不选购吧") else: print("对不起,您来晚了,期待下次活动")''' if 1==0 and 2==2: print("真") else...
a8e627974d19c53862eaef18b39b0f9a9fb4c88e
pzy636588/wodedaima
/遍历列表.py
285
3.703125
4
print("2017-2018赛季NBA西部联盟前八名") team=["休斯敦 火箭","金州 勇士","波特兰 开拓者","犹他 爵士","新奥尔良 鹈鹕","圣安东尼奥 马刺","俄克拉马合,雷霆","明腻苏达 森林狼"] for index,item in enumerate(team): print(index+1,item)
45192abcf4a54fcb1889b6eef5ffcfd096c44eed
pzy636588/wodedaima
/字典推导式.py
293
3.59375
4
import random randomdict={i:random.randint(2,5000) for i in range (1,8)} print('生成的字典为:',randomdict) name=['绮梦','姜子牙','诸葛亮'] sign=['天蝎','射手','魔蝎'] dictionary={i:j+'座' for i,j in zip(name,sign)} #使用列表推导式生成字典 print(dictionary)
9722b889ac4a249fc0c0533859a690e73f0e635a
pzy636588/wodedaima
/while循环.py
152
4.09375
4
none=True number=0 while none: number+=1 if number%3==2 and number%5==3 and number%7==2: print("这个数是",number) none=False
3d0c12f939cbd1f335b1af3cd386fa5e829f7844
pzy636588/wodedaima
/图形化主程序设计.py
783
3.625
4
import turtle #导入turtle模块 turtle.showturtle() #显示箭头 turtle.write("彭大帝国") #写字符串 turtle.forward(200) #前进300像素 turtle.color("red") #画笔颜色改为红色 turtle.left(91) #箭头左转91度 tur...
7d843e0baa43f786e7086d43d87ad59e8f00772e
pzy636588/wodedaima
/通过键值返回字典.py
929
3.75
4
name=['绮梦','大美女','奥黛丽赫本','玛丽莲梦露'] #作为键的列表 sign=['水平座','天蝎座','双鱼座','魔蝎座'] #作为值的列表 dictionary=dict(zip(name,sign)) #转换为字典 print(dictionary) print(dictionary['大美女']) #在使用字典时,很少直接输出它的内容,一般需要根据指定的键获得相应的结果 #在实际开发中,我们可不知道存在什么键,所以需要避免该异常的发生,具体的解决办法使用if语句对不存在的情况进行...
2f045372479e18bbf972dd0bce119591966e565b
pzy636588/wodedaima
/if语句的嵌套.py
729
3.828125
4
#国家质量监督检验局发布的《车辆驾驶人员血液。呼吸酒精含量阀值与检验》中规定,车辆驾驶人员血液中的酒精含量小于20Mg/100ml #不构成饮酒驾驶行为;酒精含量大于或等于20mg/100m,小于80mg/100ml为饮酒驾车;酒精含量大于或等于50mg/100ml为醉酒驾车 #现编写如下python代码判断是否酒后驾车 print("\n为了您和您家人的安全,严禁酒后驾车!\n") proof=20 if proof<20: print("\n您不构成酒驾行为,可以开车,但要注意安全") else: if proof<80: print("\n您的行为已经构成酒后驾驶标准,请不要开车") ...
753bf120aa93e505f9c4d3ff75fcbfbb3a89bc04
gaeunPark/Bigdata
/01_Jump_to_Python/Chap06/exam06.py
268
3.75
4
def compare(): while(True): num = int(input("양수를 입력하세요(종료:-1) : ")) if num == -1: break if num % 10 == 0: result = True else: result = False print(result) compare()
73c5db0e2a16823ccf399bdcdf209187d68f37ed
gaeunPark/Bigdata
/01_Jump_to_Python/Chap03/rhombus_v1.py
413
3.609375
4
# coding:cp949 print(" α׷ ver1.0") while True: num=int(input("غ Ȧ Էϼ(0 <- ): ")) if num==0: break elif num%2==0: print("¦ Էϼ̽ϴ. Էϼ") continue raw=int((num+1)/2) i=0 while i < raw: i += 1 print(" "*(raw-i), end='') print("*"*(2*i-1)) i
a2eaf2dce645e106b6a3a473a0a9700f450d7e23
gaeunPark/Bigdata
/01_Jump_to_Python/Chap05/test_1.py
438
3.75
4
class Calculator: def __init__(self, args): self.args = args self.result = 0 def sum(self): for i in self.args: self.result += i return self.result def avg(self): self.result = self.result/len(self.args) return self.result cal1 = Calculator([...
8e42970ad2ae7c970c36cb85b5fa043dff50dc10
gaeunPark/Bigdata
/01_Jump_to_Python/Chap03/135.py
265
3.53125
4
def print_gugudan(start_dan): for i in range(start_dan+5,10): for j in range(1,10): print(i*j, end="\t") print('') start_dan = int(input("시작 단 수를 입력하세요: ")) print_gugudan(start_dan)
4238ab756c8d579667946a8f8ae41111d277c496
gaeunPark/Bigdata
/01_Jump_to_Python/Chap06/exam07.py
461
3.6875
4
while(True): num1, num2, num3 = map(lambda convert_num: int(convert_num), input("세 개의 양수를 입력하세요(종료 -1): ").split(" ")) # if int(num1) != -1: # num1 = int(num1) # num2 = int(num2) # num3 = int(num3) if num3 % (num1*num2) == 0: print("%d는 %d와 %d의 공배수 입니다." %(num1, num2, num3...
4984e8eb4a5546762552cd9301f44587b9a2754d
gaeunPark/Bigdata
/01_Jump_to_Python/Chap03/park_v1.py
304
3.609375
4
#coding: cp949 fee = 0 age = int(input("̸ Էϼ: ")) if age>=0 and age<=3: fee = 0 elif age>=4 and age<=13: fee = 2000 elif age>=14 and age<=18: fee = 3000 elif age>=19 and age<=65: fee = 5000 else: fee = 0 print(" [%d] Դϴ." %fee)
2d7250222ad5cffaf318c8077b38490717062dca
peterhusisian/SimpleRenderer
/Geometry/Rectangle.py
540
3.703125
4
class Rectangle(object): def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height @classmethod def init_from_center(cls, center, width, height): x = center[0]-width//2 y = center[1]-height//2 ...
5021b76a80e0aa5258f02504b81231022e571e2d
BorislavIliev/Python
/RealPythonCourse/Part1/Functions/temperatures.py
371
4.03125
4
def celcius_to_fahrenheit(temp_c): temp_f = (temp_c * 9/5 + 32) return ("{0} degrees celcius = {1} degrees fahrenheit".format(temp_c, temp_f)) def fahrenheit_to_celcius(temp_f): temp_c = (temp_f - 32) * 5/9 return ("{0} degrees fahrenheit = {1} degrees celcius".format(temp_f, temp_c)) print(celcius_to...
3c6d1e1e3554a06d2668f7730641d2c8777bee5a
BorislavIliev/Python
/RealPythonCourse/Part1/strings.py
1,198
4.21875
4
long_phrase = """This is a long line that spans accross multiple lines preserving white spaces""" long_phrase_length = len(long_phrase) my_long_string = "Here's a string that I want to \ write across multiple lines since it is long." double_quotes_string = 'This string contains "double quotes".' apostrophe_string =...
61436fe9d880ac6e6115a6a4a6a43d411ef4bbf5
astroluj/python_study_prog
/[국민대학교]다이아몬드.py
1,446
3.53125
4
#-*- coding: utf-8 -*- ''' == Diamond Printing [국민대학교]20093326_이의재 ''' # Width and Height min size 3 # Size is odd # Exception MIN, MAX = 3, 99999 while(True): size = input("최솟값 : 3\n최댓값 : 99999\n홀 수만 입력가능 >>") try: # Str To Integer size = int(size) ...
5fd7061930a7e6497ac042c5cb4303d87c9b50be
Flaeros/leetcode
/src/sliding_window/length_of_longest_substring_replacement_424.py
1,033
3.578125
4
# dict, with count of chars # no more than 3 different chars, or sum of count of two lesser chars: c1 + c2 + c3 - max(c1,c2,c3) <= k # class Solution(object): def characterReplacement(self, s, k): window_start = 0 chars = {} result = 0 max_repeat = 0 for window_end, c in enu...
9eeb20815a0c95d8f079db807a95c402cac2809f
Flaeros/leetcode
/src/backtracking/word_search_79.py
1,525
3.5
4
# loop all board # find first char # dfs the rest of them # store visited # return true if found the last one class Solution(object): def exist(self, board, word): n = len(board) m = len(board[0]) visited = [[False for _ in range(m)] for _ in range(n)] for i in range(n): ...
ce8ffcc8dcca82fa072880c3558dde38916a77db
Flaeros/leetcode
/src/educative/longest_common_substring/longest_common_subsequence_memo.py
711
3.65625
4
def find_LCS_length(s1, s2): memo = [[-1 for _ in range(len(s2))] for _ in range(len(s1))] return find_LCS_length_rec(memo, s1, s2, 0, 0) def find_LCS_length_rec(memo, s1, s2, i, j): if i >= len(s1) or j >= len(s2): return 0 if memo[i][j] != -1: return memo[i][j] if s1[i] == s2[j...
6ce2322e31e6426fe70eaa729b34db4f95a806b3
Flaeros/leetcode
/src/educative/bounded_knapsack/count_subset_memo.py
759
3.5625
4
def count_subsets(num, sum1): dp = [[-1 for x in range(sum1 + 1)] for y in range(len(num))] return count_subsets_rec(dp, num, sum1, 0) def count_subsets_rec(dp, num, target_sum, index): if target_sum == 0: return 1 n = len(num) if n == 0 or index >= n: return 0 if dp[index][t...
6cb6d7b9c4f8e4b93761d75c24a25a2ac0576487
Flaeros/leetcode
/src/tree/dijkstra.py
1,382
3.609375
4
import math def shortest_path(tree, source, target): spt = [] tree_size = len(tree) vertices = [] for i in range(tree_size): vertices.append(math.inf) vertices[source] = 0 while len(spt) != tree_size: current_vertice = get_nearest_vertice(vertices, spt) spt.append(cu...
0c60b6e14c8baa20e4681fb8cde7c3b4b26ce73e
Flaeros/leetcode
/src/fast_slow_pointers/linked_list_has_cycle_141.py
990
3.96875
4
from typing import Optional class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: slow, fast = head, head while fast is not None and fast.next is not None: slow = slow.next ...
48db6e45634d949496ab15518edc80a0cfc901bd
Flaeros/leetcode
/src/linked/reverse_linked_list_206.py
413
3.8125
4
class ListNode(object): def __init__(self, val=0, next=None): self.val = val self.next = next # save next # change next to prev # update prev # update head to next class Solution(object): def reverseList(self, head): prev = None while head: temp = head.next ...
9c7a27fba13f26055f6f0ffb970dfba1d7e474ea
Flaeros/leetcode
/src/educative/palindromic_subsequence/lps_minimum_cuts.py
949
3.59375
4
def find_MPP_cuts(st): n = len(st) is_palindrome = [[False for _ in range(n)] for _ in range(n)] for i in range(n): is_palindrome[i][i] = True for start in range(n - 1, -1, -1): for end in range(start + 1, n): if st[start] == st[end]: if end - start == 1 or...
418caa5b1e5c94560b6be7a6f37587472d6497a3
Flaeros/leetcode
/src/educative/longest_common_substring/min_deletions_sorted_sequence_memo.py
897
3.515625
4
def find_minimum_deletions(nums): memo = {} lis = find_minimum_deletions_rec(nums, memo, -1, 0, 0) return len(nums) - lis def find_minimum_deletions_rec(nums, memo, prev, current, length): if current == len(nums): return length key = str(prev) + '-' + str(current) + '-' + str(length) ...
336d737f8683cb799f8e56ef9b5331073c87b217
Tookmund/ConfPy
/tktest.py
499
3.859375
4
#!/usr/bin/python3 from tkinter import * def hithere (): print("Hi there!!") def pick(): print(whichone.get()) root = Tk() whichone = StringVar() button = Button(root, text="hi there", command=hithere) button.pack() radiobutton = Radiobutton(root,text="This one?",variable=whichone, value="You Picked This one",co...
bc7d1c03a5ae5c337c9b091b8a56fc43b6407945
UM-SC2/MLworkshopF17
/session01/spamFilterBlank.py
726
3.546875
4
import numpy as np import pandas as pd from sklearn import linear_model from sklearn import model_selection emails = pd.read_csv("spambase/spambase.data", header=-1) xmail = np.array(emails.iloc[:,:-1]) ymail = np.array(emails.iloc[:,-1]) fractest = 0.2 ## Split into test and train data with model_selection.train_t...
feff46616035329d51aae73632d8ffeeeb048ae6
Yogesh-B/py4e
/week7_2.py
910
4.28125
4
#7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: #X-DSPAM-Confidence: 0.8475 #Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. ...
abdb9252eb05d9f357746d15dabbcb4a7e4da84e
Yogesh-B/py4e
/week11_2.py
185
3.65625
4
import re f_name=input("Enter file name:") fh=open(f_name) sum=0 #sum of all for l in fh: x=re.findall('[0-9]+',l) for i in x: sum+=float(i) print("Sum==",sum)
e0177a421fff8fa41783c55bb30b2567f27e505b
joseph-brennan/phycharm
/palindrome.py
2,463
3.890625
4
import unittest def palindrome(p): value = p if value is None: return False if value == "": return True if len(value) == "": return True if value[0] == value[len(value) - 1]: return palindrome(value[1:len(value) - 1]) else: return False def remov...
9235d351ab090501f7595dd47530ca46f1ecfe23
ankita1329/adventure-text-game
/adventure_gamee.py/adventure_gamee.py
4,435
3.734375
4
import time import random enemy = ["vampire", "werewolve", "hybrid", "witch"] demon = random.choice(enemy) items = [] def print_pause(message): print(message) time.sleep(2) def restart_game(): if "mundanes" in items: items.remove("mundanes") response = input("Would you like to play again? (y...
73b9c3f80df256ac112209540e3c3244d9b10d80
collinabidi/ca_semester_project
/example.py
1,939
4.15625
4
from functional_units import * # make_instruction takes an input line split by spaces and returns an Instruction # object with the appropriate parameters as defined by Instruction class def make_instruction(input_list): return Instruction(input_list) # Example of how to use make_instruction() function # Let's ma...
4bad58e4403f7c5ec0b459682da2f969c18f09bb
damianChoi/PSAD
/ch4/4.7 Introduction: Visualizing Recursion.py
751
3.953125
4
def tree(branchLen, t, r): if branchLen > 5: t.pencolor('brown') if branchLen <= 30: t.pencolor('green') t.width(branchLen//10) t.forward(branchLen) if branchLen <= 20: t.dot(10, "red"); angle = r.randrange(15, 45) t.right(angle) ...
de050928938662067aa6bc9664cc22d2d759b996
damianChoi/PSAD
/ch4/test5.py
615
4.09375
4
alist = [0]*6 def returnNone(anyList): """ :param anyList: any list object of which length is greater than zero :return: None This function is used to show how arguments are changed in place in the function. The object reference is passed to the function parameters. They can't be changed withi...
1ab47c9a34c8bda365a032df4a52f153a5309025
pbaldera/practice
/message.py
203
3.96875
4
message = input("Tell me what you are learning about the chapter: ") def display_message(message): """Display sentence provided by user""" print(f"{message.title()}") display_message(message)
32a28d3d489ec8e4ffae573c152102e0e8432cbc
L1ves/stepic
/12_Happy_ticket.py
1,217
4.15625
4
Паша очень любит кататься на общественном транспорте, а получая билет, сразу проверяет, счастливый ли ему попался. Билет считается счастливым, если сумма первых трех цифр совпадает с суммой последних трех цифр номера билета. Однако Паша очень плохо считает в уме, поэтому попросил вас написать программу, которая провер...
dd8407969d9ae6fde39a2d1e2fc05b3da63b8e82
pavelburundukov/algorithms
/homework2/exercise3.py
410
4
4
# 3. Сформировать из введенного числа обратное по порядку входящих в него цифр и вывести на экран. # Например, если введено число 3486, то надо вывести число 6843. x = int(input("Enter a number: ")) out = "" for i in range(len(str(x))): out += str(x // (10 ** i) % 10) print(str(out))
bcb8b1f1a0f9fcefd99a74490fe6b134e4abbf27
pavelburundukov/algorithms
/homework2/exercise4.py
378
3.921875
4
# 4. Найти сумму n элементов следующего ряда чисел: 1 -0.5 0.25 -0.125 ...Количество элементов (n) вводится с клавиатуры. last = int(input("Введите количество элементов n: ")) x = 1 s = 1 for i in range(1,last): x /= -2 print(x) s += x print("Сумма: " + str(s))
2511ac3425c92c92039e738a63ba74fd93535676
sasha39612/Algoritm_on_Pyhont_MFTI
/Exercise_7_F_MFTI.py
115
3.921875
4
a = int(input()) b = int(input()) def gcd(a, b): return a if b == 0 else gcd(b, a % b) print(gcd(a, b))
f63a699bf113d60410706507254c39f3b3cbb9e4
sasha39612/Algoritm_on_Pyhont_MFTI
/Exercise_3_B_MFT.py
272
3.765625
4
x1 = int(input("")) y1 = int(input("")) x2 = int(input("")) y2 = int(input("")) z = 0 def ferz(z): if y1 == y2: return True elif x1 == x2: return True elif x2 / x1 == y2 / y1: return True return False print(ferz(z))
045925d7d1da4d3b8e758ed629e8694083e8c321
sasha39612/Algoritm_on_Pyhont_MFTI
/Exercise_8_5_MFTI.py
629
3.921875
4
import turtle turtle.shape("turtle") def minkovskogo_draw(l, n): if n == 0: turtle.forward(l) else: minkovskogo_draw(l / 8, n - 1) turtle.left(90) minkovskogo_draw(l / 8, n - 1) turtle.right(90) minkovskogo_draw(l / 8, n - 1) turtle.right(90) ...
fcec55d73c452c159e2a30decd8932bb432054cb
sasha39612/Algoritm_on_Pyhont_MFTI
/Exercise_3_A_MFTI.py
180
3.65625
4
n = int(input("Введите трехзначное число: ")) sum = 0 digin = 1 while n > 0: digin = n % 10 sum = sum + digin n = n // 10 print(sum)
104d4316fb09373ce807eba05ac7602e2b5b5431
sasha39612/Algoritm_on_Pyhont_MFTI
/Exercise_6_G_MFTI.py
353
3.953125
4
from math import sqrt z = 0 x, y, r = map(int, input("Введите данные x, y, r: ").split()) def array_search(): if r < 0: return ("Введите радиус окружности > 0: ") else: z = sqrt(x ** 2 + y ** 2) if z <= r: return "YES" return "NO" print(array_search())
c27b2a719a927ca3d7196a123c69d660926ba1d5
akshat-harit/matasano-crypto-challenges
/set1/challenge5.py
685
3.515625
4
#!/usr/bin/env python ''' Functions for repeating-key XOR''' def hex_byte(byte): out = hex(byte) out = out[2:] if len(out) == 1: out = '0' + out return out def hex_text(inp): out = [] for byte in inp: out.append(hex_byte(byte)) return ''.join(out) def encrypt(key, inp): ...
88697eeecedfee92f1fc9898280cd778e968a055
dgansen/cs-module-project-hash-tables
/hashtable/whiteboard.py
437
3.5
4
a = [ [8, [4]], [[90, 91], -1, 3], [9, 62], [[-7, -1, [-56, [-6]]]], [201], [[76, 0], 18], ] def recurSum(arr): s = 0 compare_set = set() for elem in arr: if type(elem) == list: s += recurSum(elem) else: comp...
5685bf1234f969f14916a611016f1ce5f7e5cfc9
leigon-za/Learning_Python
/6_9_dictionary_looping_keyvalue_pairs2y.py
355
4.09375
4
fav_language = { 'jen' : 'python', 'sarah' : 'c', 'edward' : 'ruby', 'phil' : 'python', } friends = ['phil','sarah'] for name in fav_language.keys(): print(name.title()) if name in friends: print(" Hi " + name.title() + ", I see your favorite programming language is" ...
f79ee42cbbb3d8f6e6171edd43d0d662bf1aa36a
leigon-za/Learning_Python
/10_11_using_exceptions_to_prevent_crashes.py
468
4.15625
4
print("Give me two numbers and I will divide them") print("Enter 'q' to quit") while True: first_number = input("\nFirst Number: ") if first_number == 'q': break second_number = input("Second number: ") if second_number == 'q': break answer = int(first_number) / int(second_number) ...
c4e711d1bbc3a7709a51aecfd30d94333aa3c787
wangcaicai-666/PythonDemo
/selenium_20190727/test_day_01/mewDay_01/day_01_class.py
246
3.71875
4
#__author: yaomingxi #__date: 2019-08-02 #定义类Class class MyClass: def __init__(self,a,b): self.a = int(a) self.b = int(b) def sub(self): return self.a - self.b k = MyClass(9,7) y = k.sub() #print(y)
ec2512be8dddc9fcdc52ecfe9de98be6d520e6a6
wangcaicai-666/PythonDemo
/selenium_20190727/test_day_01/mewDay_01/day_print.py
272
3.703125
4
#__author: yaomingxi #__date: 2019-08-02 name = 'danan' age = '25' print("name is :"+name +" age is :"+str(age)) print("name is :%s age is :%s" % (name,age)) print("name is :{} age is :{}".format(name,age)) print("name is :{1} age is :{0}".format(age,name))
e2713e79e315df53063cd744dedf703d408194b0
MatthewWolff/CMU_Computational_Genomics_Final_Project
/code/graph.py
2,032
3.53125
4
from typing import Dict, Set from itertools import product def get_components(adjacency_dict: Dict[str, Set]) -> Dict[str, int]: """ Enumerate the disconnected components in a graph :param adjacency_dict: the graph in the form of Dict[Set] :return: a dictionary mapping a node in each components to the...
d0b515feacd53f75b9733a0573c23b5f0fd02951
hannahwhitmore/Portfolio
/socialnetwork.py
2,479
3.765625
4
class User: def __init__(self, user_name, user_id): self.user_name = user_name self.user_id = user_id self.connections = [] def add_connections(self, connection_id): self.connections.append(connection_id) def userName(self): return self.user_name def getConnections(self): return ...
7548375d2f3622c5ccdf41aefcd8b7a45d48d82a
ZhengZixiang/interview_algorithm_python
/jianzhi/04.替换空格.py
532
3.78125
4
# 请实现一个函数,把字符串中的每个空格替换成"%20"。 # # 你可以假定输入字符串的长度最大是1000。 # 注意输出字符串的长度可能大于1000。 # # 样例 # 输入:"We are happy." # # 输出:"We%20are%20happy." class Solution(object): def replaceSpaces(self, s): """ :type s: str :rtype: str """ res = '' for c in s: if c == ' ': ...
dbc5ee4c373dff71955c998ba9d818b59cad534b
ZhengZixiang/interview_algorithm_python
/jianzhi/08.用两个栈实现队列.py
1,901
4.375
4
# 请用栈实现一个队列,支持如下四种操作: # # push(x) – 将元素x插到队尾; # pop() – 将队首的元素弹出,并返回该元素; # peek() – 返回队首元素; # empty() – 返回队列是否为空; # 注意: # # 你只能使用栈的标准操作:push to top,peek/pop from top, size 和 is empty; # 如果你选择的编程语言没有栈的标准库,你可以使用list或者deque等模拟栈的操作; # 输入数据保证合法,例如,在队列为空时,不会进行pop或者peek等操作; # 样例 # MyQueue queue = new MyQueue(); # # queue.push...
f60a1c88f56c21324fe48a7a2008f529b3a67a47
ZhengZixiang/interview_algorithm_python
/jianzhi/20.调整数组顺序使奇数位于偶数前面.py
657
3.8125
4
# 输入一个整数数组,实现一个函数来调整该数组中数字的顺序。 # # 使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分。 # # 样例 # 输入:[1,2,3,4,5] # # 输出: [1,3,5,2,4] class Solution(object): def reOrderArray(self, array): """ :type array: List[int] :rtype: void """ i, j = 0, len(array) - 1 while i <= j: while...
f13391493b1ec485aa0daa6bb4d44d43661f3d20
ZhengZixiang/interview_algorithm_python
/jianzhi/03.二维数组中的查找.py
977
3.6875
4
# 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。 # # 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 # # 样例 # 输入数组: # # [ # [1,2,8,9], # [2,4,9,12], # [4,7,10,13], # [6,8,11,15] # ] # # 如果输入查找数值为7,则返回true, # # 如果输入查找数值为5,则返回false。 class Solution(object): def searchArray(self, array, target): """ :typ...
155df03483b86ac139f4d27e64cc6966230d3e72
ZhengZixiang/interview_algorithm_python
/jianzhi/15.数值的整数次方.py
771
4
4
# 实现函数double Power(double base, int exponent),求base的 exponent次方。 # # 不得使用库函数,同时不需要考虑大数问题。 # # 注意: # # 不会出现底数和指数同为0的情况 # 当底数为0时,指数一定为正 # 样例1 # 输入:10 ,2 # # 输出:100 # 样例2 # 输入:10 ,-2 # # 输出:0.01 class Solution(object): def Power(self, base, exponent): """ :type base: float :type exponent: int ...
1cf028b0f30782731925e51b28927d3bf55c81a3
ZhengZixiang/interview_algorithm_python
/jianzhi/34.二叉搜索树的后序遍历序列.py
880
3.5625
4
# 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。 # # 如果是则返回true,否则返回false。 # # 假设输入的数组的任意两个数字都互不相同。 # # 样例 # 输入:[4, 8, 6, 12, 16, 14, 10] # # 输出:true class Solution: def verifySequenceOfBST(self, sequence): """ :type sequence: List[int] :rtype: bool """ if not sequence: return...
b6fc473943f450b0582a17906eea0651bf58c65c
ZhengZixiang/interview_algorithm_python
/leetcode/editor/cn/[37]解数独.py
2,143
3.5625
4
# 编写一个程序,通过已填充的空格来解决数独问题。 # # 一个数独的解法需遵循如下规则: # # # 数字 1-9 在每一行只能出现一次。 # 数字 1-9 在每一列只能出现一次。 # 数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。 # # # 空白格用 '.' 表示。 # # # # 一个数独。 # # # # 答案被标成红色。 # # Note: # # # 给定的数独序列只包含数字 1-9 和字符 '.' 。 # 你可以假设给定的数独只有唯一解。 # 给定数独永远是 9x9 形式的。 # # Related Topic...
81af9e8421ac5f9e71cba1631d331f7bce5c83fd
RishabhGoswami/Algo.py
/Pair sum in bst.py
1,339
3.75
4
class Node: def __init__(self,data): self.data=data self.left=None self.right=None def pair(root,target): s1=[] s2=[] temp=root while(temp): s1.append(temp) temp=temp.left temp=root while(temp): s2.append(temp) temp=temp.right ...
2044548574bbe5eef616efcb74d52b7accbad874
RishabhGoswami/Algo.py
/O(1) Connect nodes at same.py
2,945
3.8125
4
class Node: def __init__(self,data): self.left=None self.right=None self.nextRight=None self.data=data def getn(p): temp = p.nextRight while (temp != None): if (temp.left != None): return temp.left if (temp.right != None): retu...
e84d8280ff0d99328d0a0cd88bb3ccea06ac0004
RishabhGoswami/Algo.py
/Zig zag traversal.py
903
3.84375
4
class Node: def __init__(self,data): self.left=None self.right=None self.nextRight=None self.data=data def zigzag(root): s1=[] s2=[] s1.append(root) while(len(s1)>0 or len(s2)>0): while(len(s1)>0): t=s1[-1] s1.pop(-1) ...
173fda912a41339353e6c5bf07560e2451d2136f
RishabhGoswami/Algo.py
/Reverse in k group.py
1,299
3.796875
4
class Node: def __init__(self,data): self.data=data self.next=None class Linke: def __init__(self): self.head=None def push(self,data): newp=Node(data) newp.next=self.head self.head=newp def reverse(self,k): dummy=Node(0) ...
ae6e9b0881cd1bdabff0c2f76c915988bb5778b9
RishabhGoswami/Algo.py
/Sort k nearly array.py
383
3.671875
4
import heapq def sort(arr,k): l=arr[:k+1] heapq.heapify(l) start=0 for i in range(k+1,len(arr)): arr[start]=heapq.heappop(l) heapq.heappush(l,arr[i]) start+=1 while(l): arr[start]=heapq.heappop(l) start+=1 for i in range(0,len(arr)): prin...
932a3961e057ed51e7ecd984208ec1843a75212a
RishabhGoswami/Algo.py
/Is bst .py
946
3.8125
4
class Node: def __init__(self,data): self.data=data self.left=None self.right=None def insert(root,data): if(root is None): return Node(data) if(root.data<data): root.right=insert(root.right,data) else: root.left=insert(root.left,data) return ...
3677277cd289fc5f8b72a62ba55aa8c3e1786fc8
RishabhGoswami/Algo.py
/preorder iterative.py
561
3.734375
4
class Node: def __init__(self,data): self.data=data self.left=None self.right=None def inorder(root): s=[] while(len(s)>0): a=s.pop() print(a.data) if(a.right): s.append(a.right) if(a.left): s.append(a.left) ...
6387898ac51291cb2db532cbb9e317cc1dbc7a25
RishabhGoswami/Algo.py
/First node of loop.py
1,039
3.8125
4
class Node: def __init__(self,data): self.data=data self.next=None class Linke: def __init__(self): self.head=None def push(self,data): newp=Node(data) newp.next=self.head self.head=newp def printl(self): temp=self.head ...
d78c648c6105e61f1d8fb43dffc34d1cdb16bee6
RishabhGoswami/Algo.py
/Chech for bst.py
920
3.71875
4
class Node: def __init__(self,data): self.data=data self.left=None self.right=None def convert(root): prev=Node(-1) return final(root,prev) def final(root,prev): if(root is None): return True left=final(root.left,prev) if(root.data<=prev.data): ...
430a91fd4502e3c5bb6a10653ce3c8e961e4211b
RishabhGoswami/Algo.py
/Merge 2 bst.py
1,785
3.890625
4
class newNode: # Constructor to create a new node def __init__(self, data): self.data = data self.left = None self.right = None def merge(root1,root2): s1=[] s2=[] temp=root1 while(temp): s1.append(temp) temp=temp.left temp=root2 while(temp): s2.append(temp) ...
5f00477a2b5d3ee2f451474a778723ba94ac17d1
RishabhGoswami/Algo.py
/Rotate matrix.py
386
3.984375
4
def rotate(mat): for i in range(0,len(mat)-1): for j in range(i+1,len(mat)): mat[i][j],mat[j][i]=mat[j][i],mat[i][j] i=0 while(i<len(mat)): for j in range(0,len(mat)//2): mat[i][j],mat[i][len(mat)-1-j]=mat[i][len(mat)-1-j],mat[i][j] i=i+1 return mat mat=[[...
c533220e5dd01411ffca2944bad04872a8253439
RishabhGoswami/Algo.py
/Longest pal seq.py
380
3.59375
4
def longest(s1,s2,n,m): t=[[0 for j in range(m+1)] for i in range(n+1)] for i in range(1,n+1): for j in range(1,m+1): if(s1[i-1]==s2[j-1]): t[i][j]=1+t[i-1][j-1] else: t[i][j]=max(t[i][j-1],t[i-1][j]) a=t[n][m] print(a) s1='a...
417ef7e845b9d597cf179c724843fbb746facb3a
Pyt-Sergei/sqlite3
/BD/base.py
5,237
3.734375
4
import sqlite3 as sql import sys con=sql.Connection('student.sqlite') cur=con.cursor() try: for x in cur.execute("select sqlite_version()"): print(x) cur.execute("CREATE TABLE 'Direction' (id_direction INTEGER PRIMARY KEY AUTOINCREMENT,code VARCHAR(32) NOT NULL,full_name VARCHAR(256) NOT NULL,sho...
ae02219070476c7b2fef0fcd155df706cb420ec0
Harshvartak/Lab
/Harsh/Harsh/ostl pracs1.py
673
3.75
4
str1="Hello world" str2 = str1[6:] print(str1) print(str1[0:5]) print(str2) li=['hi','hello',34,'python'] print(li) print(li[0]) li.append('there') print(li) li.insert(2,'bang') print(li) li.remove(34) print(li) for i in li: print(i) t1=(1,2,3,4,5,6,7) t2=(55,3,22,45,12) print(t1) print(t2) t3=t1+t2 print(t3) pr...
d7069375730b0119089f11f795e4354da1cd03f2
balilarder/leetcode
/problem/p_0021_merge_two_sorted_lists/solutions.py
1,345
3.96875
4
from typing import Optional # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None def __repr__(self): return str(self.val) class Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> Optional[ListNode]: if l1...
077d267e331a8dc0265c4c12ab9cb38cfe2f7ee2
MfonUdoh/Mazer
/game.py
4,351
3.71875
4
class Game(object): def __init__(self): #Board width self.size = 10 self.minMoves = 0 self.level = 0 self.marksLocations = [] self.wallsLocations = [] self.empties = self.size ** 2 - len(self.wallsLocations) - len(self.marksLocations) self.maxLevels =...
c45c7cdf685e03b4179bffb22172006c198eeb17
deacoon/Euler-challenges
/eulerChallenge006.py
351
3.78125
4
def sum_of_squares(last_number): if last_number == 1: return 1 return last_number**2 + sum_of_squares(last_number-1) def square_of_sum(last_number): return sum(range(1, last_number+1))**2 def difference(number): return square_of_sum(number) - sum_of_squares(number) print(...