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
49b93f4a152ba84f7adcf5f8d529777d3fbc02d7
xtypox/CS_521_Python
/eythuang_hw_2_1_5.py
1,339
4.09375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Jan 26 20:47:01 2021 Eva Huang CS 521 - Spring 1/26/21 Homework Problem 5 create BML calculator @author: ehuang """ print("Let me calculater your BMI! ") # Imperial or Metrics, y for Imperial, n for metrics. Render input to lower case imp_or_mtr= input("...
4bcf932cb0e0ad8f3c89b6bd23730cfe6694237a
JiajiaLi04/Deep-Learning-Project-Demos
/1. A Multi-layer Percetron for Natural Language Processing/test.py
170
3.890625
4
def add(a, b, c=None): p = a + b if c is not None: c = c else: c = 1 e = c + 1 return e print(add(1, 2, 2)) a = add(1, 2) print(a)
fd7718ccfc471b24223d8b6ab9dafc41d93b3a94
dimitermilev/web_scraping_regression_job_listings
/web_scrape_data_science_listings.py
8,409
3.546875
4
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup import requests import pandas as pd import numpy as np import sys import re import os import json import time def initiate_scraper_job_listings(title, location): ...
3926ba17b6e89a70429a2522844615cedde83f0a
aderter/python-algorithms
/binary_search.py
583
3.90625
4
def binary_search(list1, low, high, n): if low <= high: mid = (low + high) // 2 if list1[mid] == n: return mid elif list1[mid] > n: return binary_search(list1, low, mid - 1, n) else: return binary_search(list1, mid + 1, high, n) ...
862d5e43d8143663ccf6bc05d58aaedd6f91c675
JasonWatts/laterHasArrived
/parseToCSV/generateMatrix.py
4,458
3.59375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Sep 21 13:10:43 2018 @author: Kyle Hansen and Jared Wilkens """ import pandas as pd import re def parse(file): #opens file that has the saved responses from the survey #file must be in same directory as this python file intermediateFile = ...
b523540a563cf15c63d240228651cf1b1c8c7079
Nicodemos234/Solving-problems-with-python
/questao07.py
192
3.84375
4
x = 0 i = 0 while x < 1 or x > 10: x = int(input("insira um valor inteiro de 1 a 10: ")) while i <= 10: z = i*x print(str(x)+"x"+str(i)+" = "+str(z)) i = i+1
e1f8292c46171c086c81da2d45888e2f287e00c1
Nicodemos234/Solving-problems-with-python
/questao08.py
429
3.703125
4
qtdMercadorias = int(input("Insira o total de mercadorias: ")) aux = 1 somaMercadoria = 0 while aux <= qtdMercadorias: somaMercadoria = somaMercadoria + float(input("insira o valor da "+ str(aux)+"ª mercadoria: ")) aux = aux+1 mediaValMerc = somaMercadoria/qtdMercadorias print("o valor total em est...
3abe9e029df3f2d793a0fd5cd64537146af115d0
AbhiKhoyani/ai50-projects-2020-x-tictactoe
/tictactoe.py
4,704
3.953125
4
""" Tic Tac Toe Player """ import math import random import copy #import runner X = "X" O = "O" EMPTY = None def initial_state(): """ Returns starting state of the board. """ return [[EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY]] def player(board): ...
c7c231d3724cedfadc5434df9435c70a27440008
ghilbing/Ejemplos
/romanToInteger.py
357
3.625
4
def romanToInteger(A): values = {'I': 1, 'V': 5, 'X':10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} decimal = 0 for i in range(len(A)): if i > 0 and values[A[i]] > values[A[i-1]]: decimal += values[A[i]] - 2 * values[A[i-1]] else: decimal += values[A[i]] return decim...
cd6f1f7d929a227c59d212981da395177e2fe6f2
ghilbing/Ejemplos
/colorfullNumber.py
355
3.625
4
def colorfullNumber(A): N = str(A) vals = set() for l in range(1, len(N) + 1): for i in range(0, len(N) - l + 1): ans = 1 for k in range(i, i + l): ans *= int(N[k]) if ans in vals: return 0 vals.add(ans) return 1 A ...
ab55bb1f24115fb95904185f7a1a1b99b910b375
ghilbing/Ejemplos
/balancedBinaryTree.py
334
3.609375
4
def isBalanced(A): def balance(A): if A is None: return 0 left = balance(A.left) right = balance(A.right) if left == -1 or right == 1 or abs(left - right) > 1: return -1 return 1 + max(left, right) if balance(A) != -1: return 1 else: ...
e90b32492b9f8303b69850861db7d6ba43bbfb40
ghilbing/Ejemplos
/insertionSort.py
350
4.09375
4
def insertionSort(A): for i in range(1, len(A)): currentvalue = A[i] position = i while position > 0 and A[position - 1] > currentvalue: A[position] = A[position - 1] position = position - 1 A[position] = currentvalue A = [54, 26, 93, 17, 77, 31, 44, 55, ...
e8daa4bcc8abf2abb9a35fa2cec37eb42a377bad
ghilbing/Ejemplos
/braces.py
1,116
3.96875
4
def braces(A): braces1 = 0 braces2 = 0 braces3 = 0 balanced = True n = A[0] for j in range(1, len(A)): strings = list(A[j]) for i in range(0, len(strings)): if strings[i] == "{": braces1 = braces1 + 1 elif strings[i] == "[": ...
53cd865405718e80ae7bdb522ad474657a6aab91
ghilbing/Ejemplos
/removeDuplicatesFromSortedList.py
613
3.890625
4
class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: # @param head, a ListNode # @return a boolean def removeDuplicates(self, head): cur = head while cur: while cur.next and cur.next.val == cur.val: cur.next = c...
f8826601865125dbbfb79e8a0ec356e281fbd06d
ghilbing/Ejemplos
/regularExpressionII.py
1,413
3.5625
4
def isMatch(A, B): table = [[0] * (len(A) + 1) for _ in range(len(B) + 1)] table[0][0] = 1 for i in range(2, len(B) + 1): table[i][0] = table[i - 2][0] and B[i - 1] == '*' for i in range(1, len(B) + 1): for j in range(1, len(A) + 1): if B[i - 1] != '*': table...
ca5789d2f4a54899e37cb218fbcc19b325cde9e4
ghilbing/Ejemplos
/maxRectangleInBinaryMatrix.py
540
3.59375
4
def maximalRectangle(A): if not A or not A[0]: return 0 n = len(A[0]) height = [0] * (n+1) ans = 0 for row in A: for i in range(n): height[i] = height[i] + 1 if row[i] == 1 else 0 stack = [-1] for i in range(n+1): while height[i] < height[stack...
3b6347200d2ed3ca7238aac60ad34fe7f21c921d
ghilbing/Ejemplos
/maxSumPathInBinaryTree.py
886
3.59375
4
class Treenode: def __init__(self,x): self.val = x self.left = None self.right = None class Solution: def maxPathSum(self, A): def dfs(node): left = right = 0 leftsum = rightsum = None if node.left: left, leftsum = dfs(node.lef...
0d4d5899855e743571fcce24706975f509d7227f
safelyafnan/Muhammad-Safely-Afnan_I0320070_M-Wildan-Rusydani_Tugas-4
/Exercise 4.12.py
437
3.5
4
#!/usr/bin/python a=60 #60=0011 1100 b=13 #13=0000 1101 c=0 c=a&b; #12=0000 1100 print ("Line 1 - Value of c is", c) c=a|b; #61=0011 1101 print ("Line 2 - Value of c is", c) c=a^b; #49=0011 0001 print ("Line 3 - Value of c is", c) c=~a; #-61=1100 0011 print ("Line 4 - Value of c is", c) c=a<...
10de83ee6cfaf4ff40da234ec955af07668a66e2
AllanCosta12/Beginner-Projects
/calcular_media4.0.py
1,744
3.6875
4
def calcular_media(soma): media = soma / 4 return media def verifica_aprovado(media_calculada): if media_calculada >= 8: print('a media do aluno e', media_calculada, 'ele foi aprovado e esta de parabens') elif media_calculada >= 6: print('a media do aluno e', media_calculada, 'e...
3a064fdd3d9c57446e74f9895da023300c782a12
henryCraig/Coding-Challenges
/Bronze/diceRoller.py
479
3.6875
4
#https://www.reddit.com/r/dailyprogrammer/comments/8s0cy1/20180618_challenge_364_easy_create_a_dice_roller/ import random def diceRoller(diceString): iterator = 0 randList = [] dLoc = diceString.find("d") for i in range(int(diceString[:dLoc])): randomNum = random.randint(1,int(diceString[dLoc...
a257dd6d6d7cdee44217583c27f43b4411fa7485
Oziel-Silva/Porta-Serial-com-Python
/serial_port_read.py
2,354
3.734375
4
# -*- coding: latin1 -*- # Códido para ler a porta serial e fazer um log em txt # do que foi feito no arduino def arduino(): import serial import sys import time port = '/dev/ttyACM0' #configuração da serial baud_rate = 9600 ser = serial.Serial (port, baud_rate) # Abrindo a porta te...
4a9ffc5e0aea7e890b6c8d9c037e8e75d685ec48
gabsSP1/mopidy-killthedj
/mopidy_killthedj/tracklist.py
923
3.53125
4
class TrackStructure(object): def __init__(self, track, user): self.track = track self.user = user self.votes = 0 class Tracklist(object): """ Tracklist works as following: Track with the most votes goes first. After that the track with one vote less. """ def __init__(s...
9e10117cd1c1658a51db6fe3e810af4f00137ca5
chiyx/pytour
/src/python_cookbook/ch03/month_range.py
608
4.0625
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from datetime import datetime, date, timedelta import calendar def get_month_range(start_date=None): if start_date is None: start_date = date.today().replace(day=1) _, days_in_month = calendar.monthrange(start_date.year, start_date.month) end_date = ...
6a1afd526bb90fd4ce7a395b1e99b8de715c15e1
chiyx/pytour
/src/fluent_python/ch19/bulkfood/bulkfood_v2prop.py
857
3.875
4
# -*- coding: UTF-8 -*- # 特性(property)的使用, 使用工程方法包装 def quantity(storage_name): def qty_getter(instance): return instance.__dict__[storage_name] def qty_setter(instance, value): if value > 0: instance.__dict__[storage_name] = value else: raise TypeError('valu...
7dd49ff364344453ff4a8516e5dfa583f096da7c
pritam-shyam/Python_Assignments
/IA03/models/predictive_models.py
891
4
4
#The fuction lm() requires an input of (i,m) and then stores #those values into varibles and function lm1() computes the #linear model using slope and interept. def lm(i, m): slope = m intercept = i def lm1(x): number = x answer = intercept + (slope*number) return answer return l...
d425de88085f2ecc0552b5d14e7462d477d344d7
AiZhanghan/Leetcode
/code/451. 根据字符出现频率排序.py
429
3.625
4
import collections class Solution: def frequencySort(self, s): """ Args: s: str Return: str """ counter = collections.Counter(s) counter_list = list(counter.items()) counter_list.sort(key=lambda x: x[1], reverse=True) ...
c3e988cbbea731cde9312159ed65ece510b11506
AiZhanghan/Leetcode
/秋招/360/2/3.py
938
3.53125
4
class Solution: def func(self, matrix, n): """ Args: matrix: list[list[int]] n: int Return: int """ self.res = 0 self.dfs(matrix, 0, n, 0) return self.res def dfs(self, matrix, index, rest_n, path): """...
07931a8d04ab9471d504c3e5f6282bd2b5cf4c4e
AiZhanghan/Leetcode
/code/20. Valid Parentheses.py
832
3.75
4
# -*- coding: utf-8 -*- """ Created on Mon Jun 24 20:34:55 2019 @author: Administrator """ class Solution: def isValid(self, s: str) -> bool: stack = [] for i in range(len(s)): if s[i] == '(' or s[i] == '{' or s[i] == '[': stack.append(s[i]) else: ...
654f32c87933ce7392df079e202bcd720ae4b000
AiZhanghan/Leetcode
/秋招/网易/1.py
696
3.546875
4
class Solution: def generate_huiwen(self, s): """ Args: s: str Return: str """ for left in range(len(s)): if self.is_huiwen(s, left, len(s) - 1): return s + s[:left][::-1] def is_huiwen(self, s, left, right...
aefc068b661ead2f05520a417d998e45d51376e2
AiZhanghan/Leetcode
/code/139. 单词拆分.py
1,283
3.578125
4
from typing import List class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: """DP Args: s: str wordDict: list[str] Return: bool """ wordDict = set(wordDict) dp = [False for _ in range(len(s)...
bb2f7a4d8fc4a75281339ac8dfcb757e9d6347aa
AiZhanghan/Leetcode
/code/5. 最长回文子串.py
783
3.75
4
class Solution: def longestPalindrome(self, s: str) -> str: if not s: return "" start = 0 end = 0 for i in range(len(s)): len1 = self.expand_around_center(s, i, i) len2 = self.expand_around_center(s, i, i + 1) len_ = max(len1, len2) ...
b8865b24f1d378f29321676b97a511580a290b6e
AiZhanghan/Leetcode
/code/138. 复制带随机指针的链表.py
1,131
3.703125
4
# Definition for a Node. class Node: def __init__(self, x, next=None, random=None): """ Args: x: int next: Node random: Node """ self.val = int(x) self.next = next self.random = random class Solution: def copyRandomList(self, ...
f6ab196c4ec5afac9c6374591bc643e10a9200bd
AiZhanghan/Leetcode
/秋招/美团/1.py
615
3.5
4
class Solution: def func(self, a, b): """ Args: a: list[int] b: list[int] Return: list[int] """ a_set = set(a) b_set = set(b) res = [ len(a_set - b_set), len(b_set - a_set), len...
e0ff4e937ee0cbe995de9fa416204aca50997ebd
AiZhanghan/Leetcode
/code/86. Partition List.py
911
3.75
4
# -*- coding: utf-8 -*- """ Created on Sat Jun 22 10:12:48 2019 @author: Administrator """ # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def partition(self, head: ListNode, x: int) -> ListNode: #less t...
7540169cd9fbc1f37c8412d46c3c7d479e6b55de
AiZhanghan/Leetcode
/code/79. Word Search.py
1,457
3.515625
4
# -*- coding: utf-8 -*- """ Created on Tue Jul 9 19:12:40 2019 @author: Administrator """ class Solution: def exist(self, board: List[List[str]], word: str) -> bool: self.__m = len(board) assert self.__m > 0 self.__n = len(board[0]) self.__visited = [[False for _ in range...
5fafc3391d7a9074f052d0a390ddb4e346aed047
AiZhanghan/Leetcode
/秋招/阿里/2.py
354
3.796875
4
def word_count(filename, s): """ Args: filename: str s: str Return: int """ res = 0 with open(filename) as f: for line in f.readlines(): res += line.count(s) return res if __name__ == "__main__": filename = r"./test.txt" res = word_c...
01c0b258320011c19e374e3836bf6e06ae9659ca
AiZhanghan/Leetcode
/code/55. 跳跃游戏.py
821
3.609375
4
from typing import List class Solution: def canJump(self, nums: List[int]) -> bool: if len(nums) <= 1: return True max_dist = 0 for i, jump in enumerate(nums): if i > max_dist: return False max_dist = max(max_dist, i + jump) retur...
975a449a3a8cec07c6b2a1576c359a3b0d01cd8c
AiZhanghan/Leetcode
/code/39. Combination Sum.py
953
3.53125
4
# -*- coding: utf-8 -*- """ Created on Mon Jul 8 16:56:09 2019 @author: Administrator """ class Solution: def combinationSum(self, candidates, target): res = [] candidates.sort() if candidates[0] > target: return res c = [] s...
bdcaec93ea4bca3469e5b30358baaef40a8cf367
AiZhanghan/Leetcode
/code/92. Reverse Linked List II.py
1,582
4
4
# -*- coding: utf-8 -*- """ Created on Fri Jun 21 21:05:19 2019 @author: Administrator """ import test_module # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def reverseBetween(self, head: ListNode, m: int, n: int) -> L...
e563081bd06de46d07aa505d6e7670695d9dda24
AiZhanghan/Leetcode
/code/687. 最长同值路径.py
1,692
4.03125
4
# Definition for a binary tree node. class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def longestUnivaluePath(self, root): """ Args: root: TreeNode Return: int """ ...
ef790017e6572b9eada7babe5bd6ebb52adb3dc5
AiZhanghan/Leetcode
/code/9. 回文数.py
831
3.734375
4
class Solution: def isPalindrome(self, x): """ Args: x: int Return: bool """ if x < 0: return False div = 1 while x // div >= 10: div *= 10 while x > 0: left = x // div ri...
fb1633215a952eea2f95bec7a6238c0183ca379c
AiZhanghan/Leetcode
/code/98. Validate Binary Search Tree.py
635
3.609375
4
# -*- 0oding: utf-8 -*- """ Created on Sun Jun 30 11:31:44 2019 @author: Administrator """ # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def isValidBST(self, root, floor = -float('i...
858a0b20cc4bb7ec804810681eb3c5a2a39eacf0
AiZhanghan/Leetcode
/秋招/小米/1/1.py
1,565
3.5625
4
# #!/bin/python # # -*- coding: utf8 -*- # import sys # import os # import re #请完成下面这个函数,实现题目要求的功能 #当然,你也可以不按照下面这个模板来作答,完全按照自己的想法来 ^-^ #******************************开始写代码****************************** def pathInZigZagTree(label): """ Args: label: int Return: list[int] """ l...
af3ea5d2263ed919cb46f73618327ba1b9e99624
AiZhanghan/Leetcode
/code/127. 单词接龙.py
3,553
3.796875
4
import collections class Solution: def ladderLength(self, beginWord, endWord, wordList): """ Args: beginWord: str endWord: str wordList: list[str] Return: int """ if endWord not in wordList: return 0 ...
c7657af42235e4baefe9b51c6887b992cace8850
AiZhanghan/Leetcode
/code/524. 通过删除字母匹配到字典里最长单词.py
1,485
3.5625
4
class Solution: def findLongestWord(self, s, d): """ Args: s: str d: list[str] Return: str """ res = "" for x in d: if self.is_subsequence(s, x): if len(x) > len(res) or (len(x) == len(res) and x...
ae0b88c79435b380bddd0781b73e8fe7702e5ba4
AiZhanghan/Leetcode
/秋招/美团/2.py
362
3.625
4
class Solution: def func(self, S): """ Args: S: str Return: int """ upper_count = 0 for c in S: if c.isupper(): upper_count += 1 return abs(len(S) // 2 - upper_count) if __name__ == "__main__": ...
c1771ceccb9966e2006f5d10b902703effd41211
AiZhanghan/Leetcode
/code/215. Kth Largest Element in an Array.py
883
3.5625
4
# -*- coding: utf-8 -*- """ Created on Mon May 27 15:31:56 2019 @author: Administrator """ class Solution: def findKthLargest(self, nums, k) -> int: #quick sort partition #[1...i-1] > flag #[j...len(nums) - 1] <= flag i = 1 j = len(nums) flag = nums[0] ...
2d803efb09d6ebfbe00c7d108a0afbf3058d4992
AiZhanghan/Leetcode
/code/342. 4的幂.py
758
3.90625
4
import math class Solution: def isPowerOfFour(self, num): """ Args: num: int Return: bool """ return num > 0 and num & (num - 1) == 0 and num & 0xaaaaaaaa == 0 # class Solution: # def isPowerOfFour(self, num): # """ # A...
34a4a9b8480b200ca4e08bc69ad74c212b815130
AiZhanghan/Leetcode
/code/836. 矩形重叠.py
1,050
3.875
4
class Solution: def isRectangleOverlap(self, rec1, rec2): """ Args: rec1: list[int] rec2: list[int] Return: bool """ x_overlap = not (rec1[2] <= rec2[0] or rec2[2] <= rec1[0]) y_overlap = not (rec1[3] <= rec2[1] or rec2[3] ...
a4aaa3debfc5aa4928fa1280a5a5a82840f033ed
AiZhanghan/Leetcode
/秋招/搜狗/1.py
1,048
3.578125
4
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # 返回能交换奖品的最大数量 # @param a int整型 # @param b int整型 # @param c int整型 # @return int整型 # class Solution: def numberofprize(self , a , b , c ): # write code here nums = [a, b, c] return self.helper(nums) def helper(self, nums): nums.sort...
93b816ec1dc6dad0ce25d354b5022a0da5812a59
AiZhanghan/Leetcode
/code/面试题22. 链表中倒数第k个节点.py
499
3.5625
4
# Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def getKthFromEnd(self, head: ListNode, k: int) -> ListNode: """ :param head: ListNode :param k: int :return: ListNode """ ...
4ddcae26fbfe2206df1916c53833bd190c4299f3
AiZhanghan/Leetcode
/code/766. 托普利茨矩阵.py
1,369
3.546875
4
class Solution: def isToeplitzMatrix(self, matrix): """ Args: matrix: list[list[int]] Return: bool """ for i in range(1, len(matrix)): for j in range(1, len(matrix[0])): if matrix[i][j] != matrix[i - 1][j - 1]: ...
2768a94678051e1936abaac060d27f333c602d37
AiZhanghan/Leetcode
/code/189. 旋转数组.py
1,342
3.640625
4
class Solution: def rotate(self, nums, k): """ Do not return anything, modify nums in-place instead. Args: nums: list[int] k: int """ k %= len(nums) self.reverse(nums, 0, len(nums) - 1) self.reverse(nums, 0, k - 1) self...
36ffcc421774fce7a3a66a8fd5b3a496b343d5aa
AiZhanghan/Leetcode
/code/127. Word Ladder.py
1,290
3.609375
4
# -*- coding: utf-8 -*- """ Created on Tue Jun 25 11:05:24 2019 @author: Administrator """ from collections import deque class Solution: def ladderLength(self, beginWord, endWord, wordList): d = self.construct_dict(wordList) queue, visited = deque([(beginWord, 1)]), set() while q...
00c5490a58cf77e0149a14ed6e611df2fe08dfbd
AiZhanghan/Leetcode
/code/501. 二叉搜索树中的众数.py
1,106
3.6875
4
# Definition for a binary tree node. class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def findMode(self, root): """ Args: root: TreeNode Return: list[int] """ ...
562c5324a74b2f503ca3324a851d1293b6821ff8
AiZhanghan/Leetcode
/code/409. 最长回文串.py
869
3.5
4
from collections import Counter class Solution: def longestPalindrome(self, s): """ Args: s: str Return: int """ counter = Counter(s) res = 0 for value in counter.values(): res += value - (value & 1) if re...
029ae92358737c98ea1e2a3bf64deb9098d947ab
AiZhanghan/Leetcode
/code/面试题31. 栈的压入、弹出序列.py
1,064
3.578125
4
class Solution: def validateStackSequences(self, pushed, popped): """ :param pushed: list[int] :param popped: list[int] :return: bool """ stack = [] j = 0 for x in pushed: stack.append(x) while stack and stack[-1] == popped[j]:...
328d9297b449cf7d77e9fb9e707a4f0833a9d12a
AiZhanghan/Leetcode
/code/684. 冗余连接.py
1,109
3.734375
4
class UnionFind: def __init__(self, n): """ Args: n: int """ self.roots = [x for x in range(n + 1)] def find(self, i): """ Args: i: int Return: int """ if self.roots[i] == i: return ...
95cdbb4d5a61197ab1fd340cf10986c94f4f26ab
AiZhanghan/Leetcode
/code/130. Surrounded Regions.py
1,679
3.515625
4
# -*- coding: utf-8 -*- """ Created on Tue Jul 9 20:31:00 2019 @author: Administrator """ class Solution: def solve(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ self.__m = len(board) if self.__m == 0: ret...
a51dff73c16188226a01f2ce9ff02cff5bd2da5a
chisness/aipoker
/ttt.py
2,117
3.59375
4
from typing import List, Optional, Dict from abc import ABC, abstractmethod class GamePosition(ABC): @abstractmethod def value(self) -> Optional[int]: pass @abstractmethod def player(self) -> int: pass @abstractmethod def available_moves(self) -> List['GamePosition']: ...
c05fee178aa7615d2c07fb37bc40994a920da9dc
toddschultz/DATA558
/myLogisticRegression.py
6,961
3.59375
4
# %% Binary logistic regression with l2 regularization # Implementation and demonstration of binary logistic regression with l2 # regularization. The example data set is the spam data set from Elements of # Statisitical Learning hosted on # https://statweb.stanford.edu/~tibs/ElemStatLearn/datasets # Comments ar...
974579c5d3dc1148e46405722301237080e547ff
NeyBrito/introduction_python
/codes/aula2.py
1,382
4.03125
4
nota1 = int(input("Primeiro bimestre: ")) if nota1 > 10: nota1 = int(input("Você digitou errado. \nSegundo bimestre:")) nota2 = int(input("Segundo bimestre: ")) if nota2 > 10: nota2 = int(input("Você digitou errado. \nTerceiro bimestre:")) nota3 = int(input("Terceiro bimestre: ")) if nota3 > 10: nota3 = int...
cd779e2371a430d6be57d6fe90c36a5e02cee260
NeyBrito/introduction_python
/codes/aula11PersonalizarExcecao.py
1,754
4.09375
4
class Error(Exception): pass class InputError(Error): def __init__(self, message): self.message = message while True: try: x = int(input("Entre com um numero de 0 a 10: ")) print(x) if x > 10: raise InputError('Nota não pode ser maior que 10.') elif x < ...
cc574bc99ee13b206648274e3ad764c36ad4257b
KentoKlasen/python_rps
/rps.py
877
4.09375
4
import random def main(): choices = ['rock', 'paper', 'scissor'] user_choice = False while user_choice == False: cpu_choice = random.choice(choices) user_choice = input('enter a choice (rock, paper, scissor): ') print(f'cpu chose {cpu_choice}') if user_choice not in choices: print('not a valid choice') ...
4221e1c6df47872d910c462da5e3aff516755f86
doctor-blue/python-series
/Intermediate/strings.py
503
4.15625
4
# a = "Hello\nWorld" # a = '''Lorem ipsum dolor sit amet, # consectetur adipiscing elit, # sed do eiusmod tempor incididunt # ut labore et dolore magna aliqua.''' # print(a) # a = 'Hello' # print(a[-5]) # print(len("banana")) # for x in "banana": # print(len(x)) # print("ca" not in "banana") a = "Hello, ...
6a85bbc76b9f73042d55ac1c2e792bb81afa1dce
doctor-blue/python-series
/Intermediate/decorator_tut.py
950
3.5
4
import functools # def say_hi(): # def say_hi_again(): # print('Hello') # return say_hi_again # greet = say_hi() # greet() # def greet(name): # return 'Hello ' + name # def call_func(greet): # other_name = 'John' # return greet(other_name) # print(call_func(greet)) # def start_end_d...
8c06aa5f4907a2fcefc5cdac6aadec88cbf3a6d5
doctor-blue/python-series
/Data Structures/stack_pac/stack.py
788
3.96875
4
class Stack: def __init__(self): self.storage = [] def size(self): return len(self.storage) def is_empty(self): return self.size() == 0 def push(self, value): self.storage.insert(0, value) return self def pop(self): return self.storage.pop(0) ...
c4b71e1ac49da52e9406339ce3fbd3b2941c872e
flavio022/exercicios_python
/ex1Arquivos.py
435
3.75
4
#Desenvolva um programa que leia os times cadastrados no arquivo arquivos.txt e apresente na tela os nomes dos times em ordem alfabetica fim_arquivo = False arquivo = open('arquivos.txt','r') times=[] while not fim_arquivo: linha = arquivo.readline() if linha =='': fim_arquivo = True else:...
509d3f83f259aad55709fd795d7e0f04a47734be
flavio022/exercicios_python
/times.py
620
3.78125
4
"""meu_arquivo = open('arquivos.txt', 'r') linha = meu_arquivo.readline() time_a = linha.rstrip() linha = meu_arquivo.readline() time_b = linha.rstrip() print('Jogo:') print(time_a,'versus',time_b) print("Não perca esse evento!") meu_arquivo.close()""" final_arquivo = False string_vazia = '' meu_arquiv...
6a7b641985b11520f0b6ff2191260a3780e51987
flavio022/exercicios_python
/ex.py
398
3.84375
4
lista =[] num = int(input("Digite um número da sequência: ")) while num != - 1: lista.append(num) num = int(input("Digite um número da sequência: ")) elemento = int(input("Digite o elemento a ser procurado: ")) cont = 0 for i in range(len(lista)): if lista[i] == elemento: cont += 1 p...
e17bf3dbc82e0d180eb01c9791f1db21403c6fb3
flavio022/exercicios_python
/strings.py
917
4.0625
4
# retorna True se s contém somente letras s = 'Hello' print(s, s.isalpha()) s = 'Hello!' print(s, s.isalpha()) #retorna True se s contém somente dígitos. s = '1234' print(s, s.isdigit()) s = 'G1234!' print(s, s.isdigit()) #lower retorna a versão de s com todas as letras minúsculas. upper retorna a vers...
41648b3b049240cff4de36d108fa8e6d1acd32b8
flavio022/exercicios_python
/ex5.py
352
3.828125
4
lista = [] print("Escolha uma opção: ") print("(1) Cadastrar um amigo") print("(2) Mostrar nomes de todos os amigos") print("(9) Sair do programa") op = int(input()) if op == 1: nome = input("Digite o nome do amigo") lista.append(nome) elif op == 2: print(lista) elif op == 9: print("Fi...
b972aee85fb8e21ccc77c8c144f3aa07af1c72cd
flavio022/exercicios_python
/dadosElementosCurso.py
446
3.78125
4
""" Faça um programa que simule um lançamento de dados. Lance o dado 100 vezes e armazene os resultados em um vetor. Depois, mostre quantas vezes cada valor foi consequido. """ import random lista = [] n = int(input("Digite o número de lançamentos: ")) for i in range(n): lista.append(random.randint(1,6)) p...
68fa03b28cca59922d593a214b353c05eac9e8b6
cuker0/Python
/Exercise 14 - List Remove Duplicates/Exercise_14___List_Remove_Duplicates.py
744
3.9375
4
#Exercise 14 (and Solution) #Write a program (function!) that takes a list and returns a new list that contains all the elements of the first list minus all the duplicates. # #Extras: # #Write two different functions to do this - one using a loop and constructing a list, and another using sets. #Go back and do Exercise...
3b25e59cd8ef2f769e36aca0497e4dd7b9db38ad
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise04_39.py
744
4.21875
4
import turtle x1, y1, r1 = eval(input("Enter circle1's center x-, y-coordinates, and radius: ")) x2, y2, r2 = eval(input("Enter circle2's center x-, y-coordinates, and radius: ")) # Draw circle 1 turtle.penup() turtle.goto(x1, y1 - r1) turtle.pendown() turtle.circle(r1) # Draw circle 2 turtle.penup() turtle.goto(x2,...
9d57ed4a28628104fa84f1fc880f352ccefc38bf
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise11_41.py
2,428
3.703125
4
from tkinter import * # Import tkinter from Sudoku import isValidGrid # Import isValid from Sudoku import search # Import search import tkinter.messagebox # Import tkinter.messagebox class MainGUI: def __init__(self): window = Tk() # Create a window window.title("Sudoku") # Set title ...
c4cdd39b52b2dfe4a010b726aad89942b8a35629
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise06_37.py
469
3.671875
4
import turtle import RandomCharacter # Write text at the specified location def writeLine(text, x, y): turtle.penup() # Pull the pen up turtle.goto(x, y) turtle.pendown() # Pull the pen down turtle.write(line, font = ("Times", 18, "bold")) x = -130 y = 50 line = "" for i in range(1, 101): line +=...
15da090df965a538bb0129434f7da1d8de12c93b
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise15_21.py
457
3.921875
4
def main(): binary = input("Enter a binary number: ").strip() print(binary + " is decimal " + str(binaryToDecimal(binary))) def binaryToDecimal(binaryString): return binaryToDecimalHelper(binaryString, 0, len(binaryString) - 1) def binaryToDecimalHelper(binaryString, low, high): if high < low: ...
6462c0647f93fe56be262bfc772428373359c32e
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise05_45.py
632
4.0625
4
decimal = eval(input("Enter an integer: ")) hexString = "" value = decimal while value != 0: single = value % 16 if single == 15: hexString = "F" + hexString elif single == 14: hexString = "E" + hexString elif single == 13: hexString = "D" + hexString elif single...
a84d5e68e4be81863fcb2b64dbccb3d83fdaf33b
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise10_11.py
457
4
4
import random def main(): # Read numbers as a string from the console s = input("Enter numbers: ") items = s.split() # Extracts items from the string numbers = [ eval(x) for x in items ] # Convert items to numbers shuffle(numbers) print(numbers) def shuffle(list): for i in range(len(list)...
18bd27d93e3165f97a4f80e1078098cd3e2f3c7b
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise09_17.py
1,750
3.609375
4
from tkinter import * # Import tkinter width = 200 height = 100 radius = 80 class MainGUI: def __init__(self): window = Tk() # Create a window window.title("Racing Car") # Set a title self.canvas = Canvas(window, bg = "white", width = width, height = height) self.canvas.pa...
7129c55d94b726cd8ce660f7d1d54de83f6eceb6
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise04_15.py
951
3.890625
4
import random # Generate a lottery lottery = random.randint(0, 999) # Prompt the user to enter a guess guess = eval(input("Enter your lottery pick (three digits): ")) # Get digits l1 = lottery // 100; l2 = (lottery % 100) // 10; # l2 = (lottery / 10) % 10 l3 = lottery % 10; g1 = guess // 100 g2 = (guess % 100) // 1...
cdafc21021b20a0f9c72d46a79754af77178913e
SamJ2018/LeetCode
/python/python语法/day2.py
223
3.796875
4
#!/usr/bin/env python # coding=utf-8 def foo(): print("foo") def bar(): print("bar") dic = { 'foo' : foo, 'bar' : bar, } while True: choice=input(">>:") if choice in dic: dic[choice]()
17cd274e2850f19ab62c9da51fe777b058a56caf
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise05_35.py
243
3.65625
4
for number in range(6, 10000 + 1): sum = 0 divisor = number - 1 while divisor >= 1: if number % divisor == 0: sum += divisor divisor -= 1 if number == sum: print(number, end = " ")
50aa838108041994970b4a245b95fa893a34737f
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise05_09.py
279
3.765625
4
tuition = 10000 count = 1 while count <= 10: tuition = tuition * 1.05; count += 1 print("Tuition in ten years is", tuition) sum = tuition for i in range(2, 5): tuition = tuition * 1.05 sum += tuition print("The four-year tuition in ten years is", sum)
f41363225d12dd535fcef03e0a5c381a9dea06b7
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise05_13.py
234
3.640625
4
count = 1 for i in range(100, 201): if not (i % 5 == 0 and i % 6 == 0) and (i % 5 == 0 or i % 6 == 0): if count % 10 != 0: print(i, end = " ") else: print(i) count += 1
b5c1b06ef0b66d3536310427b1fbd35896875346
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise05_07.py
276
3.984375
4
import math print(format("Degree", "<15s"), format("Sin", "<15s"), format("Cos", "<15s")) for degree in range(0, 360 + 1, 10): print(format(degree, "<15d"), format(math.sin(degree * math.pi / 180), "<15.4f"), format( math.cos(degree * math.pi / 180), "<15.4f"))
52c9aea49059ced947432dd6cf05cd8c58f5ed9e
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise11_45.py
1,455
3.859375
4
import math from tkinter import * # Import tkinter class MainGUI: def __init__(self): window = Tk() # Create a window window.title("Square Function") # Set title width = 400 height = 150 canvas = Canvas(window, width = width, height = height) canvas.pack...
9dc7e1d18fa44ab8943c127f29d426b6fd0be8be
SamJ2018/LeetCode
/python/python语法/03字符串exercise.py
1,428
3.9375
4
# python # 转换 bool() str() int() name = " aleX " name.strip() print(name.strip().startswith('al')) print(name.endswith('X')) print(name.replace("l", "p")) print(name.partition('l')) # l也会分割出来 print(name.rsplit('l')) sname = name.rsplit('X') print(type(sname)) print(name.upper()) print(name.lower()) print(n...
dbbba75541ad17b8513956f52d8ca7befbb8111c
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise10_27.py
672
3.984375
4
def main(): s = input("Enter integers separated by spaces from one line: ") items = s.split() # Extracts items from the string numbers = [ eval(x) for x in items ] # Convert items to numbers if isConsecutiveFour(numbers): print("The series has consecutive fours") else: print("The s...
7a02905d8b244c6e96eb871ff8099d6c0db26e03
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise04_11.py
1,309
4.125
4
# Prompt the user to enter input month = eval(input("Enter a month in the year (e.g., 1 for Jan): ")) year = eval(input("Enter a year: ")) numberOfDaysInMonth = 0; if month == 1: print("January", year, end = "") numberOfDaysInMonth = 31; elif month == 2: print("February", year, end = "") if year % 40...
f8288db5e882865f27e312c79cf837e966bec95d
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise10_03.py
485
3.703125
4
def main(): s = input("Enter the integers between 1 and 100: ") items = s.split() # Extracts items from the string numbers = [ eval(x) for x in items ] # Convert items to numbers counts = 100 * [0] for value in numbers: if value <= 100 and value >= 0: counts[value - 1] += 1 ...
317506d5361b478397604918249afb20bf51f762
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise10_05.py
334
4.03125
4
def main(): s = input("Enter the numbers: ") items = s.split() # Extracts items from the string list1 = [ eval(x) for x in items ] # Convert items to numbers list2 = [] for number in list1: if not (number in list2): list2.append(number) print("The distinct numbers are", l...
8eed6f99e34f720e1b6a2c0e7d406e938fbc11ff
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise11_27.py
738
4.1875
4
def main(): SIZE = 3 print("Enter a 3 by 3 matrix row by row: ") m = [] for i in range(SIZE): line = input().split() m.append([eval(x) for x in line]) print("The column-sorted list is ") printMatrix(sortColumns(m)) def reverse(m): for i in range(len(m)): for j ...
be6bed1c6c15377c1bd5d78c321d8413fcb85bf5
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise06_17.py
643
4.28125
4
import math def main(): edge1, edge2, edge3 = eval(input("Enter three sides in double: ")) if isValid(edge1, edge2, edge3): print("The area of the triangle is", area(edge1, edge2, edge3)) else: print("Input is invalid") # Returns true if the sum of any two sides is # greater than the th...
7e95d4951c3a8cc07f207e8c169c7fc8c8dbd367
SamJ2018/LeetCode
/python/python语法/pyexercise/Exercise02_13.py
244
3.859375
4
number = eval(input("Enter an integer: ")) d1 = number % 10 number = number // 10 d2 = number % 10 number = number // 10 d3 = number % 10 number = number // 10 d4 = number % 10 number = number // 10 print(d4) print(d3) print(d2) print(d1)
34872477a8eccf6cd0278144802a9da0cbd44f9c
capoletti/python-basico
/python-basico/strings_except.py
282
3.71875
4
""" Strings e Excecoes """ texto_string = "tratando string" print len(texto_string) #string com multiplas linhas multi_line = """primeira linha segunda linha terceira linha""" print multi_line try: print 0/0 except ZeroDivisionError: print 'erro ao dividir por zero'
2608df1e9d7d7a7dabfc23600cc0ab47b70883a3
EvgenyTyurin/Dictionary-demo
/dict.py
571
4.34375
4
# Bill Lubanovich "Introducing Python" # Chapter 3, Exercises 10-14: Dictionary demo # English/French dictionary e2f = { "dog": "chien", "cat": "chat", "walrus": "morse"} print("English/French dictionary: " + str(e2f)) # Walrus in french? print("walrus in french = " + e2f["walrus"]) # Ma...
3842697b1f14c70664275a9fa76118c389c4506b
BogdanYatsiv/HelloWorld
/hw1(2).py
248
3.75
4
print("Now some questions\n") user_name = input("What is your name?\n") user_age = input("How old are you?\n") user_city = input("Where do you live?\n") print("Hello",user_name) print("Your age is",user_age) print("You live in",user_city)
6afa356e1d1d93ad2e330f3dca2f1b8e683866de
ambushneupane/videoMerger
/listvideos.py
625
3.9375
4
#this script returns the list of videos (.mp4) from the path you choose. import os pathOfVideo=input("Enter the full path where videos are located.") def array_Of_Videos(): fileExists= os.path.exists(pathOfVideo) #returns a boolen if fileExists: dirList= sorted(os.listdir(pathOfVideo)) #returns list of fil...