blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string |
|---|---|---|---|---|---|---|
2f378c0a2d6c83b2386de46d40fcef336c57a94d | wangtao090620/LeetCode | /wangtao/leetcode/0106.py | 991 | 3.953125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-02-15 09:39
"""
根据一棵树的中序遍历与后序遍历构造二叉树。
注意:
你可以假设树中没有重复的元素。
例如,给出
中序遍历 inorder = [9,3,15,20,7]
后序遍历 postorder = [9,15,7,20,3]
返回如下的二叉树:
3
/ \
9 20
/ \
15 7
"""
... |
8ce8bbc8a02e6cd8b06feefdd1514f73175b9978 | wangtao090620/LeetCode | /wangtao/leetcode/0538.py | 685 | 3.609375 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-01-12 15:10
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
# 反向的有序遍历 右->根->左
c... |
6eea0940ef48de0d26b54ee7f1b866aed6daac1c | wangtao090620/LeetCode | /wangtao/leetcode/0128.py | 759 | 3.515625 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2019-12-24 18:07
"""
给定一个未排序的整数数组,找出最长连续序列的长度。
要求算法的时间复杂度为 O(n)。
示例:
输入: [100, 4, 200, 1, 3, 2]
输出: 4
解释: 最长连续序列是 [1, 2, 3, 4]。它的长度为 4。
"""
from typing import List
class Solution:
... |
b988fb07367396cb74852e86a7bc21211c388143 | wangtao090620/LeetCode | /wangtao/leetcode/0136.py | 746 | 3.59375 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2019-12-24 18:19
"""
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
说明:
你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?
示例 1:
输入: [2,2,1]
输出: 1
示例 2:
输入: [4,1,2,1,2]
输出: 4
"""
from typing impor... |
dba1f34d38eca8b8c74c8fd9c89a9a50016e5cfc | wangtao090620/LeetCode | /wangtao/leetcode-medium/0560.py | 699 | 3.5 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-28 22:37
from typing import List
"""
给定一个整数数组和一个整数 k,你需要找到该数组中和为 k 的连续的子数组的个数。
前缀和
"""
class Solution:
def subarraySum(self, nums: List[int], k: int) -> int:
sum_v, r... |
32a08ed7960c22b393388da650d132d8410417d4 | wangtao090620/LeetCode | /wangtao/leetcode-easy/0001.py | 578 | 3.578125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-14 22:53
"""
两数之和,考察hash值
hash k:值 value:脚标
"""
from typing import List
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hash_map = dict... |
927517a9558bd3334e8f76b5f1af27fd8462c9a5 | wangtao090620/LeetCode | /wangtao/leetcode/0287.py | 1,127 | 3.890625 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-01-07 17:41
"""
给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和 n),
可知至少存在一个重复的整数。假设只有一个重复的整数,找出这个重复的数。
示例 1:
输入: [1,3,4,2,2]
输出: 2
示例 2:
输入: [3,1,3,4,2]
输出: 3
"""
from typing impo... |
795ce3aa84efb2d2cb0e9b906665849126ca3950 | wangtao090620/LeetCode | /wangtao/leetcode/0124.py | 1,195 | 3.5 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2019-12-24 15:26
"""
给定一个非空二叉树,返回其最大路径和。
本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。
示例 1:
输入: [1,2,3]
1
/ \
2 3
输出: 6
示例 2:
输入: [-10,9,20,null,null,15,7... |
d39be3572bd3518d49279b377a7d9b40e481fd1c | wangtao090620/LeetCode | /wangtao/leetcode/0010.py | 2,265 | 3.546875 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2019-11-15 17:02
# 给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配。
#
# '.' 匹配任意单个字符
# '*' 匹配零个或多个前面的那一个元素
# 所谓匹配,是要涵盖 整个 字符串 s的,而不是部分字符串。
#
# 说明:
#
# s 可能为空,且只包含从 a-z 的小写字母。
# p 可能为空,且只包含... |
31690e2b2fd1d4777f6bf148341b089f1cf4981c | wangtao090620/LeetCode | /wangtao/leetcode-easy/0058.py | 537 | 3.890625 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-15 23:56
class Solution:
def lengthOfLastWord(self, s: str) -> int:
flag = count = 0
for i in s[::-1]:
if flag == 0 and i == ' ':
con... |
0fcd6cb370b7c54718925841eaf3e382e4633731 | wangtao090620/LeetCode | /wangtao/leetcode/0046.py | 573 | 3.640625 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2019-12-05 10:19
class Solution:
def permute(self, nums):
res = []
self.dfs(nums, [], res)
return res
def dfs(self, nums, path, res):
if not nums:
... |
db11701afc10da8eb81b2636b047f48e131c1aed | wangtao090620/LeetCode | /wangtao/leetcode/0494.py | 1,697 | 3.78125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-01-11 12:23
"""
给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S。现在你有两个符号 + 和 -。对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前面。
返回可以使最终数组和为目标数 S 的所有添加符号的方法数。
示例 1:
输入: nums: [1, 1, 1, 1, 1], S: 3
输出: 5
解释:... |
e608976856d8f955efc415a64d98e60404720df4 | wangtao090620/LeetCode | /wangtao/leetcode-medium/0036.py | 1,547 | 3.734375 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-24 14:29
from typing import List
"""
row没有重复的
col没有重复的
3X3没有重复的
box_index = (row // 3) * 3 + columns // 3 遍历子数独
"""
class Solution:
def isValidSudoku(self, board: List[List... |
a99fed46dd115af6631d3c9b8962258cf6d9690f | wangtao090620/LeetCode | /wangtao/leetcode/0572.py | 784 | 3.828125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-02-15 17:50
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
... |
2f4367e022ce52e304e555013e2b8fbae443da62 | wangtao090620/LeetCode | /wangtao/leetcode-medium/0006.py | 617 | 3.6875 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-20 23:29
"""
Z子变换
"""
class Solution:
def convert(self, s: str, numRows: int) -> str:
if numRows < 2:
return s
i, flag = 0, -1
res = [""] * ... |
da10379660723e79763c1a514662a649c13ebaa5 | wangtao090620/LeetCode | /wangtao/leetcode-easy/0083.py | 537 | 3.53125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-16 13:24
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
... |
7c534a99dc87b97249ce2e63772f865ae800b6d6 | wangtao090620/LeetCode | /wangtao/leetcode/0543.py | 744 | 3.859375 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-01-13 09:37
# 最长路径 =
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Sol... |
2c23a4c8240dbb01f2b2752204feb9f72d03c537 | wangtao090620/LeetCode | /wangtao/leetcode-easy/0167.py | 656 | 3.578125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-17 23:36
from typing import List
"""
双指针 + 二分
脚标不是从0开始,所以每次都要加1
"""
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left, right = 0, l... |
f6c0c54a763f72da690cdd70134f0b4217065e04 | wangtao090620/LeetCode | /wangtao/leetcode-easy/0226.py | 502 | 3.703125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-18 15:56
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
... |
149a2b2bb77b8927f200a042323b9c206ab10ae5 | wangtao090620/LeetCode | /wangtao/leetcode/0079.py | 2,586 | 3.65625 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2019-12-13 10:42
"""
给定一个二维网格和一个单词,找出该单词是否存在于网格中。
单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。
示例:
board =
[
['A','B','C','E'],
['S','F','C','S'],
['A','D... |
9a723934939366688cb6804631f15677f7f69f88 | wangtao090620/LeetCode | /wangtao/leetcode/0714.py | 935 | 3.703125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2019-12-24 09:56
"""
给定一个整数数组 prices,其中第 i 个元素代表了第 i 天的股票价格 ;非负整数 fee 代表了交易股票的手续费用。
你可以无限次地完成交易,但是你每次交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。
返回获得利润的最大值。
示例 1:
输入: prices = [1, 3, 2, ... |
240e9b34b2b23d6b051315168914d01c4c3bf045 | wangtao090620/LeetCode | /wangtao/leetcode-medium/0146.py | 1,448 | 3.5 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-27 11:33
"""
init get put
双链表
关键写写出add和remove
"""
class Node:
def __init__(self, k, v):
self.key = k
self.val = v
self.pre = None
self.next =... |
6b6afc7e47b7bd237ffab61c50c957a8f21f7d9e | wangtao090620/LeetCode | /wangtao/leetcode-easy/0234.py | 959 | 3.609375 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : wangtao
# @Contact : wangtao090620@gmail.com
# @Time : 2020-07-18 16:07
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
""""
快慢指针
快指针走完的时候,慢指针在一半的位置
"""
class Solution:
def isPalindrome(self, hea... |
f9e1b08791f6f67ec34222cef6d1f92495f5e280 | kamalkishorsingh/python | /for1_loop.py | 277 | 4.125 | 4 | # Program to iterate through a list using indexing
genre = ['pop', 'rock', 'jazz']
# iterate over the list using index
#for i in range(len(genre)):
for i in genre:
print ("I like", i)
#digits = [0, 1, 5]
#for i in digits:
# print(i)
#else:
# print("No items left.")
|
ea2da489554a3695057def170ea9b110b3dae15f | apexcz/devopsTraining | /module1/classy.py | 842 | 3.953125 | 4 | from abc import abstractmethod
class Animal:
def __init__(self):
self.distance_traveled_in_km = 0
self.time_taken_in_mins = 0
def move(self, distance):
distance_moved = 0
while(distance_moved < distance):
self.time_taken_in_mins += self.time_to_travel_one_km()
... |
b27e02c0a81a45d0679aa4bfcbbc6e7f66706ad0 | jaygoyani1/Solved_Leetcode_Python | /time-based-key-value-store/time-based-key-value-store.py | 964 | 3.625 | 4 | class TimeMap:
def __init__(self):
"""
Initialize your data structure here.
"""
self.list = collections.defaultdict(list)
def set(self, key: str, value: str, timestamp: int) -> None:
self.list[key].append((timestamp,value))
def get(self, ... |
e82f299041a76be1f3db73f31a1edf170b8eced1 | iknight7000/lambdata-iknight | /lambdata/helper_functions.py | 1,596 | 4.28125 | 4 | """ These helper functions will be used to count
the total null values and turn lists into columns """
import pandas as pd
import numpy as np
from faker import Faker
#Assign the method Faker to fake
fake = Faker()
#Import the df for testing purposes
df = pd.read_csv(
"https://raw.githubusercontent.com/iknight7... |
678171e70411c2ced1606974172ad96ffb5cf0e9 | gonayak/assignment | /lab3_d.py | 385 | 4.1875 | 4 | # Write a function that accepts a list and doubles each value in the list.
# When no input parameter is provided, return an empty list
list1= [3,4,5,6]
list2=[]
def doublelist(n):
new_list= []
#if the list is empty
if not n: pass
#if list is not empty
for i in n:
new_list.append(... |
9e031edae20ff9f19b6e15216d1c3c23f816f25c | baroodya/cos429-a2 | /utils.py | 7,664 | 3.71875 | 4 | import os, pickle
import numpy as np
import cv2
class Softmax(object):
def __init__(self):
self.W = None
def train(self, X, y, learning_rate=1e-3, reg=1e-5, num_iters=100,
batch_size=200, verbose=False):
"""
Train this linear classifier using stochastic gradient descent.... |
37ce69b3dfc6c0d00465ed3720680faef6c33590 | TheMorpheus407/AdventOfCode2020 | /11.py | 2,356 | 3.515625 | 4 | import itertools
adjacent = [(i, j) for i, j in itertools.product(range(-1, 2, 1), repeat=2) if i != 0 or j != 0]
def count_adjacent_seats(row_id, col_id, seats):
counter = 0
for off_i, off_j in adjacent:
if 0 <= row_id + off_i < len(seats) and 0 <= col_id + off_j < len(seats[row_id + off_i]) and seats... |
0eee19c9f767ce7aba0fe967b09b48fd7b1b0b49 | Sudarat1003/Mee | /Untitled1.py | 948 | 3.75 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[2]:
x=10
y=5
z=x+y
print (z)
# In[5]:
money=150
incomePD=300
cosPD=120
result=150+300*30-120*30
print(result)
# In[14]:
x=True
y=False
z=x or y
a=10
b=5
c=a>b
c=5
prin(c)
# In[11]:
a=10
b=5
c=a+b
b=10
print(b)
# In[16]:
a=10
b=12
c=a+b
a=a+5
print(a)
# In[... |
66d9f9b3b870c4ec3791a38e4fff3eb2e0323e42 | FPU-CIS03/CIS312-Project2 | /mini_project_2_LawlerCarroll.py | 7,563 | 4.34375 | 4 | #For this project, Michael researched and found prices for our ingredients and helped with formatting while I composed the logic \
#and structure of the code.
#Importing the math module allows us to do some rounding that will come in handy later.
import math
#Explains recipe and objective.
print("My family has... |
d233bc0b57a9b8977e936bdc3dcaed23b2938578 | Raihan-J/Python-Spoken-Tutorial | /Testing and Debugging/find_lcm.py | 400 | 3.765625 | 4 | from find_gcd import gcd
def lcm(a, b):
return (a * b) / gcd(a, b)
if __name__ == '__main__':
for line in open('lcmtestcases.txt'):
numbers = line.split()
x, y = int(numbers[0]), int(numbers[1])
result = int(numbers[2])
if lcm(x, y) != result:
print ("Faile... |
6c7618e90f579eb69b67318f6a29a2bdc5835066 | montilos-zhang/testPython | /myLib.py | 285 | 3.765625 | 4 | class Hello:
def __init__(self,name):
self._name=name
def sayHello(self):
print("Hello {0}".format(self._name))
class Hi(Hello):
def __init__(self, name):
Hello.__init__(self,name)
def sayHi(self):
print ("Hi {0}".format(self._name))
|
335a3bb400ea97d737dec9b18e7a85989aad019c | konpapp/curly-spoon | /CS50/greedy_change.py | 568 | 3.546875 | 4 | from cs50 import get_float
while True:
dollars = get_float("Change owed: ")
if dollars > 0:
break
change = round(dollars * 100)
# Variable to track number of coins
minCoins = 0
while change > 0:
# Quarters first
if change >= 25:
change -= 25
minCoins += 1
# Then dimes
... |
a6d6ac7d5894da1b625df3dbeee3c0edefb57f79 | itdxer/neupy | /neupy/algorithms/gd/step_updates.py | 8,238 | 3.578125 | 4 | import tensorflow as tf
from neupy.utils import asfloat, function_name_scope
__all__ = ('step_decay', 'exponential_decay', 'polynomial_decay')
def init_variables(initial_value, iteration=0, name='step'):
iteration = tf.Variable(
asfloat(iteration),
dtype=tf.float32,
name='iteration',
... |
e7ed98b06453b000df0f298a7147484d13238d6f | volneygs/Hackerrank | /findTheRunnerUpScore.py | 616 | 3.546875 | 4 | import sys
def findRunnerUpScore(num, scores):
scoreList = list(map(int, scores.split()))
first = scoreList[0]
second = scoreList[0]
for i in range(len(scoreList)):
if(scoreList[i] >= first):
first = scoreList[i]
for j in range(len(scoreList)):
if(scoreLi... |
58bc3b3c605a5abe56e3b56ef6dffcd86ff8761d | arm456/Hackerrank | /Arrays/MaxNonNegativeSubArray/MaxNonNegativeSubArray.py | 1,353 | 4.09375 | 4 |
******* Max Non Negative SubArray ******
Find out the maximum sub-array of non negative numbers from an array.
The sub-array should be continuous. That is, a sub-array created by choosing the second and fourth element and skipping the third element is invalid.
Maximum sub-array is defined in terms of the sum of the ... |
1f54a197d7112a4ed3d17c0917b674bf1e63da10 | arm456/Hackerrank | /SimplePython/SymmetricSquare.py | 1,344 | 4.375 | 4 | # A list is symmetric if the first row is the same as the first column,
# the second row is the same as the second column and so on. Write a
# procedure, symmetric, which takes a list as input, and returns the
# boolean True if the list is symmetric and False if it is not.
import math
def symmetric(input):
# Your c... |
fcb4266dab11f3631a8d80ccde1469d93abde708 | arm456/Hackerrank | /Arrays/LargestNumber/LargestNumber.py | 658 | 4.0625 | 4 |
/*
Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.
For example:
Given [3, 30, 34, 5, 9], the largest formed number is 9534330.
Note: The result may be very large, so you need to return a string instead of an integer.
*/
class Solution:
# @param A : t... |
940fd23212404b0ee0530d0d4abfa13361da8bba | mrmundt/pyomo | /pyomo/contrib/mindtpy/tests/MINLP4_simple.py | 1,651 | 3.609375 | 4 | # -*- coding: utf-8 -*-
""" Example 1 in Paper 'Using regularization and second order information in outer approximation for convex MINLP'
The expected optimal solution value is -56.981.
Ref:
Kronqvist J, Bernal D E, Grossmann I E. Using regularization and second order information in outer approximation for conve... |
f24ebd33395eb1fd22ae4940011feace85c80181 | anastasia-nesterenko/LRUCache | /Node.py | 442 | 3.859375 | 4 | class Node:
"""A class to represent a node of doubly linked list
Attributes
----------
key : Any
key of the node
val : Any
value of the node
next : Node
link to the next node in cache
prev : Node
link to the previous node in cache
"""
def __init__(se... |
39ef708f809cfeed8f3eab6e880a4504fe27c70e | taylor-fancher/Python | /Functions Intermediate 2/Functions Intermediate 2.py | 2,295 | 4.0625 | 4 | #1 Update values in Dictionaries and Lists
x = [ [5,2,3], [10,8,9] ]
students = [
{'first_name': 'Michael', 'last_name' : 'Jordan'},
{'first_name' : 'John', 'last_name' : 'Rosales'}
]
sports_directory = {
'basketball' : ['Kobe', 'Jordan', 'James', 'Curry'],
'soccer' : ['Messi', 'Ronaldo', 'Rooney']
}
... |
a08eb122d6d82414b491211e8c30e5bbdeb35c73 | arkhatic/terminal-todo | /src/db.py | 6,377 | 3.9375 | 4 | import sqlite3
import os
from datetime import *
import locale
import shutil
# date and welcome
locale.setlocale(locale.LC_ALL, '')
today = datetime.today().strftime('%d-%m-%B').split('-')
print(f'Boas vindas ao terminal todo! Hoje é dia {today[0]} de {today[2]}!')
## useful functions
# convert tuple to string
def toS... |
ca67c478be3dcd322a41d4569c14a38c9778c2f5 | BitnaKeum/LCS-Length_Top-down_Memoization_Python | /main.py | 2,067 | 3.578125 | 4 | import time
import random
import string
from matplotlib import pyplot as plt
def random_input(n): # Random input
rand_str = ""
for i in range(n): # n개의 문자 생성
rand_str += str(random.choice(string.ascii_uppercase)) # 랜덤한 대문자 문자열 생성
return rand_str
def MAX(num1, num2): # 더 큰 값 반환
... |
fbb4240bf42387a21635d432eacaf6b8b8fab020 | OdhiamboJacob/If...else | /Monty1/hello.py | 572 | 3.984375 | 4 | print('Hello World')
print("Hello Friend")
print('I won\'t be able to come.')
print(2/2)
print('Football\\rugby')
name=input('Enter your name')
print('Hello {}'.format(name))
class BBIT:
def __init__(self,first_name,last_name):
self.first_name=first_name
self.last_name=last_name
def Student(sel... |
125bbfab4503f01c0fdb1745d1e6e02ffb061944 | Guzya1/homework | /file4.py | 1,381 | 4.03125 | 4 | '''
a=input ("Имя:")
b=input ("Возраст:")
c=input ("Любимый фильм:")
print(f'Меня зовут, {a.title()}, мне {b.upper()} лет.\n Ваш фильм {c.title()} меня заинтересовал.')
a="Google создаст специальную команду для поиска багов в особо важных приложениях."
print(len(a.split()))
b="У вас есть строка 'Запуск Ethereum 2.0 с... |
607c18b56d16a5454a5f55be9f26c4a6330414d7 | nguytinh/Python-Backup | /1.3.2/Nguyen_1.3.2.py | 581 | 4.125 | 4 | def add_tip(total, tip_percent):
'''Return the total amount including tip'''
tip = tip_percent*total
return total + tip
def hyp(leg1,leg2):
'''returns the length of the hypotenuse'''
return ((leg1**2 + leg2**2)**0.5)
def mean(a,b,c):
'''Finds the mean of 3 numbers'''
return ... |
f40804a8627074f6a6a1dfa474e02e299c21f4cb | nguytinh/Python-Backup | /1.3.3/Nguyen_1.3.3.py | 3,670 | 3.875 | 4 | from __future__ import print_function # use Python 3.0 printing
'''Procedure'''
# 1-5 N/A
'''Part 1: Conditionals'''
# 6a. Prediction: I think that the output would be True.
# My prediciton was correct.
# 6b. Prediction: I think that the output will be True.
# My prediction was correct again.
# 7. I made a compound c... |
41eaeaa11a09b4ae0ddb36236ccd25e0c7528195 | klenderreis/Python | /contaSegundos.py | 353 | 3.578125 | 4 | segs = input("Por favor, entre com o número de segundos que deseja converter: ")
total = int(segs)
dias = total // 86400
seg_rest = total % 86400
horas = seg_rest // 3600
seg_restantes = seg_rest % 3600
minutos = seg_restantes // 60
segundos = seg_restantes % 60
print(dias,"dias,",horas,"horas,",minutos,"mi... |
6786345fbe5d5d9cc8c46f3e5309c8dbba169d94 | izasab/ENG-SCI-25 | /beginner neural nets/IZA CLASS CODE DEMO.py | 895 | 3.578125 | 4 | from numpy import exp, array, random, dot
def sig(x):
return 1 / (1 + exp(-x))
def sig_der(x):
return x * (1 - x)
inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]]) #TRAINING INPUT DATA
outputs = array([[0, 1, 1, 0]]).T #TRAINING OUTPUT DATA
weights = 2 * random.random((3, 1)) - 1 #RANDOM NE... |
b78c38eca0f760b9356e6c1ddb2ce6d2492f31aa | newbiemonty/learnpy | /stack.py | 2,250 | 4.15625 | 4 | class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def is_empty(self):
if len(self.items) > 0:
return False
else:
return True
def size(self):
... |
2117b310c3844d50598b5c36c75f29031c3b6b58 | redlotus88/PythonDemo | /fileutils/FileReader.py | 319 | 3.640625 | 4 | # -*- coding:utf-8 -*-
import sys
import os
def readlines(path):
if exist(path):
f = open(path, 'r')
return f.readlines()
def exist(path):
if not os.path.isfile(path):
raise TypeError(path, " does not exists")
return True
if __name__ == '__main__':
exist('FileReader.py')
print(readlines('FileReader.py')) |
840a2a808fa7dae0dec2e1733f0474b1fb5010c2 | liam-fletcher1/ICS3U-Assignment-5-Python | /assignment5.py | 1,169 | 4.375 | 4 | #!/usr/bin/env python3
# Created by: Liam Fletcher
# Created on: Oct 2021
# This program asks the user for two numbers
# Then the programs find the LCM of the two numbers
def main():
# this tells the user the LCM of two numbers
# input
number1 = input("Please enter the first number: ")
number2 = inp... |
8238d73c20600dd2bbabe1c93335fb06326951bf | ashleymichal/computation | /set/set-py-function-unanswered | 1,058 | 3.515625 | 4 | #!/usr/bin/env python
def contains(i, s): return s(i)
def containsAll(elems, s):
return "TODO"
def containsNo(elems, s):
return "TODO"
empty = return "TODO"
def singleton(i):
return "TODO"
def multiple(*elems):
return "TODO"
def insert(i, s):
return "TODO"
def remove(i, s):
return "TODO... |
852244d5f034231bfa381bdf67e7ea234e927ee6 | unevencoconut/thesnek | /booleans.py | 734 | 4.15625 | 4 | # STRINGS
# Since I'm already familiar with Booleans from other languages,
# I'll just mark items here that catch my eye
# bool()
# The bool() function allows you to evaluate any value, and give you True or False in return.
print( bool("Hello") ) # A String returns True
print( bool(15) ) #A Int returns True
x = "Hell... |
3276441a052f0fda879a9e65937f2c6bb22b87d3 | unevencoconut/thesnek | /numbers.py | 1,240 | 4.4375 | 4 | #NUMBER TYPES
# Three Number Types
# int
# float
# complex
x = 1 # int
y = 2.8 # float
z = 1j # complex
print(x,y,z)
# INT
# These are WHOLE numbers, positive or negative, without decimals, of unlimited length
x = 1
y = 483029543278463287
z = -478342986
print(x,y,z)
# Float ( Floating Point Number )
# ... |
7b2603f11caec72e7ce96b674a6e0382907c9868 | gobuunnwo/python | /28.py | 377 | 3.90625 | 4 |
class Employee:
def __init__(self,name,address):
self.name = name
self.address = address
# 古い書き方
def fullname(self):
return "{}{}".format(self.name,self.address)
emp1 = Employee("A","a")
emp12= Employee("B","b")
print(emp1)
print(emp12)
print(emp1.name)
print(emp12.name)
print(em... |
4383bce05affd0c691b218750f6fa48beb7338c3 | gobuunnwo/python | /15_def.py | 167 | 3.734375 | 4 | # def②
def greet(name,time):
print(f"good morning {name},hope your great at this {time}")
x=input("enter your name")
y=input("enter the time")
greet(x,y)
|
3b6e420b83b38151d9adc098210af849c6ab4603 | gobuunnwo/python | /10.py | 334 | 3.625 | 4 | # while文
name=20
age=2
while age<name:
if name%2==0:
print(age)
age+=2
i=1
while i < 6:
print(i)
i+=1
i=1
while i<6:
print(i)
if i ==3:
break
i+=1
i=0
while i <6:
i+=1
if i==3:
continue
print(i)
i=0
while i<11:
i+=1
if i%2==0:
continue
... |
197cc37d3697cfdeb7ce58e29ee5f1878bb1116f | gobuunnwo/python | /9.py | 225 | 3.90625 | 4 | # for文①
fruits = ["apple","banana","cherry"]
for x in fruits:
print(x)
# for文②
boxes =["A","B","C","D","E"]
for box in boxes[1:4]:
if box =="A":
print(f"{box}-say hello")
else:
print(box) |
1c06b3b8e8631f884e32ae9cdcd1e2bf51ecb54a | GanMan78/BeWithPython | /Rec.py | 725 | 4.1875 | 4 | # Recursion : Calling the function from same function itself.
def DisplayI(no):
for i in range(no): # Iteration using for loop
print("Hello")
def DisplayIW(no): # Iteration using while loop
while no!=0:
print("Hello")
no=no-1
def DisplayR(no):
if no!=0:
no=no-1
print("Hello")... |
5e366aaec5ec357098d05303554f91c42fb4c463 | GanMan78/BeWithPython | /Demo.py | 276 | 3.921875 | 4 |
def Addition(no1,no2):
return no1+no2
def main():
print("Enter first number")
value1=int(input())
print("Enter second number")
value2=int(input())
ret=Addition(value1,value2)
print("Addition of 2 numbers:",ret)
if __name__=="__main__":
main() |
4efcdd2792ef42ba6d6b442b6fd70adc1c03035b | utp2018th/plot-graph | /color.py | 276 | 3.671875 | 4 | import numpy as np
def generate_random_color():
ans = ""
while len(ans) != 7:
ans = '#{:X}{:X}{:X}'.format(*[np.random.randint(0, 255) for _ in range(3)])
return ans
if __name__ == "__main__":
for i in range(3):
print(generate_random_color())
|
d0710d3b12aa7f49743cc9068f7a06266bf1a9c4 | yichenluan/LeetCodeSolution | /backup/Python/148.py | 885 | 3.796875 | 4 | class Solution(object):
def sortList(self, head):
if not head or not head.next:
return head
slow = head
fast = head
pre = None
while fast and fast.next:
fast = fast.next.next
pre = slow
slow = slow.next
pre.next = None
... |
5a3556da0b36d1e833222e1c1ce05e6b16b0ee35 | yichenluan/LeetCodeSolution | /backup/Python/147.py | 1,178 | 3.671875 | 4 | class Solution(object):
def insertionSortList(self, head):
if not head:
return None
dummy = ListNode(-9999)
dummy.next = head
curr = head
pre = dummy
while curr:
node = curr
pre.next = curr.next
begin = dummy
... |
24d586a1faccb2413f120048d3ee5b192a353b21 | yichenluan/LeetCodeSolution | /backup/Python/222.py | 458 | 3.53125 | 4 | class Solution(object):
def countNodes(self, root):
if not root:
return 0
l = self.height(root.left)
r = self.height(root.right)
if l > r:
return self.countNodes(root.left) + (1 << r);
else:
return self.countNodes(root.right) + (1 << l);
... |
25a535e5c023be25a73d61fdb53cda4c12034aea | yichenluan/LeetCodeSolution | /backup/Python/80.py | 545 | 3.5 | 4 | class Solution(object):
def removeDuplicates(self, nums):
n = len(nums)
count = 0
flag = 0
for i in range(1, n):
if nums[i] == nums[i - 1]:
flag += 1
if flag > 1:
count += 1
if nums[i] != nums[i - 1]:
... |
13197febba4aadc9af729b749b41784372d4ba7a | zulushakaka/named-entity-discovery-and-linking | /code_ner_bert/dictionary.py | 733 | 3.5 | 4 |
stopwords = set(["a", "an", "the", "of", "at", "on", "upon", "in", "to", "from", "out", "as", "so", "such", "or", "and", "those", "this", "these", "that",
"for", ",", "is", "was", "am", "are", "'s", "been", "were"])
other_pronouns = set(["who", "whom", "whose", "where", "when","which", 'i'])
def is_url(word):
... |
5ee491f9191b10d1f6ad064a55fe1d1572bcfc9c | willsir14/learningpython | /decorator/divide.py | 488 | 3.96875 | 4 | # Decorator can enhance the functionality of function
def divide_with_power(func):
def wrapper(a,b):
if (b == 0):
return "Denominator is 0 cannot divide"
print("Divide Sucessful !!! The result is: ", end="")
return func(a,b)
return wrapper
@divide_with_power
def divide(a,b):... |
ec92006f6f66f9ae64955e3b8dfa19601fc281e8 | Divyansh-Pal/Python-Project | /simple-interest.py | 195 | 4 | 4 | #WAP to calculate Simple Interest (SI)
P= int(input("Enter Principal amount here:"))
R= float(input("Enter Rate of Interest here:"))
T= float(input("Enter Time here:"))
print(P*R*T/100)
|
4ea014946ce2c9aa6c7994805dfd5bee18d398e1 | shrutee2000/taskq1.py | /task3.py | 102 | 3.53125 | 4 | c=0
n1=int(input("n1"))
n2=n1
while n2!=0:
c=c+1
n2=n2//10
print(f"no of digits in {n1}={c}")
|
8120996dfb9e899371b4d99e7bd289cd2e92fdb9 | lamperem/play-python | /control-structures/ex-02.py | 103 | 3.75 | 4 | #if Statements
a = 6
b = 5
if a>b:
print(a, "is more bigger of ", b)
print("Program ended") |
9329791e035995c617650bf567a514069fab97c0 | lamperem/play-python | /control-structures/ex-11.py | 119 | 3.796875 | 4 | #Operator Precedence
x = 4
y = 2
if not 1 + 1 == y or x == 4 and 7 == 8:
print("Yes")
elif x > y:
print("No") |
a31270efac9905ad6a4a2f68a4d23dbd20ec5979 | lamperem/play-python | /basic/ex-15.py | 107 | 3.84375 | 4 | # Assign operations
x = 2
print(x)
x += 3
print(x)
y = "Spam"
print(y)
y += "eggs"
print(y) |
c537324f7fd1cd72d02381dd93955e12225b5082 | zzzhangpluto/04-Python-Programming | /3.0 数字计算.py | 1,876 | 4.375 | 4 | #3.1 数值数据类型
type(3)
type(3.14)
type(3.0)
myInt=-32
type(myInt)
myFloat=32.0
type(myFloat)
#3.2 类型转换和舍入
round(3.14)
pi=2.1415926
round(pi,2)
round(pi,3)
int("32")
float("32")
float("9.8")
# A program to calculate the value of some change in dollars
def main():
print("Change Counter")
pri... |
a32caaec08a9afaf71c406a36b1d3d7e69afd045 | farriork5780/cti-110 | /P2HW1_Basicmath_keisshawnfarrior.py | 307 | 4.15625 | 4 | #program that does math
#6-19-20
#CTI - 110 P2HW1
#keisshawn farrior
num1 = float(input("enter the first number:"))
num2 = float(input("enter the second number:"))
sum = num1+ num2
mul=num1*num2
print("the sum of the number is:",sum)
print("the product of given numbers is:",mul)
#display the sum
#display the product
|
9d924635790e97a62fc82c033ba70c8554054b13 | rjorth/lab3-key | /p6.py | 1,477 | 3.625 | 4 | class Stack(object):
def __init__(self):
self.storage = []
def push (self, newValue):
self.storage.append( newValue )
def top(self ):
return self.storage[len(self.storage) - 1]
def pop(self ):
result = self.top()
self.storage.pop()
return result
def isEmpty(self):
return len(self... |
4d8b26df9ed2eda854b9c9447286f8c368ed1a77 | mudzi42/pynet_class | /class9/ex9/class9_ex9.py | 591 | 3.875 | 4 | #!/usr/bin/env python
"""
9. Write a Python script in a different directory (not the one containing mytest).
a. Verify that you can import mytest and call the three functions func1(), func2(), and func3().
b. Create an object that uses MyClass. Verify that you call the hello() and not_hello() methods.
"""
fro... |
48a4ddfb0f6b3a8d09d3eff18de6000807eb819f | willisrocks/cnc | /.archive/proglang/labs/softwarestudents/ch13 (OOP)/python/Polynomial.py | 958 | 3.921875 | 4 | class Polynomial:
def __init__(self, coef):
"""constructor"""
self.coefficient = [ ] + coef
def degree(self):
"""Highest power with a non-zero coefficient"""
return len(coefficient)
def coefficient(self, power):
"""Coefficient of given power"""
if power > len(coefficient):
return 0
return co... |
b28460d4d8aa2f537b21596bddba3631b27e1065 | tristanburgess/fresh_tomatoes | /movie.py | 1,032 | 3.75 | 4 | class Movie:
"""Encapsulates information pertaining to a particular movie.
Attributes:
title: string representing the title of the movie.
director: string representing the director of the movie.
If more than one director is known to have
worked on the movie, my favorite one is ... |
5954bdb63690e0c021b1a64d2a5ae495cd502d73 | Xinshuai-Lyu/toy-algorithms | /get_random_number_uniformly_from_huge_dataset.py | 833 | 3.875 | 4 | # """
# Given a stream of elements too large to store in memory,
# pick a random element from the stream with uniform probability.
# """
from random import randint
# element is uniformly picked
# https://www.dailycodingproblem.com/blog/how-to-pick-a-random-element-from-an-infinite-stream/
def get_random_element_unifor... |
0e128e8900515032808b9c85ae28f634cc4e9e32 | Xinshuai-Lyu/toy-algorithms | /get_list_from_product_of_other_list_except_ith_ele.py | 2,384 | 3.953125 | 4 | '''
Problem:
given an integer list L [x1, x2, x3, ..., xn], return a new list new_L that the i_th element value in new_L is the multiplication of all other elements in L except i_th element. You are not allowed to use division! Ex. L=[1,2,3], new_L=[6, 3, 2]. (Division has a problem when meeting zero)
'''
# tip1: Beg... |
47d95bde0e155f57babef0ed5855ffc59920f76b | vbrame/MinasCode | /LinkedStack.py | 1,351 | 3.859375 | 4 | from Empty import Empty
class LinkedStack:
# Nested Node Class
class Node:
def __init__(self, element, next):
self.__element = element
self.__next = next
def get_next(self):
return self.__next
def get_element(self):
return self.__elemen... |
46d0e67901fbc27cd4b3f5e004478cd75f90af1b | kroos010/cdms | /helpers/encryption.py | 1,604 | 3.75 | 4 | from helpers.typevalidation import TypeValidation
class Encryption:
alpha_capital = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alpha_lower = "abcdefghijklmnopqrstuvwxyz"
key = 7
def __init__(self, key=None):
if key is not None:
self.key = key
def encrypt(self, message):
if TypeVal... |
82debf3d64c78509bcabd4f70941504ffa3a4fc1 | ti250/notificationcenter | /notificationcenter/_notificationcenter.py | 3,258 | 3.578125 | 4 | class NotificationCenter(object):
"""
Singleton class which handles communication between objects using notifications.
"""
_instance = None
def __init__(self):
# Makes a dictionary of observers if it doesn't already exist.
# (This should only happen when the first instance is create... |
51ef550ba37fc5276fa4bee759d8be99044fd454 | natejangeles/Rosalind | /2_Transcribe_DNA.py | 443 | 4.0625 | 4 | # Transcribing a DNA sequence into an RNA sequence
# python 2_Transcribe_DNA.py 2_Rosalind_DNA.txt
import sys
input_file = open(sys.argv[1], 'r')
dna_seq = input_file.readline().strip() # A single-line text file
""" Given a DNA string t with at most 1000 nucleotdies, returns a
string, rna, corresponding to the tran... |
30dbbb58689e53414d9024c707d917efd8688228 | natejangeles/Rosalind | /3_DNA_Complement.py | 576 | 4.21875 | 4 | # Finding the reverse complement of a DNA sequence
# python 3_DNA_Complement.p 3_Rosalind_Revc
import sys
input_file = open(sys.argv[1], 'r')
dna_seq = input_file.readline().strip() # A single-line text file
""" Given a DNA string s with at most 1000 bp, returns a string
representing the reverse complement, sc, o... |
70f2e7eb7888da6e9df37242a503d69c1df7be01 | PuchatekwSzortach/software_development_best_practices_course | /sample_project/utilities.py | 1,319 | 3.828125 | 4 | """
Module with utilities
"""
def get_factorial(x):
"""
Computes factorial of x
:param x: int
:return: int
"""
if x < 0:
raise ValueError("Input must be positive, but {} was given")
factorial = 1
for value in range(1, x + 1):
factorial *= value
return factorial... |
5925bc99f5a8b83aec57a8b055227cc4762d0464 | Rsuthea-S/CoinShares | /src/main.py | 6,379 | 3.84375 | 4 | import pandas as pd
import sys
import datetime as dt
from datetime import datetime
import os
# Implement the code needed to answer the following questions and if a value is requested print it into a text file :
# 1. Parse the 2 CSV files in the data folder
#
# 2. What is the minimum low value for BTC-USD ?
#
# 3. What ... |
c48a3bc7ce7d8c1dd11641ca1ea2fc80a205ee66 | ivklisurova/SoftUni_Python_Advanced | /Multidimensional_lists/miner.py | 2,630 | 3.5 | 4 | def is_valid_cell(n, new_row, new_col):
is_valid = True
if new_row >= n or new_row < 0:
is_valid = False
elif new_col >= n or new_col < 0:
is_valid = False
return is_valid
def collect(matrix, new_col, new_row):
global coal_count
global interrupted
if matrix[new_row][new_col... |
c4fede8e4ceb633d4af78fdee4ee7df67e164984 | ivklisurova/SoftUni_Python_Advanced | /Multidimensional_lists/matrix_shuffling.py | 1,070 | 3.734375 | 4 | rows, columns = map(int, input().split(' '))
matrix = [list(input().split(' ')) for i in range(rows)]
while True:
args = input()
if args == 'END':
break
if args.startswith('swap'):
args = args.split(' ')
if len(args) == 5:
row1 = int(args[1])
col1 = int(args... |
39acb486b606999a7cf60878f758f8ec51a72f42 | ivklisurova/SoftUni_Python_Advanced | /Exam_retake/numbers_search.py | 549 | 3.65625 | 4 | def numbers_searching(*args):
my_list = []
max_num = max(*args)
min_num = min(*args)
for i in range(min_num,max_num+1):
if i not in args:
missing_number = i
my_list.append(missing_number)
s = set([x for x in args if args.count(x) > 1])
duplicate = list(s)
my_l... |
3e53d0d4d4a5f09ecbd58ac6923d346d95b43e4c | ivklisurova/SoftUni_Python_Advanced | /Comprehension/word_filter.py | 100 | 3.53125 | 4 | text = input().split(' ')
result = [x for x in text if len(x) % 2 == 0]
[print(x) for x in result] |
f392cba59873a41837e74c9f77e2e9fdf0fc5c5c | ivklisurova/SoftUni_Python_Advanced | /Comprehension/matrix_modification.py | 692 | 3.546875 | 4 | n = int(input())
matrix = [list(map(int, input().split(' '))) for x in range(n)]
while True:
args = input().split()
command = args[0]
if command == 'END':
break
row = int(args[1])
col = int(args[2])
value = int(args[3])
if command == 'Add':
if 0 <= row <= len(matrix) - 1 an... |
9f004f5923f4208913d7da3571c9943530ff902f | ivklisurova/SoftUni_Python_Advanced | /Tuples_and_Sets/count_same_values.py | 205 | 3.5625 | 4 | numbers = map(float, input().split(' '))
t = tuple(numbers)
unique_grades = []
[unique_grades.append(i) for i in t if i not in unique_grades]
[print(f'{x} - {t.count(x)} times')for x in unique_grades]
|
8b427e4889ab850d8bc57372501569ad242423f9 | ivklisurova/SoftUni_Python_Advanced | /Stacks_and_queues/water_dispenser.py | 620 | 3.734375 | 4 | from collections import deque
litters = int(input())
queue = deque()
while True:
command = input()
if command == 'Start':
break
else:
queue.append(command)
while queue:
args = input()
if args.startswith('refill'):
args = args.split(' ')
current_litters = int(args[1... |
519eea45605e3426ed0512c79714ac16d5d6dfb9 | ivklisurova/SoftUni_Python_Advanced | /Stacks_and_queues/balanced_parentheses.py | 592 | 3.84375 | 4 | text = input()
stack = []
is_balanced = True
for i in text:
if i in '({[':
stack.append(i)
if i in ')}]':
if len(stack) > 0:
b = stack.pop()
if i == ')' and b != '(':
is_balanced = False
break
elif i == '}' and b != '{':
... |
905293c562d6cd8cdd7ef742e7fb974ec39620d1 | ivklisurova/SoftUni_Python_Advanced | /Multidimensional_lists/bombs.py | 1,660 | 3.640625 | 4 | def count_alive_cells(field):
alive_cells = 0
for j in field:
for x in j:
if x > 0:
alive_cells += 1
return alive_cells
def sum_alive_cells(field):
total_sum = 0
for j in field:
for x in j:
if x > 0:
total_sum += x
return ... |
00bcc27bd1f9d4aa4f39a499e7ef913b2429fb1c | ivklisurova/SoftUni_Python_Advanced | /Exam_prep/present_delivery.py | 3,402 | 3.546875 | 4 | def santa_position(matrix):
for row in range(len(matrix)):
if 'S' in matrix[row]:
santa_position_row = row
santa_position_col = matrix[row].index('S')
santa_position_in_matrix = (santa_position_row, santa_position_col)
return santa_position_in_matrix
def cle... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.