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 |
|---|---|---|---|---|---|---|
4f27f9b1d4c1ad564a1128ddd8cca84a12e7314e | NehaRapolu3/python-tasks | /task 5.py | 252 | 4 | 4 | r=input("enter the month")
a=("January","March","May","July","August","October","December")
b=("February")
if r in a:
print("The month has 31 days ")
elif r in b:
print("The month has 28 days")
else:
print("The month has 30 days")
|
f08f53149b0aeef0f9f9542b113d19a0630be066 | Kristijan10048/PythonTutorials | /IronPython/t1/t1/t1.py | 285 | 3.59375 | 4 | #function with default arguments
def defaultArgs(test = "abrakadabra"):
print(test);
#function to calculate sum
def sum(a, b):
return a + b;
#prints hello world
print('Hello World');
#function call
c = sum(4, 5);
print(c);
#call function wiht defaults args
defaultArgs();
|
ba95e341a9625b89e624dd9a00714c552f14075a | kobesxl/ud120-ML | /svm/svm_author_id.py | 1,593 | 3.59375 | 4 | #!/usr/bin/python
"""
This is the code to accompany the Lesson 2 (SVM) mini-project.
Use a SVM to identify emails from the Enron corpus by their authors:
Sara has label 0
Chris has label 1
"""
import sys
import numpy as np
from time import time
sys.path.append("../tools/")
from email_preproc... |
17996e5adf4dd50daac386d7dd533adbebe3f523 | pengshuai2010/hello_python | /hello_python/test/fibonacci.py | 860 | 3.828125 | 4 | '''
Created on Jul 28, 2015
@author: speng
'''
class Fibonacci:
'''
generator class of fibonacci sequence
'''
def __init__(self, max_value):
self.max_value = max_value
def __iter__(self):
'''
The __iter__() method is called whenever someone calls iter(Fibonacci).
... |
98dba43b224cf4d4da94fb259d754cecd1eac732 | asiskc/python_assignment_dec8 | /function.py | 176 | 4.21875 | 4 | def odd_even(n):
if n % 2 == 0:
print ("It is an even number")
else:
print ("It is an odd number")
odd_even(int(input("enter a number"))) |
94e971d062803bda0dbee06307607932b0654849 | zongrh/untitled_python | /test02.py | 1,008 | 4.15625 | 4 | # coding=utf-8
print("hello world")
print "你好,世界!";
counter = 100 # 赋值整型变量
miles = 1000.0 # 浮点型
name = "john" # 字符串
print counter
print miles
print name
# -----------------------------标准数据类型
# Numbers(数字)
# String(字符串)
# List(列表)
# Tuple(元组)
# Dictionary(字典)
# -------------------------------Python数字
var1 = 1
var... |
0dddda651dbe0d301732ff821e905025d858d104 | zongrh/untitled_python | /py1_variable/Python_Dictionary.py | 723 | 3.96875 | 4 | # coding=utf-8
# 字典(dictionary)是除列表以外python之中最灵活的内置数据结构类型。列表是有序的对象集合,字典是无序的对象集合。
# 两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取。
# 字典用"{ }"标识。字典由索引(key)和它对应的值value组成。
dict = {}
dict["one"] = "this is one"
dict[2] = "this is two"
tinydict = {"name": "jhon", "code": 222, "dept": 62L, "msg": "非法参数异常"}
print dict["one"] # 输出键值为"o... |
a23774f21cc699e1c272105014f54ba9dabee81a | wj84234/Python_Winter_2019_1 | /ShapesAbstract.py | 1,111 | 4.03125 | 4 | import math
from abc import ABC, abstractmethod
class Shape(ABC):
def __init__(self, a=10, b=20):
self.set_params(a, b)
def set_params(self, a, b):
self._a = a
self._b = b
def get_a(self):
return self._a
def get_b(self):
return self._b
def __str__(self):
... |
7dee377d325fd5ea80bb7c096851f1ad343f7495 | ghgithub/river-flow | /src/run_scripts/flood_graph.py | 1,556 | 3.90625 | 4 | import pickle
from queue import PriorityQueue
graph = pickle.load(open('graph.pkl', 'rb'))
def flood(point):
points_in_lake = generate_lake(point)
# TODO Merge the list of points in the lake into one point
def generate_lake(point):
# Store points which are part of the lake in a list
lake = []
... |
79240a2127ba8262a1a2d25775e2034a717ef668 | cMinzel-Z/Web-crawler | /Getting_start/spider_practice/spider_start/reg_test.py | 693 | 3.609375 | 4 | # -*- coding: utf-8 -*-
import re
# \d{4}
1999-8-1
# b{2,4}
# (o|c)b
"bobby"
"ccbbc"
# \d{4}(y|-)
"1999y8m1d"
1998-8-1
info = "name:bobby dob:1987-10-1 ug:2005-9-1"
# 提取字符串
#print(re.findall("\d{4}", info))
# match方法是从字符串的最开始进行匹配
match_res = re.match(".*dob.*?(\d{4})", info)
#print(match_res.group(1))
# 替换字符串
... |
c7f21b8ae4ad7454fadf11d8d0bf2c8e5ceaf318 | Leahxuliu/Data-Structure-And-Algorithm | /Python/每周竞赛/1418. Display Table of Food Orders in a Restaurant.py | 819 | 3.578125 | 4 | class Solution:
def displayTable(self, orders: List[List[str]]) -> List[List[str]]:
info = {}
all_dish = set()
for each_order in orders:
table = each_order[1]
order = each_order[2]
all_dish.add(order)
if table in info:
info[tabl... |
263d53a7e4b5bf94b4f777e586cef3de4b64021f | Leahxuliu/Data-Structure-And-Algorithm | /Python/Graph/practice.py | 2,365 | 3.59375 | 4 | from collections import deque, defaultdict
class Graph:
def DFS_Traversal(self, nums, pairs):
def dfs(node):
if visited[node] == 1:
return
preorder.append(node)
visited[node] = 1
for out in adjacent[node]:
dfs(out... |
29758903b934a615cfcf41b586972479e76536c4 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Graph/133.Clone Graph.py | 3,994 | 3.890625 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/16
# @Author : XU Liu
# @FileName: 133.Clone Graph.py
'''
1. 题目要求:
2. 理解:
对无向图进行复制
graph看起来是一样的,nodes是new(deep copy)
3. 题目类型:
无向图
图的性质
4. 输出输入以及边界条件:
input: list,eg:adjList = [[2,4],[1,3],[2,4],[1,3]];1链接的2,4;2链接着1,3
output: list,同上
corner case: 只有一... |
af559c5d6de605811b0eb007b7c28202533f761c | Leahxuliu/Data-Structure-And-Algorithm | /Python/Heap/347.Top K Frequent Elements.py | 5,085 | 3.5 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/05
# @Author : XU Liu
# @FileName: 347.Top K Frequent Elements.py
'''
1. 题目要求:
找出现频率最多的k个数
time complexity must be better than O(n log n)
2. 理解:
3. 输出输入以及边界条件:
input:
output:
corner case:
4. 解题思路
5. 空间时间复杂度
'''
'''
dict + sort
字典排序时间复杂度O(n l... |
2baef912ee5f0d37d2b8c23150bf7f3321ecc3db | Leahxuliu/Data-Structure-And-Algorithm | /Python/巨硬/A28.二叉树的下一个节点.py | 1,073 | 3.703125 | 4 | '''
给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。
https://www.nowcoder.com/practice/9023a0c988684a53960365b889ceaf5e?tpId=13&tqId=11210&tPage=1&rp=1&ru=%2Fta%2Fcoding-interviews&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&tab=answerKey
'''
# 1.右边的最左节点;2.右上节点
# -*- coding:utf-8 -*-
# class... |
20ab694e8b2967e65c4982ba8492872f7f7a9a42 | Leahxuliu/Data-Structure-And-Algorithm | /Python/BinaryTree/1530. Number of Good Leaf Nodes Pairs.py | 984 | 3.703125 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def countPairs(self, root: TreeNode, distance: int) -> int:
if root == None:
return 0
... |
2e027c271f142affced4a4f873058702cea3487b | Leahxuliu/Data-Structure-And-Algorithm | /Python/Binary Search Tree/669.Trim a Binary Search Tree.py | 1,471 | 4.09375 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/30
# @Author : XU Liu
# @FileName: 669.Trim a Binary Search Tree.py
'''
1. 题目类型:
BST
2. 题目要求与理解:
Trim a Binary Search Tree(修剪树)
给定一个二叉搜索树,同时给定最小边界 L 和最大边界 R。通过修剪二叉搜索树,使得所有节点的值在 [L, R] 中 (R>=L)
3. 解题思路:
对比R, L, root之间的大小关系,类似二分法里找一定范围... |
eb5b6c989b13c535c77d7651f7812231cd6053e4 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Graph/最短路径/743. Network Delay Time.py | 2,085 | 3.5 | 4 | from heapq import *
from collections import defaultdict
class Solution:
def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:
# bulid the graph
graph = defaultdict(dict)
for i, j, w in times:
graph[i][j] = w
res = {}
heap = [(0, K)]
... |
d75019877651f2d9df6a674d0a92326485adaadc | Leahxuliu/Data-Structure-And-Algorithm | /Python/巨硬/C10.对应排序.py | 266 | 3.78125 | 4 | '''
给定一个按照字典序列的string字符串数组,每个字符串表示一个int,要求按照string对应的int大小重新排序
'''
# change into dict, sort
a = {'a':10, 'b':2, 'c': 5}
sorted_a = sorted(a.keys(), key = lambda x:a[x])
print(sorted_a) |
0d4a3da86f67411aa0b7fd32c5cfe0ac67e6336d | Leahxuliu/Data-Structure-And-Algorithm | /Python/Math/图形类/836. Rectangle Overlap.py | 750 | 3.921875 | 4 | class Solution:
def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
def check(A, B):
'''return true if overlap
Args:
A(list): [x1, x2] or [y1, y2] from rec1
B(list): [x1, x2] or [y1, y2] from rec2
Return:
... |
4a29901279a8008afc0776cd78ac8f2b6f512fc7 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Binary Search/374.Guess Number Higher or Lower.py | 1,070 | 4 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/27
# @Author : XU Liu
# @FileName: 374.Guess Number Higher or Lower.py
'''
1. 题目理解:
猜数字,范围是1-n
-1 : My number is lower --> 猜的数比计算机的数要大
1 : My number is higher
0 : Congrats! You got it!
2. 题目类型:
binary search
3. 输出输入以及边界条件:
inpu... |
efc9b6d05c4c80a1c4382a0c6d3339ed4761c9af | Leahxuliu/Data-Structure-And-Algorithm | /Python/DP/403. Frog Jump.py | 2,202 | 3.65625 | 4 |
'''
brout force
use backtacking to simulate jump
'''
class Solution:
def canCross(self, stones: List[int]) -> bool:
if len(stones) < 2:
return True
if stones[1] > 1:
return False
def find(start, steps):
'''simulation of jumpping
... |
e11ce7a7489623f1c1cc2845e4d1b478a852dc7f | Leahxuliu/Data-Structure-And-Algorithm | /Python/BinaryTree/257.Binary Tree Paths.py | 2,920 | 3.65625 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/04
# @Author : XU Liu
# @FileName: 257.Binary Tree Paths.py
'''
1. 题目要求:
2. 理解:
3. 题目类型:
4. 输出输入以及边界条件:
input:
output:
corner case:
5. 解题思路
'''
#DFS
class Solution:
def binaryTreePaths(self, root: TreeNode) -> List[str]:
... |
c8c72fef577fe5901ea9c6e740e39a22f0f544dd | Leahxuliu/Data-Structure-And-Algorithm | /Python/BinaryTree/366. Find Leaves of Binary Tree.py | 1,234 | 3.8125 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
from collections import defaultdict
class Solution:
def findLeaves(self, root: TreeNode) -> List[List[int]]:
if root... |
6bd47f050f406989bfa4f9978a9668324c4fb528 | Leahxuliu/Data-Structure-And-Algorithm | /Python/链表/61.Rotate List.py | 2,240 | 3.796875 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/05
# @Author : XU Liu
# @FileName: 61.Rotate List.py
'''
1. 题目要求:
最后一个node移动到第一个,重复k次
2. 理解:
3. 输出输入以及边界条件:
input:
output:
corner case:
4. 解题思路
5. 空间时间复杂度
'''
'''
two pointers (slow and fast pointer) 仅限于k的取值比链表长度小
1. make dummy, dum... |
9c0eb97bc9248d2bdf4966a535f429a25120b3ee | Leahxuliu/Data-Structure-And-Algorithm | /Python/巨硬/B5.石子游戏.py | 2,362 | 3.5625 | 4 | '''
877
'''
'''
1. 用相对分数,play1加分数,play减分数
2. 不是比较左右,取最大,而是比较取左之后,别人取了有的情况
brout force
backtracking to simulation stone game
'''
class Solution:
def stoneGame(self, piles: List[int]) -> bool:
def play_game(start, end):
'''
先取的人尽可能最大
'''
if (start, end) in memo... |
e0931fc421f3da8b6d4a314c15722c5900e4afed | Leahxuliu/Data-Structure-And-Algorithm | /Python/巨硬/A40.连续相同值子序列的最大长度.py | 730 | 3.75 | 4 | '''
给一个数组,可修改一个值,求由连续相同值组成的子序列的最大长度
'''
from collections import defaultdict
def count(arr):
if len(arr) < 3:
return len(arr)
n = len(arr)
left = 0
res = 1
count = 0
diff = 0
for right in range(1, n):
if arr[right] != arr[right - 1]:
count += 1
... |
b9d72fe04957416311354a56e53d9f464c9a35e7 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Binary Search Tree/700.Search in a Binary Search Tree.py | 1,643 | 3.8125 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/31
# @Author : XU Liu
# @FileName: 700.Search in a Binary Search Tree.py
'''
1. 题目类型:
BST
2. 题目要求与理解:
最最最普通的查找
3. 解题思路:
4. 输出输入以及边界条件:
input:
output:
corner case:
5. 空间时间复杂度
'''
class Solution:
def searchBST(self, root: TreeN... |
496b9a5e06279f1e16ba01b3d0ba01cffd79dd21 | Leahxuliu/Data-Structure-And-Algorithm | /Python/巨硬/A2打印缺失数字.py | 1,440 | 4.0625 | 4 | '''
一个sorted array,整数,要求输出缺失的数字。比如输入是[5,6,7,11,13],输出8, 9, 10, 12
'''
def find_miss_integer(arr):
'''
param: sorted array
return missing integers in a list
'''
if arr == []:
return []
minVal = arr[0]
maxVal = arr[-1]
if len(arr) == maxVal - minVal + 1:
return []
... |
4c462f2762e0f6fcd34dd1c9c3a8f0d61b49b030 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Graph/有向图/399. Evaluate Division-带权并查集.py | 1,386 | 3.578125 | 4 | '''
b / a = 3c / 6c = 0.5 把‘不同的变量’转换成‘相同变量’的倍数
一边查询一边修改
路径压缩
2.0 3.0
a --> b --> c
6.0 3.0
a --> c <-- b
'''
class Solution:
def calcEquation(self, equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[float]:
gT = {}
weight = {}
def add(i):
... |
2b7639d299e47c4772e9697bbec3c272b48b8a9c | Leahxuliu/Data-Structure-And-Algorithm | /Python/String/stack/844. Backspace String Compare.py | 953 | 3.84375 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/07/20
class Solution:
def backspaceCompare(self, S: str, T: str) -> bool:
new_S = []
new_T = []
for i in S:
if i == '#':
if new_S != []:
new_S.pop()
else:
... |
33a015aa5f9c1adae29963d96558d043b48ed632 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Math/504. Base 7.py | 367 | 3.546875 | 4 | class Solution:
def convertToBase7(self, num: int) -> str:
if num == 0:
return str(0)
res = ''
if num > 0:
flag = ''
else:
flag = '-'
num = abs(num)
while num != 0:
res = str(num % 7) + res
num = ... |
fa20d0eb6a96fed2a24c4d1b321681e39916d46b | Leahxuliu/Data-Structure-And-Algorithm | /Python/BinaryTree/103. Binary Tree Zigzag Level Order Traversal.py | 1,797 | 3.765625 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
'''
BFS 按层次遍历
'''
from collections import deque
class Solution:
def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]:
if root == None:
... |
44ab080409a0baddac6e71cc84accb4bf5592c7f | Leahxuliu/Data-Structure-And-Algorithm | /Python/BinaryTree/297. Serialize and Deserialize Binary Tree.py | 4,106 | 3.984375 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
# 前序遍历
class Codec:
def serialize(self, root):
"""Encodes a tree to a single string.
:type root: TreeNode
:rtyp... |
db75315d50fc2e6e3e330a48c0b53efc8f377c6b | Leahxuliu/Data-Structure-And-Algorithm | /Python/Binary Search/167.Two Sum II - Input array is sorted.py | 3,516 | 3.765625 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/24
# @Author : XU Liu
# @FileName: 167.Two Sum II - Input array is sorted.py
'''
1. 题目要求:
Given an array of integers that is already sorted in ascending order,
find two numbers such that they add up to a specific target number.
2. 理解:
给的array里面,两数相加=t... |
f586c7be734c4bb09de68c72975cbe50eab23109 | Leahxuliu/Data-Structure-And-Algorithm | /Python/sort/912. Sort an Array.py | 3,674 | 3.796875 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/07/02
# 递归
class Solution:
def sortArray(self, nums: List[int]) -> List[int]:
if len(nums) == 0:
return []
if len(nums) == 1:
return nums
mid = len(nums) // 2
L = nums[:mid]
R = nums... |
5c65765bca74c42c366893ddad3b783c54da6286 | Leahxuliu/Data-Structure-And-Algorithm | /Python/DP/数组中是否有相加等于S的数.py | 1,960 | 3.71875 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
'''
1. 题目类型:
DP
2. 题目要求:
给定一个正整数s, 判断一个数组arr中,是否有一组数字加起来等于s
都是正整数
'''
# 递归
arr = [3, 34, 4, 12, 5, 2]
def rec_subset(arr, i, s):
if i == 0:
return arr[0] == s
'''
if i == 0:
return arr[0] == s
错误
因为后面还有i-1
'''
if a... |
582c77dcaac7aabd9a5828795db5e035130a4c8e | Leahxuliu/Data-Structure-And-Algorithm | /Python/巨硬/C26.替换部分字符.py | 1,179 | 3.671875 | 4 | '''
写了一道题,大概意思就是给定一个字符串'aaabbbccc{{a}b{c}}'
然后可替换的部分'a: [d, e], c: [f], dbf: [x], ebf: [y]'
最后返回所有可能生成的字符串
'''
def change_string(s, data):
if s == "":
return ""
def change(s, start, path):
nonlocal res
if start == len(s):
res.add(''.join(path))
return
i... |
29ae5bf6cd55abbb4ed01967339cbf4d03795473 | Leahxuliu/Data-Structure-And-Algorithm | /Python/LeetCode2.0/Graph/261.Graph Valid Tree.py | 3,618 | 3.84375 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/05/09
'''
I. Clarify
a valid tree == no cirle and one island
II. Method
1. DFS / BFS
Steps:
1. the length edges != n - 1 --> False
beacuse the graph has circle or more than one island
2. build visited (0: not visi... |
6d334b9854eb84eec9346d5b4078b01efe6a07a7 | Leahxuliu/Data-Structure-And-Algorithm | /Python/DFS:Backtracking/典型回溯法/78.Subsets.py | 3,245 | 3.75 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/04/02
# @Author : XU Liu
# @FileName: 78.Subsets.py
'''
1. 题目类型:
2. 题目要求与理解:
找子集
无重复树
3. 解题思路:
4. 输出输入以及边界条件:
input:
output:
corner case:
5. 空间时间复杂度
'''
'''
回溯法
易错点:
注意nums里的值与index,不要混淆
'''
class Solution:
def subsets(self, nu... |
b4deae1a0ceaccc374d37c496da57e6674076f16 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Binary Search/367.Valid Perfect Square.py | 2,268 | 3.640625 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/27
# @Author : XU Liu
# @FileName: 367.Valid Perfect Square.py
'''
1. 题目理解:
判断给到的数字是不是可以被开平方
不能使用 sqrt function
16 --> 4 * 4 --> true
14 --> None --> False
2. 题目类型:
binary sort
target
3. 输出输入以及边界条件:
input: int
output: bool
co... |
9084f4690be5d54199a6728d3cf971e83363219c | Leahxuliu/Data-Structure-And-Algorithm | /Python/双指针问题/对撞对开指针/287. Find the Duplicate Number.py | 1,231 | 3.625 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/06/20
# hash
# time complexity: O(n)
# space complexity:O(n)
from collections import defaultdict
class Solution:
def findDuplicate(self, nums: List[int]) -> int:
info = defaultdict(int)
for i in nums:
info[i] += 1
... |
6b2f5874385ddc11c81875ba6e31091a0f44f643 | Leahxuliu/Data-Structure-And-Algorithm | /Python/双指针问题/分离双指针/349.Intersection of Two Arrays.py | 1,316 | 3.859375 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/04/29
# @Author : XU Liu
# @FileName: 349.Intersection of Two Arrays.py
'''
1. 题目要求:
给定两个数组,编写一个函数来计算它们的交集。
输出结果中的每个元素一定是唯一的。
我们可以不考虑输出结果的顺序。
输入: nums1 = [1,2,2,1], nums2 = [2,2]
输出: [2]
输入: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
输出: [9,4]
2. 理解:
找相同的值
3... |
47a5183567e67b82f98f8e608b0928b8cd0f2af3 | Leahxuliu/Data-Structure-And-Algorithm | /Python/链表/138.Copy List with Random Pointer.py | 1,347 | 3.578125 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/05/06
# @Author : XU Liu
# @FileName: 138.Copy List with Random Pointer.py
'''
1. 题目要求:
2. 理解:
3. 输出输入以及边界条件:
input:
output:
corner case:
4. 解题思路
5. 空间时间复杂度
'''
"""
# Definition for a Node.
class Node:
def __init__(self, x: int, next: 'N... |
a778142f0be70d546af43255da6c4c3ffe59a0d1 | Leahxuliu/Data-Structure-And-Algorithm | /Python/String/stack/946. 验证栈序列.py | 505 | 3.515625 | 4 | class Solution:
def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
if pushed == [] and popped == []:
return True
if pushed == [] or popped == []:
return False
stack = []
j = 0
for i in pushed:
stack.app... |
d9a550cc7729fcf87aeafc68858551272b19d6aa | Leahxuliu/Data-Structure-And-Algorithm | /Python/双指针问题/前向型指针-快慢/922. Sort Array By Parity II.py | 1,512 | 3.578125 | 4 | # 暴力
class Solution:
def sortArrayByParityII(self, A: List[int]) -> List[int]:
odd = []
even = []
for i in range(len(A)):
if i % 2 == 0 and A[i] % 2 != 0:
odd.append(i)
elif i % 2 != 0 and A[i] % 2 == 0:
even.append(i)
for i i... |
4f21735e9b85b9072567a6aa2df7d17ac121f39c | Leahxuliu/Data-Structure-And-Algorithm | /Python/Binary Search/33.Search in Rotated Sorted Array.py | 1,766 | 4.28125 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/26
# @Author : XU Liu
# @FileName: 33.Search in Rotated Sorted Array.py
'''
1. 题目理解:
找到目标值
给到的arr是部分sort,都是升序,旋转
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand
输出target的index(0-based)
如果... |
58083918e77b197ab6336783ea8e0d2dc06b8036 | Leahxuliu/Data-Structure-And-Algorithm | /Python/Graph/323.Number of Connected Components in an Undirected Graph.py | 3,093 | 3.75 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time : 2020/03/20
# @Author : XU Liu
# @FileName: 323.Number of Connected Components in an Undirected Graph.py
'''
1. 题目要求:
2. 理解:
无向图
判断有几个群
3. 题目类型:
无向图
判断孤立和分群
4. 输出输入以及边界条件:
input: n: int, edges: List[List[int]]
output: int
corner case: n == 0 --> 0
... |
902aea11bd59efe4945b43424f4916b69342f1ae | Leahxuliu/Data-Structure-And-Algorithm | /Python/coding/genres.py | 611 | 3.5625 | 4 | '''
corner case:
numU is 0 or not userB or numG == 0 or not bookG: return {}
Method:
corner case
transfer bookG to value:k
scan userB to create new dic
for name, create {type:number}
sort the {}
add to new dic
scan new dic, output the max number
'''
def favorite(numU, userB, numG, bookG):
if num... |
3da4457d043dda55a99aa4b64ebb7cc87d15acad | sahthi/backup2 | /backup_files/practice/str.py | 220 | 4.0625 | 4 | def remove(string,n):
first=[ :n]
last=[n+1: ]
return first+last
string=raw_input("enter the string name:")
n=int(input("enter the index to remove:")
print("modified string:")
print(remove(string,n))
|
5952daff834f8f713be39ef520f25d896034a006 | sahthi/backup2 | /backup_files/practice/sample/exp.py | 374 | 4.125 | 4 | import math
x=[10,-5,1.2,'apple']
for i in x:
try:
fact=math.factorial(i)
except TypeError:
print("factorial is not supported for given input:")
except ValueError:
print ("factorial only accepts positive integers")
else:
print ("factorial of a", x, "is",fact)
fin... |
46bc228f7805e43e22526ff7265dbf8cfd7aa030 | sahthi/backup2 | /files/2.py | 374 | 3.640625 | 4 | #!/usr/bin/python
import socket
def valid_ip(address):
try:
socket.inet_aton(address)
return True
except:
return False
if __name__=="__main__":
txt = raw_input("Text > ")
txt = txt.split()
ips = []
for word in txt:
if valid_ip(word):
ips.append(wor... |
f1ad2505648929b1898fb08b158ae21a8c5cd80e | sahthi/backup2 | /flask-application/rect.py | 287 | 3.953125 | 4 | class rectangle():
def __init__(self,length,breadth):
self.length=length
self.breadth=breadth
def area(self):
return self.breadth*self.length
a=input("enter len:")
b=input("enter breadth:")
obj=rectangle(a,b)
print("area of rect:",obj.area())
|
7ea33fbc516fccc8932ef09595bed811bd0500ec | sahthi/backup2 | /backup_files/practice/regw3.py | 158 | 3.890625 | 4 | import re
def match(string):
text=re.compile(r'^5')
if text.match(string):
return True
else:
return False
print match('5-236278')
|
b94971fd2e175be3814b33a69556ec6a49057acc | sahthi/backup2 | /backup_files/practice/thread.py | 242 | 3.65625 | 4 | import threading
def sum(x,y):
sum=x+y
return sum
def sub(x,y):
sub=x-y
return sub
x=input("enter number:")
y=input("enter number:")
t=threading.Thread(target=sum)
w=threading.Thread(target=sub)
t.start()
w.start()
|
966fff71c5c817d6a346f031d59692ff5cce0c00 | sahthi/backup2 | /backup_files/sanfoundry/dict.py | 155 | 4.125 | 4 | #!/usr/bin/python
d={'a':1,'b':2,'c':3}
key=raw_input("enter the key to check:")
if key in d.keys():
print (d[key])
else:
print key is not present
|
bc36e83cb948337ab012912032d943d6d3829669 | sahthi/backup2 | /backup_files/practice/aj.py | 230 | 3.578125 | 4 | print abs.__doc__
print int.__doc__
print raw_input.__doc__
def square(num):
'''return the square value of input number.
the input number must be an integer
'''
return num ** 2
print square(2)
print square.__doc__
|
8eabc5915442c74698de459405acdb8a6cb90fa6 | sahthi/backup2 | /backup_files/practice/rect.py | 352 | 4.0625 | 4 | #!/usr/bin/python
class rectangle:
def __init__(self,length,breadth):
self.length=length
self.breadth=breadth
def area(self):
return self.breadth*self.length
a=input("enter the length of rectangle:")
b=input("enter the breadth of rectangle:")
obj=rectangle(a,b)
print("area of rectan... |
0166da43f2e816f1792ad7ee16271f7023d3cf47 | sahthi/backup2 | /backup_files/practice/sample/lis.py | 243 | 4 | 4 | '''def my_list(li):
li.append(1)
x=[0]
my_list(x)
x'''
x=list(input("enter:"))
y=input("enter element to multiply:")
def multiply(x,y):
for i,e in enumerate(x):
x[i]=e*y
return x
print multiply(x,y)
|
465ce3bb60e8314ea7e91e9cc1971d0cbc977e4b | sahthi/backup2 | /Practise/threadpro.py/sample.py | 168 | 3.8125 | 4 | f = open("sample.txt", "rb")
s = f.readlines()
print s
f.close()
f = open("newtext.txt", "wb")
s.reverse()
print s
for item in s:
print>>f, item
f.close()
|
0ad1927eca95969c88b0f8aae5903e6ceb8c6d01 | sahthi/backup2 | /backup_files/practice/la.py | 112 | 3.59375 | 4 | l=input("enter the lower range:")
u=input("enter the upper range:")
a=[(x,x**2)for x in range(l,u+1)]
print(a)
|
4fc6069a201cf338719bfec341d351415ed7d244 | noway56/crawler_manage | /tests/test3.py | 472 | 3.671875 | 4 | def main():
my_list = [x for x in range(1, 11)]
print(my_list)
# my_sum = sum(my_list)
my_sum = get_sum(my_list)
print(f'连和为{my_sum}')
my_multi = get_multi(my_list)
print(f'连乘为{my_multi}')
pass
def get_sum(my_list):
total = 0
for i in my_list:
total += i
return tota... |
679fe79508d58c6dcc29f7b09ae6da800ab86c44 | villares/py.processing-play | /Arduino/firmata_arduino_basico/firmata_arduino_basico.pyde | 1,258 | 3.671875 | 4 | """
Código para a leitura dos potenciômetros, requer biblioteca Firmata (Arduino)
Você deve ajustar o valor de SERIAL para porta USB com seu Arduino
No Linux pode ser que precise fazer sudo chmod 666 /dev/ttyUSB0 (ou equivalente).
"""
# ARDUINO
add_library('serial') # import processing.serial.*;
add_library('arduino'... |
3d8315bb51269fc8293e7e9e10c718ac6dfb07ee | villares/py.processing-play | /lista_de_pontos/lista_de_arestas_v2/lista_de_arestas_v2.pyde | 5,633 | 3.65625 | 4 | """ Alexandre B A Villares - http://abav.lugaralgum.com
Brincando com uma lista de pontos, e agora arestas.
Para rodar, instale o Processing Modo Python.
Desenvolvido principalmente durante o Carnahacking 2017
no Garoa Hacker Clube - http://garoa.net.br
e publicado em https://github.com/villares/py.... |
bc1e5d9f3349799b82f84e610af176bbbba116a5 | Guie15/infNumeros | /treino.py | 925 | 3.828125 | 4 | from emoji import emojize
from math import sqrt
def linha():
print('-=-' * 14)
linha()
print('\033[34m Informações de Números!!\033[m')
print('-=-' * 14)
n=int(input(' Digite um número para sua tabuada: '))
limite_n = int(input(' Limite da Tabuada : '))
raiz= sqrt(n)
linha()
print(f' Sua raiz é {raiz}')
print(em... |
a4d4a66a22ad0d6bcc32995193620732a5991a0a | Rayd62/python3_practise | /2020_11/ex16_1.py | 543 | 3.609375 | 4 | #!/usr/bin/python
from sys import argv
script, filename = argv
print(f"We're going to erase {filename}.")
print("If you don't want to do that, press CTRL-C(^C).")
print("IF you want to do that, press RETURN.")
input("?")
print(f"opening {filename} ...")
fp = open(filename, 'w')
print(f"Erasing {filename}")
fp.tr... |
504bbae5852c55f00281cc2af5a3d0383313944a | patelyash9775/Python-Work | /Leapyear.py | 180 | 4.21875 | 4 | year=int(input("Enter a year : "))
if(year%400==0 or (year%100!=0 and year%4==0)):
print("Entered year is a leap year")
else:
print("Entered year is not a leap year")
|
451c5cd6f02d0500a2d40c7427876f4b9d7dbaee | patelyash9775/Python-Work | /Lower triangular matrix.py | 373 | 3.5 | 4 | n=int(input())
l=[]
for i in range(n):
row=list(map(int,input().split()))
l.append(row)
for i in range(n):
for j in range(n):
if(i<j):
l[i][j]=0
if(j==n-1):
print(l[i][j],end="")
else:
print(l[i][j],end=" ")
if(i==n-1):
... |
c980d7814d270c5f4ab39a023b3fd81d4313046e | JuneJoshua/Python-MITx- | /MITx I/Problem Set 1/vowels.py | 249 | 4.125 | 4 | vowels = 0
s = str(input("Enter a string: "))
for falchion in s:
if falchion == 'a' or falchion == 'e' or falchion == 'i' or falchion == 'o' or falchion == 'u':
vowels += 1
else:
vowels += 0
print("Number of vowels: " , vowels)
|
b3b0800b6add715999684c41393d1df9a636459d | All-I-Do-Is-Wynn/Python-Codes | /Codewars_Challenges/get_sum.py | 547 | 4.28125 | 4 | # Given two integers a and b, which can be positive or negative,
# find the sum of all the integers between and including them and return it.
# If the two numbers are equal return a or b.
# Note: a and b are not ordered!
def get_sum(a,b):
sum = 0
if a < b:
for x in range(a,b+1):
sum += x
... |
17f219735e8c34b60cba458f615647dba7b1cfba | rayvantsahni/after-MATH | /Euclidean Algorithm/gcd.py | 280 | 3.875 | 4 | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def main():
from functools import reduce
numbers = list(map(float, input("Enter the numbers space separated\n").split()))
print("\nGCD:", reduce(gcd, numbers))
main()
|
15fdbc037475927e58bf3b36a60c5cffc95264bc | rayvantsahni/after-MATH | /Rotate a Matrix/rotate_matrix.py | 1,523 | 4.40625 | 4 | def rotate(matrix, n, d):
while n:
matrix = rotate_90_clockwise(matrix) if d else rotate_90_counter_clockwise(matrix)
n -= 1
return matrix
def rotate_90_counter_clockwise(matrix):
"""
The function rotates any square matrix by 90° counter clock-wise.
"""
for row in matrix:
... |
55593ab0e18b4b617310e5b4d23bc46b306b15b8 | rayvantsahni/after-MATH | /Duck Numbers/duck_number.py | 211 | 3.984375 | 4 | def is_duck_number(s):
return "0" in str(int(s))
def main():
s = input("Enter number to check for Duck Number\n")
print("Is a Duck Number" if is_duck_number(s) else "Is NOT a Duck Number")
main()
|
9a651902f1820bcfa5b785894af03a48cbb081c5 | rayvantsahni/after-MATH | /Fast Exponentiation/fast_exponentiation.py | 442 | 4.03125 | 4 | def calculate_power(base, power):
if not power:
return 1
if not power % 2:
return calculate_power(base, power // 2) * calculate_power(base, power // 2)
else:
return calculate_power(base, power // 2) * calculate_power(base, power // 2) * base
if __name__ == "__main__":
a = int... |
aed25f8f014c605b35ff8c26ff4a20023a672e30 | bloodycoder/VirtualTkinter | /实例/简易计算器.py | 415 | 3.59375 | 4 | #vitual tkinter
from Tkinter import *
from ttk import *
root=Tk()
def calcu():
cal.set(eval(cal.get()))
NONE=StringVar()
Label(text= "calculator!",foreground="red").place(x=232,y=67)
cal=StringVar()
Entry(textvariable= cal,foreground="red",background="white").place(x=144,y=122)
Button(text= "click",command=ca... |
4b456009148aef6ebf47b94952a37eaefa42598a | LukumBest/VSA-VU-2018 | /proj01_ifelse/proj01.py | 12,560 | 4.3125 | 4 | # Name:
# Date:
# proj01: A Simple Program
# Part I:
# This program asks the user for his/her name and grade.
#Then, it prints out a sentence that says the number of years until they graduate.
# Part II:
# This program asks the user for his/her name and birth month.
# Then, it prints a sentence that says the number... |
9aeda27b9286de27061c8c425b75b5e15d24f6f4 | Harsh5606/PythonTraining | /Assignment 1/q2.py | 156 | 4.125 | 4 | # 2) Assign String to x variable in DD-MM-YYYY format extract and print Year from String.
x="19-08-2021"
print("Printing Only Year Frim String",x[6:]) |
1adada8a6b7d5332bed5c37d411571ca2ab1eae8 | ursawd/springboardexercises | /Unit18/Unit18-2/fs_4_reverse_vowels/reverse_vowels.py | 1,200 | 4.25 | 4 | def reverse_vowels(s):
"""Reverse vowels in a string.
Characters which re not vowels do not change position in string, but all
vowels (y is not a vowel), should reverse their order.
>>> reverse_vowels("Hello!")
'Holle!'
>>> reverse_vowels("Tomatoes")
'Temotaos'
>>> reverse_vowels("Re... |
1cfa1fc1cd7939f564382c105b359a8ce71a90f8 | harxingxing/pythonStudy | /history/day2/index.py | 945 | 3.78125 | 4 | # !/user/local/python3/bin
## 字符串格式化
print('我叫%s,今年%d岁了'%('小明', 20))
'''
知识点:
in:如果在指定的序列中找到值返回 True,否则返回 False,not in与之相反。a in b标识a在b里。p.Python成员运算符
is:判断两个标识符是不是引用自一个对象,in not与之相反。x is y, 类似 id(x) == id(y)。p.Python身份运算符
is 与 == 区别:is 用于判断两个变量引用对象是否为同一个, == 用于判断引用变量的值是否相等。p.Python身份运算符
在不同的机器上浮点运算的结果可能会不一样。在整数除法中,除法 ... |
1a725964b2cb0b3c01658c3f41c462a5caa346dc | CRomanIA/Python_Undemy | /Seccion_19_Libreria_Numpy/Secc19_cap71_Matrices_Transpuestas.py | 357 | 3.953125 | 4 | #Arrays o matrices transpuestas (cambiar ordenadamente las filas por las columnas)
import numpy as np
#se crea un array, arange(para dar rango de 0 a 14) reshape(fila,columna) para organizar
array = np.arange(15).reshape((3,5))
print(array)
print(array[1][1])
#TODO Transponer: cambiar las filas de las columnas
arra... |
3efbe784d9ead8c3e5307b1b26a7a1004a3386c1 | CRomanIA/Python_Undemy | /Seccion_19_Libreria_Numpy/Sec19_cap68_Arrays.py | 1,006 | 3.828125 | 4 | #Librerias Numpy
#TODO: Es importante esto, para instalar la libreria debes en terminal ingresar pip install numpy
import numpy as np
#arrays con condicion cero(donde toma 4 valores)
print(np.zeros(4))
#arrays con condicion uno(donde toma 4 valores)
print(np.ones(4))
#arrays con condicion de rango [igual a range] (... |
6aeb4f6cb0de29dbfd6fabc3a57b2e099b589963 | CRomanIA/Python_Undemy | /Seccion_9_Modulos-Librerias/sec9cap29.py | 248 | 3.71875 | 4 | #Pip : es un gestor de paquetes (Librerias) y modulos para python, un modulo es una libreria de python que puedes incluir en el proyecto
import camelcase
camel = camelcase.CamelCase()
texto = "el luigi Se la come doblada"
print (camel.hump(texto)) |
c93b30cbc764609d46114bfddc543283659c160d | CRomanIA/Python_Undemy | /Seccion_17_Pruebas_Automaticas/Sec17cap63.py | 714 | 3.734375 | 4 | #Doctest - Generar pruebas dentro de la documentacion
def sumar(numero1, numero2):
"""
Esto es la documentacion de este metodo
Recibe dos numeros como parametros y devuelve su suma
Se genera la prueba en los comentarios (No olvidar en el mayor que, darle un espacio)
(suma correcta)
>>> sumar(4,... |
e4feb584223c8092289627479e9244771c55cc5d | CRomanIA/Python_Undemy | /Seccion_22_Tratamiento_De_Datos/Secc22_cap88_Concatenacion_Dataframes.py | 998 | 3.8125 | 4 | #Concatenacion de Arrays, Series y Dataframes
import pandas as pd
import numpy as np
array1 = np.arange(9).reshape(3,3)
#print(array1)
print(np.concatenate([array1,array1]))
#Para concatenar hacia la derecha
print(np.concatenate([array1,array1],axis=1))
#Como concatenar una serie
serie1 = pd.Series([1,2,3], index=[... |
14f9f69ff6c9c63111a097411eccda0a64db058c | QiangChen-CG/mercurial | /src/math_objects/geometry.py | 9,491 | 3.640625 | 4 | import math
import random
import numpy as np
from math_objects import functions as ft
"""
Bunch of convenience classes which are not really used anymore. Except Point.
Perhaps the rest will come in handy at a later stage.
"""
class Coordinate(object):
"""
Class that models a coordinate in Carthesian space.... |
c0ee8e526f8165f410f7a0e92d9a335e406a15da | ShanmukhaSrinivas/python-75-hackathon | /log.py | 326 | 4 | 4 | #Logging the Exceptions, errors and warnings
import logging
logging.basicConfig(filename = 'log.txt', level = logging.WARNING)
try:
a = int(input('Enter a number:'))
b = int(input('Enter another number:'))
c = a/b
except Exception as e:
logging.exception(e)
else:
print('The result of division is... |
5768c55600fd738801f17853ff3b2405baa300fc | ShanmukhaSrinivas/python-75-hackathon | /private_variableIn_class.py | 473 | 3.765625 | 4 | #Class with a private variable
class Bank:
def __init__(self):
self.accno = 1001
self.name = 'Ganesh'
self.bal = 5000.0
self.__loan = 1500000.00
def display(self):
print('Acc.No= ', self.accno)
print('Name= ', self.name)
print('Balance= ', self.bal)
... |
12e6dc66ff42c823a1d4c4eb21a21a6a2b82f6fe | nathan-osman/django-archive | /django_archive/util/file.py | 969 | 3.609375 | 4 | """
Utility class for working with temporary files
"""
import os
from tempfile import mkstemp
class MixedModeTemporaryFile:
"""
Temporary file that can be opened multiple times in different modes
"""
def __init__(self):
self._fd, self._filename = mkstemp()
def __enter__(self):
... |
c6d2d5095d319fdfe43ad2dc712cd97cbe44cb9e | rohit-kuma/Python | /List_tuples_set.py | 1,822 | 4.1875 | 4 | courses = ["history", "maths", "hindi"]
print(courses)
print(len(courses))
print(courses[1])
print(courses[-1])
print(courses[0:2])
courses.append("art")
courses.insert(1, "Geo")
courses2 = ["Art", "Education"]
print(courses)
#courses.insert(0, courses2)
#print(courses)
courses2.extend(courses)
print(courses2)
print(co... |
4e2e110df413222d58718090475bc2700eafe9d7 | rohit-kuma/Python | /OOPS/normal_class_static_method.py | 1,315 | 3.828125 | 4 | class Employee:
num_emp = 0
raise_amount = 1.04
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + '.' + last + '@company.com'
Employee.num_emp += 1
def fullname(self): #regular method
# print(self... |
c53f6e0a2497c08ddda641471dc72ce572be4792 | bayusuarsa/PDF_to_Audibook_2 | /test.py | 968 | 3.734375 | 4 | import tkinter as tk
from tkinter import filedialog
from PIL import Image
watermark = Image.open("image/image_7.jpg")
def browse_for_image():
chosen_image = tk.filedialog.askopenfilename(title="Choose a file")
return chosen_image
def add_watermark():
file = browse_for_image()
image = Image.open(fil... |
598a1c47c454c6e31408824cdec50d9d4a262cef | mswinkels09/Critters_Croquettes_server | /animals/petting_animals.py | 2,463 | 4.3125 | 4 | # import the python datetime module to help us create a timestamp
from datetime import date
from .animals import Animal
from movements import Walking, Swimming
# Designate Llama as a child class by adding (Animal) after the class name
class Llama(Animal):
# Remove redundant properties from Llama's initialization,... |
4ac0211c37a552b429614b3f8165c139611c1447 | Roneetshr/C98 | /calculater.py | 229 | 3.84375 | 4 | def calculate(numb1,numb2):
numbers = input("This sum will be multiplyed: ")
ans = 0
for line in numbers:
ans = ans + numb1*numb2
print("The answer is")
print(ans)
calculate(13,24)
|
c27892b565bb1731b02f2fa7f6258419bad34edd | Uma-Ravi22/Bertelsmann-Technology-Scholarship-Python-Challenges | /Day42_RedactText.py | 1,421 | 4.6875 | 5 |
# Day 42 Challenge: Redacting Text in a File
# Sensitive information is often removed, or redacted, from documents before they are released to the public.
# When the documents are released it is common for the redacted text to be replaced with black bars. In this exercise
# you will write a program that redacts all ... |
dc24942f5115667462dd5c11064d903c92d38825 | Uma-Ravi22/Bertelsmann-Technology-Scholarship-Python-Challenges | /Day67_LastlineFile.py | 553 | 4.46875 | 4 | # Day 67 Challenge: Print last Line of a File.
# Function iterates over lines of file, store each line in lastline.
# When EOF, the last line of file content is stored in lastline variable.
# Print the result.
def get_final_line(fname):
fhand = open(fname, "r")
for line in fhand:
fhand = line.rstrip()... |
ec508478bbd76531f1ef8e2a7a849254092cb3e4 | Uma-Ravi22/Bertelsmann-Technology-Scholarship-Python-Challenges | /Day45_RecurStr.py | 689 | 4.28125 | 4 | # Day 45: Recursive (String) Palindrome
def Palindrome(s):
# If string length < 1, return TRUE.
if len(s) < 1:
return True
else:
# Last letter is compared with first, function called recursively with argument as
# Sliced string (With first & last character removed.)
if s[0... |
7b47ad842688389a9f2cb3a15a316d8f632fcdd8 | AlexDvorak/Python-Coding-Train-Intelligence-and-Learning | /week1-graphs/01_binary_tree/tree.py | 438 | 3.96875 | 4 | from node import *
# Tree object
class Tree(object):
def __init__(self):
# Just store the root
self.root = None
# Start by searching the root
def traverse(self):
self.root.visit()
# Start by searching the root
def search(self,val):
found = self.root.search(val)
return found
# Add a new value to the ... |
bf23966c63dcaf59b048df443f59a16e315e0419 | mazimidev/daen500 | /CalcOTPay.py | 515 | 4 | 4 | hours = input('Enter Hours: ')
rate = input('Enter Rate: ')
try:
otHours = float(hours)%40
otRate = float(rate)*1.5
print (otHours)
print (otRate)
except:
print('please enter numeric')
else:
if float(hours) > 40:
regPay=40 * float(rate)
print(regPay)
otPay=otHours * otRa... |
f4b342b436780dd1688b5f9163dd2e9248d7ec21 | soldiers1989/tradecap | /tradeday.py | 435 | 3.515625 | 4 | #!/usr/bin/python2
# coding:utf8
def is_trade_day(date):
# date 日期,日期格式 20160101
# 是交易日 返回1 否则返回0
trade_days = []
with open('trddate.txt') as f:
for i in f:
if i not in trade_days:
trade_days.append(i.strip())
if date in trade_days:
return 1
else:
... |
9c5b596221ade0a208c0d8d274e7dbc84d0a6709 | FB-18-19-PreAP-CS/math-helper-wcarllWRLD | /math_helper_Carll_W.py | 5,577 | 4.25 | 4 | import math
def main():
print("Welcome to the math helper!")
while True:
try:
print("")
print("Type [quit] to quit.")
select = input("[1] Compound Interest \n[2] Volume of a Sphere \n[3] Distance Formula \n[4] Midpoint \n[5] Area of a Semi-Circle \nPlease select your... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.