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
3abd1b6657ee864f9a4dc1a45158936ef3a1ff22
Wang-Yann/LeetCodeMe
/python/_1001_1500/1442_count-triplets-that-can-form-two-arrays-of-equal-xor.py
2,328
3.59375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-07-09 23:21:14 # @Last Modified : 2020-07-09 23:21:14 # @Mail : lostlorder@gmail.com # @Version : alpha-1.0 """ # 给你一个整数数组 arr 。 # # 现需要从数组中取三个下标 i、j 和 k ,其中 (0 <= i < j <= k < arr.length) 。 # # a ...
8add24e7751b54d5ee885281fbdbb58e143e3de3
Wang-Yann/LeetCodeMe
/python/_1001_1500/1110_delete-nodes-and-return-forest.py
2,443
3.625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-07-02 08:00:00 # @Last Modified : 2020-07-02 08:00:00 # @Mail : lostlorder@gmail.com # @Version : alpha-1.0 """ # 给出二叉树的根节点 root,树上每个节点都有一个不同的值。 # # 如果节点值在 to_delete 中出现,我们就把该节点从树上删去,最后得到一个森林(一些不相交的树构...
0f58060c1424f74b7a7ed48fbc00e562fb1ada15
Wang-Yann/LeetCodeMe
/python/_0001_0500/0209_minimum-size-subarray-sum.py
1,964
3.609375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rocky Wayne # @Created : 2020-04-16 20:58:05 # @Last Modified : 2020-04-16 20:58:05 # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 """ # 给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的连续子数组,并返回其长度。如果不存在符合条件的连续子数组,返回 # 0。 # ...
d28c5a8bedf8deaeee7c92065d2337ec7809ad5a
Wang-Yann/LeetCodeMe
/python/CodingInterviews_2/43_1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.py
2,138
3.65625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-05-10 18:03:17 # @Last Modified : 2020-05-10 18:03:17 # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 # 输入一个整数 n ,求1~n这n个整数的十进制表示中1出现的次数。 # # 例如,输入12,1~12这些整数中包含1 的数字有1、10、11和12,1一共出现了5次。 # # # ...
901f23393eb40a4542aa5a9d58e2e54410623e2f
Wang-Yann/LeetCodeMe
/python/CodingInterviews_2/17_da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.py
982
3.609375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rocky Wayne # @Created : 2020-05-02 22:01:25 # @Last Modified : 2020-05-02 22:01:25 # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 # 输入数字 n,按顺序打印出从 1 到最大的 n 位十进制数。比如输入 3,则打印出 1、2、3 一直到最大的 3 位数 999。 # # 示例 1: # # 输入: n = 1 #...
2aa66db9d5887f209110262cbfe3b3325849a6cf
Wang-Yann/LeetCodeMe
/python/_0501_1000/0784_letter-case-permutation.py
1,677
3.578125
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rocky Wayne # @Created : 2020-04-12 20:15:50 # @Last Modified : 2020-04-12 20:15:50 # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 """ # 给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。 # # # 示例: # 输入: S = "a1b2" # ...
6100b0ba2a34c0314bf606cc3cd7926fb6ff928c
Wang-Yann/LeetCodeMe
/python/_1501_2000/1662_check-if-two-string-arrays-are-equivalent.py
1,986
3.6875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2021-02-25 09:49:16 # @Last Modified : 2021-02-25 09:49:16 # @Mail : lostlorder@gmail.com # @Version : 1.0 # 给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同,返回 true ;否则,返回 false 。 # # 数组表示的字符串 是由数组中的所有元素 按顺序 连接形成...
9fff13136de7240d47f0f72cb58c6f2477a87b26
Wang-Yann/LeetCodeMe
/python/_0001_0500/0179_largest-number.py
1,680
3.5625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rocky Wayne # @Created : 2020-05-01 20:12:02 # @Last Modified : 2020-05-01 20:12:02 # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 """ # 给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数。 # # 示例 1: # # 输入: [10,2] # 输出: 210 # # 示例 2: # # 输入:...
42fb40144fd432870e7ceba0e5f1ea108a2f5406
Wang-Yann/LeetCodeMe
/python/LCP/LCP 04_broken-board-dominoes.py
2,817
3.5
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-07-15 23:21:43 # @Last Modified : 2020-07-15 23:21:43 # @Mail : lostlorder@gmail.com # @Version : 1.0.0 """ # 你有一块棋盘,棋盘上有一些格子已经坏掉了。你还有无穷块大小为1 * 2的多米诺骨牌,你想把这些骨牌不重叠地覆盖在完好的格子上,请找出你最多能在棋盘上放多少块 # 骨牌?这些骨牌可以横着或...
da9d43d6a2af156a8077e79af5dfdcdd2595b3ff
Wang-Yann/LeetCodeMe
/python/_0001_0500/0367_valid-perfect-square.py
1,245
3.640625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-04-30 15:38:16 # @Last Modified : 2020-04-30 15:38:16 # @Mail : rock@get.com.mm # @Version : alpha-1.0 """ # 给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 False。 # # 说明:不要使用任何内置的库函数,如 sqrt。 # # 示例 ...
0e6dbee4eb7de6dfe452c1b7ec9abd6478c20180
Wang-Yann/LeetCodeMe
/python/_1501_2000/1798_maximum-number-of-consecutive-values-you-can-make.py
2,158
3.65625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2021-03-22 02:40:38 # @Last Modified : 2021-03-22 02:40:38 # @Mail : lostlorder@gmail.com # @Version : 1.0 # 给你一个长度为 n 的整数数组 coins ,它代表你拥有的 n 个硬币。第 i 个硬币的值为 coins[i] 。如果你从这些硬币中选出一部分硬币,它们的 # 和为 x ,那么称,你可以 构造 ...
72beb1420516bae46399ab7535920a1b8a979c37
Wang-Yann/LeetCodeMe
/python/_0001_0500/0035_search-insert-position.py
3,248
3.6875
4
#!/usr/bin/env python # -*- coding:utf-8 -*- # @Author : Rock Wayne # @Created : 4/4/20 9:43 PM # @Last Modified : 4/4/20 9:43 PM # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 # # 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 # # 你可以假设数组中无重复元素。 # # 示例 1: # # 输入: [1,3,...
8582eb7b43fbd4552d7fe354e0b0f89dbc270ed3
Wang-Yann/LeetCodeMe
/python/_1001_1500/1176_diet-plan-performance.py
2,941
3.5625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-08-05 15:11:01 # @Last Modified : 2020-08-05 15:11:01 # @Mail : lostlorder@gmail.com # @Version : alpha-1.0 """ # 你的好友是一位健身爱好者。前段日子,他给自己制定了一份健身计划。现在想请你帮他评估一下这份计划是否合理。 # # 他会有一份计划消耗的卡路里表,其中 calories[i]...
ca5bee00571aa9e1601f3f5b118ee456e19e72db
Wang-Yann/LeetCodeMe
/python/_0001_0500/0343_integer-break.py
2,804
3.5625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-05-04 23:07:24 # @Last Modified : 2020-05-04 23:07:24 # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 """ # 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。 # # 示例 1: # # 输入: 2 # 输出: 1 # 解释:...
2642c7772057c9a736088dabb09438964f97220a
Wang-Yann/LeetCodeMe
/python/_1501_2000/1516_move-sub-tree-of-n-ary-tree.py
5,445
3.859375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-08-07 19:04:36 # @Last Modified : 2020-08-07 19:04:36 # @Mail : lostlorder@gmail.com # @Version : alpha-1.0 """ Given the root of an N-ary tree of unique values, and two nodes of the tree p and q. You s...
7b121ea1c3a3cdda549af9a37f719adb70ddbb45
Wang-Yann/LeetCodeMe
/python/_1001_1500/1128_number-of-equivalent-domino-pairs.py
2,024
3.515625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-07-02 18:00:00 # @Last Modified : 2020-07-02 18:00:00 # @Mail : lostlorder@gmail.com # @Version : alpha-1.0 """ # 给你一个由一些多米诺骨牌组成的列表 dominoes。 # # 如果其中某一张多米诺骨牌可以通过旋转 0 度或 180 度得到另一张多米诺骨牌,我们就认为这两张牌是等价的。 ...
3a722f051da81efdb7559d3e5142b861fe373934
Wang-Yann/LeetCodeMe
/python/_0001_0500/0313_super-ugly-number.py
3,189
3.609375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-05-04 22:37:05 # @Last Modified : 2020-05-04 22:37:05 # @Mail : lostlorder@gamil.com # @Version : alpha-1.0 # 编写一段程序来查找第 n 个超级丑数。 # # 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数。 # # 示例: # # 输入: n = 12, pr...
8c1c0a830b84259d50350738e43bfecb1fcce561
Wang-Yann/LeetCodeMe
/python/CrackingTheCodingInterview_6/10_09_sorted-matrix-search-lcci.py
1,729
3.515625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : Rock Wayne # @Created : 2020-07-13 14:28:38 # @Last Modified : 2020-07-13 14:28:38 # @Mail : lostlorder@gmail.com # @Version : alpha-1.0 """ # 给定M×N矩阵,每一行、每一列都按升序排列,请编写代码找出某元素。 # # 示例: # # 现有矩阵 matrix 如下: # # [ # [1, 4,...
e4e1dc0506d440da8f124bdc089e9b965792617a
zhengruiguo/GuessNumberGame
/GuessNumberGame.py
1,968
3.890625
4
''' 猜数字游戏 by 郑瑞国 ''' import random #引入模块random print('猜数字游戏') #打印输出'猜数字游戏' print(''' Game Start!!! ''') #带格式打印输出'Game Start!!!' level = 0 #level参数赋值为0,用来存当前为第几关 try_time = 5 #try_time参数赋值为5,用来控制可猜测次数 while level < 100: ...
19eb4162a092c37319cccc4e1743978ac34653ed
ITlearning/ROKA_Python
/2021_03/03_14/CH04_Problem/029_If_string02.py
519
4.125
4
# 이 문제를 해결하려면 다음과 같이 코딩한다. # if 조건문과 여러 줄 문자열(3) number = int(input("정수 입력 > ")) if number % 2 == 0 : print("""입력한 문자열은 {}입니다.\n{}는 짝수입니다.""".format(number,number)) else : print("""입력한 문자열은 {}입니다.\n{}는 홀수입니다.""".format(number,number)) # 이렇게 하면 코드가 다행히 잘 보이긴 하는데, 길게 적음으로 인해 다소 복잡해보일수가 있다.
4f590e9c3667cb5e118f1a35ec41860f90f04d4c
ITlearning/ROKA_Python
/2021_03/03_21/007_File_Closed02.py
426
3.5
4
# 파일 처리 중간에 예외 발생 try: file = open("info.txt", "w") # 여러 가지 처리를 수행한다. 예외.발생해라ㅋㅋ() # 파일을 닫습니다 file.close() except Exception as e: print(e) print("# 파일이 제대로 닫혔는지 확인하기") print("file.closed:", file.closed) # 예외가 발생할경우 파일을 제대로 닫지 못하고 예외가 출력이 된다.
fac98268fcd20d442c288054a955ac2c792e3e25
ITlearning/ROKA_Python
/2021_03/03_21/011_Try_Return02.py
456
3.65625
4
# finally 키워드 활용 def write_text_file(file_name, text): try: file = open(file_name, "w") return file.write(text) except Exception as e: print(e) finally: file.close() write_text_file("text.txt", "안녕하세요") # 파일을 여는 것까지는 try 문에서 실행되었지만, return 을 만나 try ...
b92dca9fef275130832064138cfeef38e5abba69
ITlearning/ROKA_Python
/2021_03/03_08/CH02/009_Another.py
1,055
3.859375
4
# 대소문자 바꾸기 a = "Hello Python Programming" print(a.upper()) print(a.lower()) # 비파괴적 함수임 # 문자열 양옆의 공백 제거하기 input_a = """ 안녕하세요 문자열의 함수를 알아봅시다 """ print(input_a) print(input_a.strip()) # 문자열의 구성 파악하기 print("TrainA10".isalpha()) print("10".isdigit()) # 문자열 찾기 output_a = "안녕안녕하세요".find("안녕") # 왼쪽부터 찾기 시작해서 처음 등장...
3adec44c0832f4e213747dff5f86d3ad1a2bc439
ITlearning/ROKA_Python
/2021_03/03_10/CH04/004_For_List.py
185
3.53125
4
# for 반복문과 리스트 # 리스트를 선언합니다 array = ["안녕하세요", "Hello"] # 리스트에 반복문을 적용합니다 for element in array : print(element)
0a28f875e5547c966cd8b970d947d940f39b08d6
moosmann/python
/tests/elr_model.py
558
3.75
4
# Script to calculate air temperature from ELR # First import required modules import sys , os # Operating system modules # Now define our function . Variables in brackets are the inputs def model ( temperature , altitude ): #calculate modelled temperature newtemperature = temperature - 0.00649 * altitude ...
b12b51ee6edf7d4ef6f874940c00ffd4afa8bbef
0gravity000/IntroducingPython
/04/0407.py
8,544
3.515625
4
# 4.7 関数 # 関数の定義 def宣言 # 関数の呼び出し # 何もしない関数の定義 def do_nothing(): pass # 何もしない関数の呼び出し do_nothing() # 引数のない関数宣言 def make_a_sound(): print('quack') # 引数のない関数の呼び出し make_a_sound() # 引数なし、戻り値あり関数の宣言 def agree(): return True if agree(): print('Splendid!') else: print('That was unexpected') # 引数あり、戻り値...
72b0856989a4f2e3ea8d8d4b2bd44ec67065feb6
0gravity000/IntroducingPython
/06/0604.py
1,027
3.5625
4
# 6.4 メソッドのオーバーライド # 親クラス class Car1(): def exclaim(self): print("I'm a Car!") # 子クラスでexclaim()メソッドをオーバーライドする。 # exclaim()の振る舞いが書き換えられる class Yugo1(Car1): def exclaim(self): print("I'm a Yugo! Much like a Car, but more Yugo-ish.") # オブジェクト(インスタンス)を作る give_me_a_car = Car1() give_me_a_yugo = Yu...
dc051bfcc3f1389f8a352d822a1d9c58f66dbef2
0gravity000/IntroducingPython
/04/040703.py
529
3.890625
4
# 4.7.3 デフォルト引数値の指定 def menu(wine, entree, dessert='pudding'): return('wine': wine, 'entree': entree, 'dessert': dessert) menu('chardonnay', 'chicken') menu('dunkelfelder', 'duck', 'doughnut') # バグがあるコード def buggy(arg, result=[]): result.append(arg) print(result) buggy('a') buggy('b') # ['b']にならないといけな...
b1a87a718955cd4a24db14beddea90e3bc1448f9
0gravity000/IntroducingPython
/04/0406.py
3,318
4.125
4
# 4.6 内包表記 # 内包表記はひとつ以上のイテレータからPythonデータ構造をコンパクトに作れる # 4.6.1 リスト内包表記 # [expression for item in iterable] number_list = [number for number in range(1, 6)] number_list # [1, 2, 3, 4, 5] number_list = [number-1 for number in range(1, 6)] number_list # [0, 1, 2, 3, 4] # 内包表記でない別の書き方 その1 number_list = [] number_list.appe...
240bf5eb01603c73b773ae7bda168bc2407e28a5
0gravity000/IntroducingPython
/06/0609.py
1,114
4.3125
4
# 6.9 非公開属性のための名前のマングリング # Pythonは、クラス定義の外からが見えないようにすべき属性の命名方法を持っている # 先頭にふたつのアンダースコア__を付ける class Duck(): def __init__(self, input_name): self.__name = input_name #外からアクセスできないプロパティ @property def name(self): #ゲッター print('inside the getter') return self.__name @name.setter d...
b8d0130e85142df007aed7951d6ec07988bddc9a
0gravity000/IntroducingPython
/04/040601.py
1,312
4.3125
4
# 4.6.1 リスト内包表記 number_list = [] for number in range(1, 6): number_list.append(number) number_list number_list = list(range(1, 6)) number_list # リスト内包表記を使った Pythonらしいコード # [ expression for item in iterable ] number_list = [number for number in range(1, 6)] number_list number_list = [number -1 for number in rang...
08e68693b139150e7bb4f9bf6c46856490d491d5
njavid/RetreivalProject3
/Plot.py
566
3.65625
4
from sklearn.decomposition import PCA import numpy as np import matplotlib.pyplot as plt class Plot: def plot(self, clusters, X, cluster_type): pca = PCA(n_components=2) two_dim = pca.fit_transform(X) scatter_x = two_dim[:, 0] # first principle component scatter_y = two_dim[:, 1]...
da7a84916a8270ed8020c19b20c9ce1898b9b099
bektoy/fractals
/5.py
244
3.8125
4
import turtle def draw(n,l): turtle.shape('turtle') if n==0: turtle.forward(l) else: turtle.left(45) draw(n - 1, l / 2) turtle.right(90) draw(n - 1, l / 2) turtle.left(45) draw(5,1000)
878988709b11f9ff3bfd87e848b79977241dea9f
mansi135/mansi_prep
/practice/search_rotation_point.py
715
3.640625
4
#given a sorted , rotated array, find the rotation point #Hint-if mid element is less than last, rotation point is in left half, else its in right half def search_rotation(arr,first,last): while(first<=last): mid=int((first+last)/2) if arr[mid] < arr[mid+1] and arr[mid] < arr[mid-1]: ...
9fe26472b3e65060b858040cdacc132387283fbd
mansi135/mansi_prep
/practice/new_problems.py
2,850
4.1875
4
# Given two sorted lists, return the interesection (ie the common elements b/w the two sorted lists) # For example given l1 = [1, 2, 3] and l2 = [2, 3, 5, 10] (they can be different sizes) # return [2, 3] # LINEAR TIME # 4 def get_intersection(l1, l2): pass # given two sorted lists l1 and l2, merge them such that ...
7f69c02b044b9b6ea12ab6329c64376bd68153e1
mansi135/mansi_prep
/practice/find_substring.py
629
3.984375
4
# Check if the substring sub exists in s. For example, find_substring("hello buffalo", "o b") == True # Redo- flags an partial match def find_substring(s, sub): flag=False j=0 for i in range(len(s)): if s[i]==sub[j]: k=i while j<len(sub) and k<len(s): if sub[j...
be9289478e06e876b3e9e503a156998ba8a63949
viniciusdepadua/Lista-2
/questao11.py
465
3.5
4
def speak_formation_futsal(*arguments, **keywords): for args in arguments: print(args) print("-" * 40) keys = sorted(keywords.keys()) for key in keys: print(key + ":" + keywords[key]) speak_formation_futsal("There will be 5 player.", "The coach chooses them.", "The team has to win.", ...
f5751f00a394f4c4ca7d6d26fdd3b9397bee6aad
j-gilkey/nyc-ds-111819-lectures
/Mod_1/Calculator_class/descriptive.py
1,207
3.6875
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Sep 4 14:25:52 2019 @author: swilson5 """ import math class Calculator: def __init__(self, data): self.set_data(data) def set_data(self, data): self.data = sorted(data) self.length = len(self.data) self.mean ...
bf5541aff5d60357f0a736f7689cfeb3aa8b46e7
snidarian/Algorithms
/factorial_recursion.py
429
4.46875
4
#! /usr/bin/python3 # Factorial recursive algorithm import argparse parser = argparse.ArgumentParser(description="Returns factorial of given integer argument") args = parser.add_argument("intarg", help="Int to be factored", type=int) args = parser.parse_args() def factorial_recursive(n): if n == 1: r...
92a1c5435a90429a79c84f309779cf2aa446c59f
KelseyMullin/reddit-daily-programmer
/369HexColors.py
856
3.734375
4
#Challenge from https://www.reddit.com/r/dailyprogrammer/comments/a0lhxx/20181126_challenge_369_easy_hex_colors/ def hex_color(red, green, blue): color = "#" color = color + pad_color(red) color = color + pad_color(green) color = color + pad_color(blue) return color def pad_color(color): hex_...
e50c1d110f61b564c8c08ffdda812c87be4e2cbd
SR-17/Python
/Premier_Programme-2.0.py
658
3.703125
4
# Cette fonction est utilitaire. Cest à dire quelle va afficher le nombre de hello world que # l'on veut. def coucou_le_monde(nbr_de_tour): while i<nbr_de_tour: print("Hello world !"); i = i+1; # Cette fonction demande a lutilisateur combien de fois il souhaite que le message sois repeté. def combien(): nbr_boucl...
a6b76a0707bbacc2a7781e43a6a93c5a08235ee5
wdhu/store1
/任务四.py
2,421
3.515625
4
import random sss=input("是否抽取优惠券:") if sss=="y" or sss=="Y": print("----商品优惠券----") coupon = [ ["机械革命", 10, 0.5], ["卫龙辣条", 20, 0.3], ["HUA WEI WATCH", 15, 0.8], ] for key, value in enumerate(coupon): print(key, value) chose = random.randint(0, len(coupon) -...
d739217c67f8f023bb4914b9c1cb7f2dc59d1894
Factumpro/HackerRank
/Python/Tutorials/10 Days of Statistics/Day_01_2.py
1,017
3.9375
4
''' 10/Day 1: Standard Deviation from statistics import median sort mean sum map a[i] - mean **2 sqrt sum_map / len_arr round ,1 ''' ''' TEST if __name__ == '__main__': #arr =[10, 40, 30, 50, 20] #arr = [2,5,2,7,4] _arr = arr _arr.sort() _len_arr = len(_arr) _mean_arr = sum(arr)/ _le...
b47632ed15679c9156067f90a74dd370c1c71071
Factumpro/HackerRank
/Python/Tutorials/30 Days of Code/Day_08.py
531
4
4
#!/usr/bin/env python3 if __name__ == '__main__': N = int(input()) names_phone_numbers = list(map(lambda _: input().split(), range(N))) phone_book = { book_name: book_phone for book_name, book_phone in names_phone_numbers } while True: try: ...
31f74928c780208dad759bc22348e84b76f22f77
Factumpro/HackerRank
/Python/Tutorials/30 Days of Code/Day_22.py
1,333
4.0625
4
#!/usr/bin/env python3 """ Binary Search Trees ------------------- """ class Node: def __init__(self, data): self.right = None self.left = None self.data = data class Solution: def insert(self, root, data): if root is None: return Node(data) else...
aa952649de3e87a99472f6cc2b92e7b2b8bf57ea
Factumpro/HackerRank
/Python/Practice/Sets/intersection.py
535
4.15625
4
''' Set .intersection() Operation https://www.hackerrank.com/challenges/py-set-intersection-operation/problem ''' ''' The .intersection() operator returns the intersection of a set and the set of elements in an iterable. Sometimes, the & operator is used in place of the .intersection() operator, but it only operate...
9cd9cb9efd74fd3e3ff798b3865ace2590249fa4
Factumpro/HackerRank
/Python/Practice/Sets/union.py
481
4.1875
4
''' Set .union() Operation https://www.hackerrank.com/challenges/py-set-union/problem ''' ''' The .union() operator returns the union of a set and the set of elements in an iterable. Sometimes, the | operator is used in place of .union() operator, but it operates only on the set of elements in set. Set is immutable...
ba19d0e69c8133afe4e1177cd0e1d6d8b41434e8
Factumpro/HackerRank
/Python/Practice/Strings/join_Capitalize.py
849
3.96875
4
'''' Capitalize! Link to problem statement: https://www.hackerrank.com/challenges/capitalize/problem You are asked to ensure that the first and last names of people begin with a capital letter in their passports. For example, alison heck should be capitalised correctly as Alison Heck. Given a full name...
a0c707e0b76709df9517d89906c45e62b4a74644
Factumpro/HackerRank
/Python/Practice/Strings/Formatting.py
350
3.953125
4
''' String Formatting https://www.hackerrank.com/challenges/python-string-formatting/problem ''' def print_formatted(number): width = len(bin(number)[2:]) for i in range (1,number+1): print (str(i).rjust(width,' '),str(oct(i)[2:]).rjust(width,' '),str(hex(i)[2:].upper()).rjust(width,' '),str(bin(i)[...
df5a21b9722700e9b401e651a905c61873d2f75f
rileyjones-stack/pythonpizza
/pizzamenu.py
11,989
4.53125
5
print("Welcome to Henderson Pizza Place! Please start your order by typing your name. ") name = input("What is your name? ") form_of_consumption = input("Delivery or pickup? Delivery is an additional $3 charge. ").lower() if form_of_consumption == 'delivery': print("Delivery it is. $3 will be added to your ...
42d6fba978a62e664aad1dbb1aa10fe161d51fab
Epic-R-R/Round-robin-tournament
/main.py
1,536
4.125
4
from pprint import pprint as pp def make_day(num_teams, day): # using circle algorithm, https://en.wikipedia.org/wiki/Round-robin_tournament#Scheduling_algorithm assert not num_teams % 2, "Number of teams must be even!" # generate list of teams lst = list(range(1, num_teams + 1)) # rotate day ...
9fca98fab7bbfaf79a3789dbcd620f5b87aff67b
ArtoriasAbW/technosphere_python_2021_spring
/SecondTask/custom_list.py
1,138
3.515625
4
class CustomList(list): def __add__(self, other): max_cl = self if len(self) >= len(other) else other min_cl = self if len(self) < len(other) else other res = CustomList(max_cl) for i in range(len(min_cl)): res[i] += min_cl[i] return res def __radd__(self, o...
f270aa6ca9e1ded23dd590e03913a3e718a5c610
colinpannikkat/pythonexercises
/exercise2.py
165
4.28125
4
number = float(input("Input Number: \n")) number = number % 2 if number == 0: print ("Your number is even!") elif number == 1: print ("Your number is odd!")
5e7bc2b2ea7e1eb2faf45710cad46bc82b2703a8
colinpannikkat/pythonexercises
/exercise6.py
344
3.84375
4
string = input("Input String:\n") string = string.replace(" ", "") list = list(string) a = int(len(list)) x = a-1 c = [] while x > -1: b = string[x] c.append(b) x = x-1 b = int(len(c)) z = list[0:a] y = c[0:b] print (z,y) if z == y: print("The string is a palendrome!\n") else: print("The string i...
4c2d0f68ea4c705fd94634763ad1fdbdf1e3f037
macronima/Coursera-Stanford-ML-Python
/ex2/costFunction.py
1,239
3.84375
4
from numpy import log from sigmoid import sigmoid import numpy as np def costFunction(theta, X,y, return_grad=False): """ computes the cost of using theta as the parameter for logistic regression and the gradient of the cost w.r.t. to the parameters.""" # Initialize some useful values m = len(y) ...
8aaf9663f3d8d5493f12ed2c0d0fc2ef48051554
waldirpires/pitagoras
/aeda/python/4-compression/rle.py
851
3.796875
4
def encode(input_string): count = 1 prev = '' lst = [] for character in input_string: if character != prev: if prev: entry = (prev,count) lst.append(entry) #print lst count = 1 prev = character else: ...
bad4024f84f4ec31cd70f322128f519270bee8aa
MarcusQuigley/Algorithmic-Toolbox
/week5dp/money_change/moneychange.py
525
3.578125
4
import sys def get_change(money): coins = [1,3,4] minimumCoins = [] #counter = 1 minimumCoins.append(0) for m in range(1, money+1): minimumCoins.append(sys.maxsize) for coin in coins: if coin > m: break numCoins = minimumCoins[m - coin] + 1 ...
d3d4d1e8d88846bc5c8701279849e4b69451edfc
Francimary/Algoritmos
/Bubble_Insert_Merge_Quick_utilizado.py
6,821
3.96875
4
import random import time import copy #Criacao da lista lista_aleatoria = [random.randint(-0, 11000) for c in range(1000)] def bubbleSort(listab): for bolhinha in range(len(listab)-1,0,-1): for i in range(bolhinha): if listab[i]>listab[i+1]: #No Python, nao precisa...
fc06c4a94f682e89bd661d602f9803aeaa7d6b1d
SMony-L/Cracking-the-coding-interview
/Interview Questions/Arrays and Strings/oneAway.py
2,363
3.6875
4
import unittest from collections import Counter class Solution(): def checkOneAway(self,str1, str2): # if absolute value of len(s1) - len(s2) > 1 return False if (abs(len(str1) - len(str2)) > 1): return False shortString = str1 if len(str1) < len(str2) else str2 longString =...
6ecfbf4296b96120a883241f82abf55c22ab0156
SMony-L/Cracking-the-coding-interview
/Interview Questions/Linked List/deleteMidNode.py
1,336
3.78125
4
class ListNode: def __init__(self, val = 0, next = None): self.val = val self.next = next class Solution: def __init__(self): self.head = None def insertNode(self, data): newNode = ListNode(data) newNode.next = self.head self.head = newNode # 1st so...
f446118b81d7e24eae6611c1226a47c68bb958d8
asgray/Ros
/Combinatorics_ORF_OpenReadingFrames.py
4,704
3.625
4
def importFASTA(data): """reads FASTA file, builds list of DNA strings""" dnaStrings = [] dataset = open(data) appended = False for line in dataset: if line.startswith('>'): appended = False else: if appended is False: dnaStrings.append(line.st...
eb4fc7b6f8e9e85d8ba989adbba49a4d287cc6cd
asgray/Ros
/String_Algorithms_SCSP_InterleaveMotifs.py
3,145
3.921875
4
def subList(x, y): """returns list of longest common substring""" def findPath(mat, x, y): """given a Needleman-Wunsch matrix, find the longest subsequence by backtracing the path""" # VERY NAIVE BACK SORT. ROOM FOR IMPROVEMENT, only gives one possivle subsequence tempSub = '' ro...
72ad2e86e3e58b11b25b0aba2e3721f8123aa9fc
astorl63/python-blackjack
/libs/trump.py
617
4.03125
4
# -*- coding: utf-8 -*- import random class Trump: suits = ['spade', 'club', 'heart', 'dia'] min_num = 1 max_num = 13 def __init__(self) : self.deck = self.make_deck() def make_deck(self) : deck = [] for suit in self.suits: for num in range(self.min_num, self....
27aa3c6b6eae6d2e8a98a71c8579595a397dbb67
FireInsidE-fie/CA_ComputerScienceCourse
/CS101/projects/shipping.py
885
4.03125
4
# https://www.codecademy.com/paths/computer-science/tracks/cspath-cs-101/ # modules/cspath-python-control-flow/projects/python-sals-shipping weight = float(input("Please input the weight in pounds of your package : ")) # Ground shipping if weight <= 2: print("Ground shipping cost :", 20 + (1.50 * weight)) elif we...
dea49a50527177f4b87ac51746b62b7ccdb88e18
Brimstonee12/Single-Python-Projects
/UniverseSandbox.py
11,124
3.859375
4
import time print(" Welcome in UniverseSandbox!"'\n') time.sleep(0) class Galaktyka(): def __init__(self,nazwa,masa,temp,pr_orb): self.nazwa = nazwa self.masa = masa self.temp = temp self.pr_orb = pr_orb def fullname(self): p...
c06556787285fed0ada3bf845c94476d4acd23ee
zhammer/finnegan-forever
/scripts/create_unicode_scroll.py
3,029
3.796875
4
#!/usr/bin/env python3 """Script for creating a valid unicode scroll file.""" import argparse import unicodedata def _parse_args(): """Helper function to create the command-line argument parser for create_unicode_scroll. Return the parsed arguments as a Namespace object if successful. Exits the program if u...
a3ab2999c94217160a7b9e347babfa6cf94ce3a2
14171136/ML_DEMO
/kmeans.py
2,277
3.5
4
# -*- coding: utf-8 -*- # @Time : 2020/8/20 20:19 # @Author : Syao # @FileName: K_means.py # @Software: PyCharm from sklearn.datasets import load_iris import matplotlib.pyplot as plt import numpy as np class K_means: def __init__(self,K,data): self.k = K self.data = data self.initial_c...
6ea757ad5ef76148a87520864cbd5adaac8e4611
scottcarpenter28/AutomateStuffPython
/rockPaperScissors.py
707
3.90625
4
import system import random playAgain = True win =0 lose =0 tie =0 while playAgain: print('Enter r for rock, p for paper, and s for scissors') playerIn = input() ran = random.randint(1,3) if playerIn == 'r': playerIn = 1 elif playerIn =='p': playerIn = 2 elif playerIn == 's': ...
64505f0b063431e040d9583243c5d751f9516cfc
yadhesh/numpy
/2.py
137
3.90625
4
a=input('enter the array') b=input('enter the array2') a=list(a) b=list(b) for i in b: if i>0: a.append(i) print 'resultant array:',a
0375603f854dbf53a89a8eb937fd66d6b000d8e0
cmj123/MultiThreading_in_Python
/multithreading07.py
707
3.703125
4
""" Name: Esuabom Dijemeni Date: 14/03/2020 Purpose: create a program which creates multiple threads, names them and prints the name """ # Import libraries import threading import time # User defined function 1 def ug(): print threading.currentThread().getName(), 'Starting' time.sleep(2) print threading.c...
404256a57066be69400765d6b91a0bbcbd98045e
cmj123/MultiThreading_in_Python
/multithreading20.py
415
3.59375
4
""" Name: Esuabom Dijemeni Date: 17/03/2020 Purpose: Create a program where in the main thread tries to acquire the lock twice in a sequential fashion """ # Import key libraries import threading ### Case 01 lock = threading.Lock() print 'First try: ', lock.acquire() print 'Second try: ', lock.acquire(0) ### Case 0...
8faac402654b5dd2ff52c3007f44150fb320fdf0
swlee9087/bitcamp-python-docker
/basic/palindrome.py
657
3.828125
4
class Palindrome(object): pass def str_to_list(self, payload: str) -> []: return [i for i in payload if i.isalnum()] def isPalindrome(self, ls: []) -> bool: """strs = [] for char in ls: if char.isalnum(): strs.append(char.lower()) while len(str...
0d4e41d3e1e7018e9c9c8adf289064086355eb29
mohitx001/assignment1_ineuron
/2.1.comma_seperated_list/comma_seperated_numbers.py
75
3.59375
4
a=input("enter the no. seperated by comma :") b=a.split(',') print(b)
9f815235eb7c74e01c17cd19ef5622bd843c8f1d
Elsie0312/pycharm_code
/two_truths-lie.py
584
4.15625
4
print('Welcome to Two Truths and a Lie! /n One of the following statements is a lie...you need to identify which one!') print('1. I have a donkey living in my backyard.') print('2. I have three fur babies') print('3. I speak 4 languages') truth_or_lie = input('Now put in the number of the statement you think is the li...
9c5da99971f42fc7c44996a7b18c5c24ef3db89f
mamerida/Eda5-MegaChess
/MegaChess/pieces.py
711
3.625
4
##chess pieces class Pieces(object): def __init__(self,row,col,name,colour): self.row = row self.column = col self.name = name self.colour = colour def __str__(self): return f'row : {self.row} col = {self.column} name: {self.name}' def get_row(self): return...
99cf9a285f887b99d2e281fc5459276231cad51e
mamerida/Eda5-MegaChess
/MegaChess/pieceValue.py
698
3.625
4
from const import( KING, ROOK, QUEEN, PAWN, BISHOP, KNIGHT, EMPTY) class PieceValue(object): def value(self, name): """ :param name: El nombre de la pieza :return: El valor de la pieza """ if name is "p" or name is 'P': return PAWN ...
74eb9bcefe0ee43e11a7f6b85e9b550a0bd5ad0e
dondon17/algorithm
/BOJ/2667.py
655
3.53125
4
mapSize = int(input()) graph = [] part = 0 count = 0 counts = [] for _ in range(mapSize): graph.append(list(map(int, input()))) def dfs(x, y): global count if x<0 or y<0 or x>=mapSize or y>=mapSize: return False if graph[x][y] == 1: count += 1 graph[x][y] = 0 dfs(x+1, y...
7004c89fd5ae8f8534d8894c372d76054b9c9fbd
dondon17/algorithm
/samsung sw/level2/snailnum.py
996
3.546875
4
def printarr(arr): for r in arr: for e in r: print(e, end=" ") print() def solution(size): snailarr = [[0 for _ in range(size)] for _ in range(size)] val = 0 x, y = 0, -1 sw = 1 while True: for _ in range(size): val += 1 y += sw ...
0b1306434d34eb4bdac77996ae371688fec56967
dondon17/algorithm
/implementation/star5.py
164
3.890625
4
n = int(input()) for i in range(1, n+1): for _ in range(0, n-i): print(" ", end="") for _ in range(i*2-1): print("*", end="") print("")
7c87e84b797bcc1febfdbed6fb71aa5298e4049f
kalvinchang/text-generation
/first-order-markov.py
5,324
3.65625
4
import numpy, random, string # obtains the text from the file and returns each word as an array def get_corpus(filename): file1 = open(filename, "r", encoding="utf8") #, text = file1.read() # corpus as one long string return text.split(" ") # corpus as arrays (each word is its own element) # split by s...
ab527afb431c0179086edf7a033faf4ddc1774e6
hlwhsunshine/PythonWork
/TestIidle.py
173
3.546875
4
class Student(object): def __init__(self,name,score): self.name = name self.score = score bart = Student('我的',90) print(bart.name) print(bart.score)
4069bd008c4d802677e9e6c6c492ae5bb6702754
laraib07/SpaceImpact
/si_modules/ship.py
1,353
3.5625
4
import pygame from abc import ABC, abstractmethod from pygame.sprite import Group from si_modules.explosion import Explosion class Ship(ABC): '''Class to represent a ship''' def __init__(self, name, si_settings, screen): '''Initialize ship''' self.screen = screen self.screen_rect = s...
9052d1c5ba953d14b09632f79dc79e457edb8d82
mattwilliams06/AppliedControlSystems2
/CodeFiles/rotation_matrices.py
3,689
3.796875
4
import numpy as np #from sympy_transfer_mat import TransferMatrix class RotationMatrix: ''' The aim of this class is to produce a 3D rotation matrix in cartesian coordinates, based on a user-specified order of inertial frame axes about which to rotate. Parameters ---------- mat_order: list...
82ec0056c1a6679d96270e1e9a9e6cc8316c2282
thomasbarrett/cs155-miniproject3
/utility.py
178
3.546875
4
def word_pairs(line): pairs = [] words = line.split() for i in range(int(len(words)/2)): pairs.append(words[2 * i] + ' ' + words[2 * i + 1]) return pairs
b684bc7c84a726e8a09e8a9d372faed1555a3416
samlobel/INCOHERANT_INITIALIZATION
/basic_try.py
5,185
3.671875
4
import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) # I don't know if it'll really be any better in a CNN actually, they have # a crazy number of parameters already, meaning that they're probably pretty #...
21078417d8209bf5d35ba40a0e351750f28d8d36
GABIGOLeterno/CursoemV-deoExerc-cios
/desafio33.py
277
4.15625
4
while True: num = str(input("Digite três valores: ").strip()) num2 = num.split() if len(num2) == 3: maxi = max(num2) mini = min(num2) print("O valor máximo é {}.".format(maxi)) print("O valor mínimo é {}.".format(mini))
5942f3e61eb913010704506ce4a9f9efe476e3f1
GABIGOLeterno/CursoemV-deoExerc-cios
/desafio15.py
221
3.578125
4
dias = float(input("Dias alugados: ".strip())) km = float(input("Kilômetros rodados: ".strip())) #Valor a pagar valor = float(dias * 60 + km * 0.15) print("O valor total a ser pago é de R${:.2f}.".format(valor))
bdcab01a08086e9d2d6573a3bec4e9c7cfdc4c9a
GABIGOLeterno/CursoemV-deoExerc-cios
/desafio38.py
498
3.984375
4
while True: print("Qual valor é maior?") num1 = int(input("Digite o primeiro valor: ")) num2 = int(input("Digite o segundo valor: ")) if num1 > num2: print("O \033[1;4;36mPRIMEIRO\033[m valor é maior.") elif num2 > num1: print("O \033[1;4;35mSEGUNDO\033[m valor é maior.") ...
ba4bf4aa7ad64deee29b365ff786526907b3bcb6
GABIGOLeterno/CursoemV-deoExerc-cios
/desafio22.py
457
3.953125
4
nome = str(input("Digite seu nome: ").strip()) mai = nome.upper() print("Seu nome em maiúscula é: {}.".format(mai)) min = nome.lower() print("Seu nome em minúsucla é: {}.".format(min)) print("Seu nome tem {} caractéres.".format(len(nome) - nome.count(' '))) # print("Seu primeiro nome tem {} letras.".format(...
fde0f95eaae8590d71b5f6ac7013cdc358cebcfc
jhalverson/data_science
/project_hubevents/scrapers/format_harvard.py
2,826
3.859375
4
""" Date: November 16, 2015 Author: Jonathan Halverson (halverson.jonathan@gmail.com) Usage: python format_harvard.py > harvard_24june2016.html This code formats the Harvard University scraping data. """ import json with open('harvard_university.json') as data_file: events = json.load(data_file) print '<html><hea...
1db77f8b00dabed6fa5686c02885d727e40058eb
MohitBaid/CodeChef
/Practice/Beginner/Solved/HSO8TEST.py
130
3.640625
4
str=input() s=str.split() x=float(s[0]); y=float(s[1]); if x%5==0: if x+0.5<=y: print(y-x-.5) else: print(y) else: print(y)
33c38136b94829acb9360496f1db0b53907d1805
jackmitcheltree/Project_Euler_JM
/problem_12.py
524
3.53125
4
#What is the value of the first triangular number to have over five hundred divisors? import time start = time.time() def tri_num(n): t = (n * (n+1))//2 return t def factor_len(n): L = [x for x in range(1,n+1) if n%x == 0] return len(L) n = 1 a = int() while a < 500: if n % 2 == 0:...
6c3c5ff4efc2a7070937393a2d4fa00ffe770d8a
Dawson1709/The-third-50
/the new but not 50.py
3,505
3.5625
4
Hello=(¨hi if you read the title you know that i am doing this on my school computer.¨) print(Hello) print(¨And right now i am really excited that i can get github on here because i cant get python.¨) 50=(¨i am really trying to hit 50 lines now though¨) from PIL import Image import requests from io import BytesIO resp...
277ec3679228e3cf774bd617a65ec5913b283a32
zgnMark/Algorithm
/codeforce/481-B.py
289
3.578125
4
str = raw_input(); N = int(str) str = raw_input(); if (len(str) < 3) : print 0 count = 0 result = 0 for i in range(2, len(str)) : if (str[i] == 'x') and str[i-1 - count] == 'x' and str[i-2 - count] == 'x': count = count + 1 result = result + 1 else: count = 0 print result
c1b386e2a4d307bcdfab44a838fcea1a668ce892
zgnMark/Algorithm
/codeforce/975A.py
342
3.53125
4
# contest http://codeforces.com/contest/975/problem/A N = int(raw_input()) str1 = raw_input() arr = str1.split(" ") root = {} for item in arr: s = set() for c in item: s.add(c) li = list(s) li.sort() key = ''.join(li) if root.has_key(key): continue else: root[key...
f81bf757b2c9e08b0b35f7c6915deebfae964aaf
swampy990/Boring
/tempCheck.py
746
3.5625
4
#! /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 # quickWeather.py - prints the weather for a given location from the command line import json import requests import sys import pprint debug = None if len(sys.argv) > 1: debug = sys.argv[1] url = 'http://192.168.1.201/api/NNKCJxSsNFd1WMPpA5Bs...
2492520b1fc91cf095c964e1b178c483046766b6
besslwalker/algo-coding-practice
/4.1 Quicksort/quicksort.py
1,534
4.125
4
# Quicksort # Bess L. Walker # 2-21-12 import random def quicksort(unsorted): real_quicksort(unsorted, 0, len(unsorted)) def real_quicksort(unsorted, low, high): if high - low <= 1: return pivot_index = partition(unsorted, low, high) real_quicksort(unsorted, low, pivot_index) real_quicksort(unsorted, pivot_i...
9eab2d329dbc7546ddc75ddb89077e43a91c3a2c
jaypsingh/PyRecipes
/DS_and_Alg/DS_and_Alg_11.py
498
3.546875
4
record = "0123456789055.210123456789012.78" #Old Approach print (record[11:13]) print (record[-5:-1]) totalCost = float(record[10:13]) * float(record[-5:-1]) print (totalCost) #Suggest Approach share = slice(11,13) price = slice(-5, -1) print (record[share]) print (record[price]) totalCost1 = float(record[share]) * f...
c7c008011e3694dae55fa8a676721bd8e9f5e78b
jaypsingh/PyRecipes
/String_n_Text/Str_n_Txt_07.py
710
4.4375
4
''' This program demonstrates how can we specify a regular expression to search shortest possible match. By Default regular expression gives the longest possible match. ''' import re myStr = 'My heart says "no." but mind says "yes."' # Problem demonstration ''' Here we ar etrying to match a text inside a quote. So i e...
5ebf8de8d114013c968f41c0a12c2da51e9c0917
jaypsingh/PyRecipes
/DS_and_Alg/DS_and_Alg_16.py
414
3.828125
4
''' This short program shows a demo of how we can filter and compress sequence items. ittertools.compress() takes a sequence and accompanying boolean selector as input and returns a compressed list as output. ''' from itertools import compress count= [2,1,5,7,9,0] flatNo = ['A-102','B-321','C-211','D-111','E-008','F-3...