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 |
|---|---|---|---|---|---|---|
4afad10bff966b08e4f0aab782049901a3fb66dc | BalintNagy/GitForPython | /Checkio/01_Elementary/checkio_elementary_11_Even_the_last.py | 1,261 | 4.21875 | 4 | """\
Even the last
You are given an array of integers. You should find the sum of the elements
with even indexes (0th, 2nd, 4th...) then multiply this summed number and
the final element of the array together. Don't forget that the first element
has an index of 0.
For an empty array, the r... |
92067b660f1df00f7d622b49388994c892145033 | BalintNagy/GitForPython | /OOP_basics_1/01_Circle.py | 572 | 4.125 | 4 | # Green Fox OOP Basics 1 - 1. feladat
# Create a `Circle` class that takes it's radius as cinstructor parameter
# It should have a `get_circumference` method that returns it's circumference
# It should have a `get_area` method that returns it's area
import math
class Circle:
def __init__(self, radius):
... |
301046cea95790013af1c2bf157aeb0b35423256 | BalintNagy/GitForPython | /Checkio/01_Elementary/checkio_elementary_01_Say_hi.py | 802 | 4.03125 | 4 | """\
1. Say hi
In this mission you should write a function that introduce a person with a given parameters in attributes.
Input: Two arguments. String and positive integer.
Output: String.
Example:
say_hi("Alex", 32) == "Hi. My name is Alex and I'm 32 years old"
... |
3b33c74b4f0f669da47500eeda6d9f734fb07371 | BalintNagy/GitForPython | /FileIO/crypto_4encoded.py | 820 | 3.75 | 4 | # Create a method that decrypts texts/encoded_zen_lines.txt
# Write the file's content into a new file with a name of
# "decryt4_[the current timestamp]" where the timestamp format shoud be 'hhmmss'
def crypto_4encoded(file_name):
import datetime, string
f = open(file_name, 'r')
f2 = open('texts/decrypt4_'... |
7852ff2dfef25e356a65c527e94ee88d10c74a0b | BalintNagy/GitForPython | /Checkio/01_Elementary/checkio_elementary_16_Digits_multiplication.py | 929 | 4.40625 | 4 | """\
Digits Multiplication
You are given a positive integer. Your function should calculate the product
of the digits excluding any zeroes.
For example: The number given is 123405. The result will be 1*2*3*4*5=120
(don't forget to exclude zeroes).
Input: A positive integer.
Output: The p... |
285b869b5b961c2722caf04449494a2e618c3a94 | r21gh/knapsack-problem | /knapsack.py | 584 | 3.828125 | 4 | # Reza Ghanbari
# Advanced algorithm course
# Knapsack problem using dynamic programming
# Compatibiltiy with python 2 and 3
def knapSack(W, wt, val, n):
K = [[0 for x in range(W+1)] for x in range(n+1)]
for i in range(n+1):
for w in range(W+1):
if i==0 or w==0:
K[i][w] = ... |
3546d609dc4bf6c769a437d8879c2c2d66fd3873 | marcelofilhogit/URI | /1007.py | 209 | 3.578125 | 4 | def diferenca():
num1 = int(input())
num2 = int(input())
num3 = int(input())
num4 = int(input())
diferenca = (num1 * num2) - (num3 * num4)
print("DIFERENCA =",diferenca)
diferenca()
|
2b43c7e421a09ffa58dc89db962958161e9fe679 | brianmego/project_euler | /python/4.py | 550 | 4 | 4 | #!/usr/bin/env python
LARGEST = 999
SMALLEST = 100
def is_palindrome(i):
return str(i) == str(i)[::-1]
def has_three_digit_factors(i):
for j in range(LARGEST, SMALLEST - 1, -1):
if i % j == 0:
quotient = i / j
if SMALLEST <= quotient <= LARGEST:
return True
... |
ae11fe032a6e96a1914af1e66b753bd3e7721be1 | ferseg/ia-1-2015 | /src/regex/DataFile.py | 611 | 3.75 | 4 | import re
def open_file():
file = open("input.txt","r");
return file;
def read_file(file):
data_file = file.read();
return data_file;
#get all matches of the re in data
def get_babylon_tower(data):
babylon_tower = re.findall(r"\b(F[1-4])(=)([POGYH],[POGYH],[POGYH],[POGYH])((,)([POGY... |
805d278e385be0aec5a6160f0e5127bd0b5cb224 | untbr/game_programming | /materials/state.py | 4,464 | 3.828125 | 4 | """
主要な状態における処理をまとめたモジュール
インスタンス作成後、順次メソッドを呼び出すことにより処理を行っていく
"""
import itertools
import sys
import typing
from enum import Enum
from typing import NamedTuple
import pygame
from pygame.locals import * # 定数読み込み
class States(Enum):
"""状態の定義"""
TITLE = 0 # タイトル画面
USER = 1 # ユーザー名入力... |
8b2be7d66fae92613138f2071fee3164b88812ff | Dimitrov-M/landTree | /landTree.py | 4,498 | 3.515625 | 4 | #!/usr/bin/python
import argparse
class Node():
def __init__(self, id, name, parent_id=None, parent=None, is_root=False):
self.id = id
self.name = name
self.parent_id = parent_id
self.parent = parent
self.children = []
self.land = []
self.is_root = is_root
... |
12f12b5e598d78e83c01f3c59aae0e131df6a59a | MegaYEye/Cambridge_Coursework | /NLP/Analysis.py | 2,261 | 3.578125 | 4 | import math,sys
class Evaluation():
"""
general evaluation class implemented by classifiers
"""
def crossValidate(self,corpus,i):
"""
function to perform 10-fold cross-validation for a classifier.
each classifier will be inheriting from the evaluation class so you will have a... |
c62db966daf446d63bd9d19206c0719295b3f714 | mura-wx/mura-wx | /python/latihan pyhton/membuatfile.py | 1,604 | 3.828125 | 4 | # # cara membuat file pada python
# # untuk mencegah error kita biasakan menggunakan try except
# # membuat dan mengisi file
# try :
# sebuah_file = open("absen.txt", 'w')
# print ("nama file yang telah di buat".ljust(30),":", sebuah_file.name)
# print("mode pembacaan".ljust(30),":", sebuah_file.m... |
65879b26b356882b641c2c48a9a77c5244bc3d60 | mura-wx/mura-wx | /python/latihan pyhton/mengambil input user.py | 290 | 3.84375 | 4 | # cara mengambil imput user
# data yang di masukan akan bertipe str
data = input("masukan data:")
print (data, ",type", type(data))
# data yang di masukan akan bertipe int jika di masukan nilai int
data_int = int(input("masukan data:"))
print (data_int, ",type", type(data_int))
|
d5353aa98262d9de8b540c9ae863bde41ab0cda9 | mura-wx/mura-wx | /python/Practice Program/basic program/chekPositifAndNegatif.py | 306 | 4.15625 | 4 | try :
number=int(input("Enter Number : "))
if number < 0:
print("The entered number is negatif")
elif number > 0:
print("The entered number is positif")
if number == 0:
print("number is Zero")
except ValueError :
print('The input is not a number !') |
514087b467c86fedd4a91f571f641bb627cca40e | mura-wx/mura-wx | /python/Practice Program/basic program/PythonPrograToAddTwoNumbers.py | 78 | 3.578125 | 4 | x = 15
y = 10
sum = x + y
print("sum {0} and {1} is {2}".format(x,y,sum)) |
19c053e08eda876c8a587fd372a87ba470767646 | Mariamapa/EDAI | /Examen/semaforo.py | 1,395 | 3.546875 | 4 | #Medidor de covid
#Limpiar pantalla
import os
os.system("cls")
#Libreria que nos servira para leer datos desde una base de datos
import pandas as pd
import numpy as np
#Limpiamos pantalla
#Modulo que permite imprimir el texto en colores
from colorama import Fore, Back, Style, init
init()
print("\n\t\... |
eb2522f1e9b0a999086d2adc360d408db588d6b0 | dgallab/exercises_in_python | /python-based interpreter/error.py | 541 | 3.515625 | 4 | #Daniel Gallab
#CPSC 326-02
#Assignment 2
#when an error is found in the lexer,
#this class is called, and a message
#describing the error is printed
class Error(Exception):
def __init__ (self, message, line, column): #message should specify error
self.message = message
self.line = lin... |
b45e6f6b1e8bb428e0e3fd5b6985687e64812a1c | Alihussain-khan/HangMan-Game-Python | /hangman game.py | 2,638 | 4.1875 | 4 | import random
def get_word():
words= [ 'Woodstock',
'Gray',
'Hello',
'Gopher',
'Spikepike',
'green',
'blue',
'Willy',
'Rex',
'yes',
'Roo',
'Littlefoot',
'Baagheera',
'Remy',
... |
22f7069e46536953bbb80f19c882623c4bb6540c | mnahuelanca/pythonBasico | /tablaMultiplicar10.py | 1,449 | 3.96875 | 4 |
menu = """
Bienvenido, seleccione la tabla de multiplicar que necesita ✔
2
3
4
5
6
7
8
9
10
"""
opcion = input(menu)
if opcion =="2":
for i2 in range(1, 11):
resultado2 = 2*i2
print("2 x " + str(i2) + " es igual a: " + str(resultado2))
elif opcion =="3":
for i3 in range(1, 11):
resul... |
75dee3e2c6cc5d618a01fec6769cca8ddb497758 | sobostion/sudoku-solver | /hard.py | 7,238 | 3.609375 | 4 | #!/usr/bin/python
# sudoku solver
from prettytable import *
# initialise sudoku puzzle
rows = {}
rows[0] = [9, 1, None, 3, None, None, None, None, 2]
rows[1] = [None, None, None, 8, None, None, 4, None, None]
rows[2] = [None, None, 4, None, 7, None, None, None, None]
rows[3] = [None, None, 6, None, None, 3, None, None... |
cc14ca5628cd444a90a9a42ef75bd7a8e7f90e82 | enric-blackbird/hangman | /hangman.py | 2,174 | 4.09375 | 4 | from random import choice
import words
def get_unique_letters(word):
unique_letters = set()
for letter in word:
unique_letters.add(letter)
return unique_letters
def ask_dificulty_level():
selected_difficulty = ''
while (selected_difficulty in words.difficulty_levels) == False:
sele... |
25060ecf890a624e8e1796f4951a97a94eb47196 | zuxinlin/leetcode | /leetcode/editor/cn/[543]二叉树的直径-diameter-of-binary-tree.py | 1,549 | 3.984375 | 4 | #!/bin/env python
# coding: utf-8
# 给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。
#
#
#
# 示例 :
# 给定二叉树
#
# 1
# / \
# 2 3
# / \
# 4 5
#
#
# 返回 3, 它的长度是路径 [4,2,1,3] 或者 [5,2,1,3]。
#
#
#
# 注意:两结点之间的路径长度是以它们之间边的数目表示。
# Related To... |
8741f275c7cfbcb9f0dadcceda1fdc91926e3733 | zuxinlin/leetcode | /leetcode/697.DegreeofanArray.py | 845 | 3.71875 | 4 | #! /usr/bin/env python
# coding: utf-8
import collections
'''
题目:
主题:
解题思路:
'''
class Solution(object):
'''
'''
def findShortestSubArray(self, nums):
'''
:type nums: List[int]
:rtype: int
'''
firstDict, lastDict = {}, {}
for index, element in enumerat... |
9289b58e5d5a049b05736f21fe29c74fd5f62d2c | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 32 - I]从上到下打印二叉树-cong-shang-dao-xia-da-yin-er-cha-shu-lcof.py | 1,208 | 3.796875 | 4 | #! /usr/bin/env python
# coding: utf-8
# 从上到下打印出二叉树的每个节点,同一层的节点按照从左到右的顺序打印。
#
#
#
# 例如:
# 给定二叉树: [3,9,20,null,null,15,7],
#
# 3
# / \
# 9 20
# / \
# 15 7
#
#
# 返回:
#
# [3,9,20,15,7]
#
#
#
#
# 提示:
#
#
# 节点总数 <= 1000
#
# Related Topics 树 广度优先搜索
# 👍 82 👎 0
# leet... |
f04f02ec17452f7dab054f977cfa93ef3e4dcd44 | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 68 - I]二叉搜索树的最近公共祖先-er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof.py | 2,089 | 3.546875 | 4 | #! /usr/bin/env python
# coding: utf-8
# 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。
#
# 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(
# 一个节点也可以是它自己的祖先)。”
#
# 例如,给定如下二叉搜索树: root = [6,2,8,0,4,7,9,null,null,3,5]
#
#
#
#
#
# 示例 1:
#
# 输入: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q... |
2d0dd49df325cedf34a9f57348c14e5fe1f5ec6f | zuxinlin/leetcode | /leetcode/669.TrimaBinarySearchTree.py | 1,598 | 3.90625 | 4 | #! /usr/env python
# coding: utf-8
'''
二叉搜索数,移除所有节点值小于l或者大于r的节点
'''
class TreeNode(object):
'''
树节点类
'''
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution(object):
def trimBST(self, root, L, R):
'''
:type root: TreeNod... |
96fdb3f37819683bdc6483b8d2d4d790ca65ef40 | zuxinlin/leetcode | /leetcode/editor/cn/[面试题 02.01]移除重复节点-remove-duplicate-node-lcci.py | 1,403 | 3.8125 | 4 | #! /usr/bin/env python
# coding: utf-8
# 编写代码,移除未排序链表中的重复节点。保留最开始出现的节点。
#
# 示例1:
#
#
# 输入:[1, 2, 3, 3, 2, 1]
# 输出:[1, 2, 3]
#
#
# 示例2:
#
#
# 输入:[1, 1, 1, 1, 2]
# 输出:[1, 2]
#
#
# 提示:
#
#
# 链表长度在[0, 20000]范围内。
# 链表元素在[0, 20000]范围内。
#
#
# 进阶:
#
# 如果不得使用临时缓冲区,该怎么解决?
# Related Topics... |
428a526f19452e625231d84df58b073afdf67f2c | zuxinlin/leetcode | /leetcode/editor/cn/[1143]最长公共子序列-longest-common-subsequence.py | 2,256 | 3.703125 | 4 | #! /usr/bin/env python
# coding: utf-8
# 给定两个字符串 text1 和 text2,返回这两个字符串的最长 公共子序列 的长度。如果不存在 公共子序列 ,返回 0 。
#
# 一个字符串的 子序列 是指这样一个新的字符串:它是由原字符串在不改变字符的相对顺序的情况下删除某些字符(也可以不删除任何字符)后组成的新字符串。
#
#
# 例如,"ace" 是 "abcde" 的子序列,但 "aec" 不是 "abcde" 的子序列。
#
#
# 两个字符串的 公共子序列 是这两个字符串所共同拥有的子序列。
#
#
#
# 示例 1:
#
#
# 输入... |
8a7fba97f2e5895d65f3181d82455883cbe5eeee | zuxinlin/leetcode | /leetcode/204.CountPrimes.py | 741 | 3.828125 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
题目: 统计素数 https://leetcode-cn.com/problems/count-primes/
主题: hash table & math
解题思路:
1. 利用数组缓存是否素数
'''
class Solution(object):
def countPrimes(self, n):
"""
:type n: int
:rtype: int
"""
no_prime = [False] * n
count = 0
... |
65dbb54f88d96fab2bf6953724336d932e81db30 | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 30]包含min函数的栈-bao-han-minhan-shu-de-zhan-lcof.py | 1,676 | 4.03125 | 4 | #! /usr/bin/env python
# coding: utf-8
# 定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的 min 函数在该栈中,调用 min、push 及 pop 的时间复杂度都是 O(1)。
#
#
#
# 示例:
#
# MinStack minStack = new MinStack();
# minStack.push(-2);
# minStack.push(0);
# minStack.push(-3);
# minStack.min(); --> 返回 -3.
# minStack.pop();
# minStack.top(); --> 返回 0... |
dacb6006963fb1c724b4ad5116424a33cb90a7ce | zuxinlin/leetcode | /leetcode/editor/cn/[面试题 02.05]链表求和-sum-lists-lcci.py | 1,638 | 3.84375 | 4 | #! /usr/bin/env python
# coding: utf-8
# 给定两个用链表表示的整数,每个节点包含一个数位。
#
# 这些数位是反向存放的,也就是个位排在链表首部。
#
# 编写函数对这两个整数求和,并用链表形式返回结果。
#
#
#
# 示例:
#
# 输入:(7 -> 1 -> 6) + (5 -> 9 -> 2),即617 + 295
# 输出:2 -> 1 -> 9,即912
#
#
# 进阶:思考一下,假设这些数位是正向存放的,又该如何解决呢?
#
# 示例:
#
# 输入:(6 -> 1 -> 7) + (2 -> 9 -> 5),即617 + 2... |
daa3502ee43661ba21929fe62a20aa19e8ae5c77 | zuxinlin/leetcode | /leetcode/303.RangeSumQuery-Immutable.py | 1,081 | 4.0625 | 4 | #! /usr/bin/env python
# coding: utf-8
"""
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Example:
Given nums = [-2, 0, 3, -5, 2, -1]
sumRange(0, 2) -> 1
sumRange(2, 5) -> -1
sumRange(0, 5) -> -3
Note:
You may assume that the array does not change.
There are man... |
e1fba9ce8a9ce41bc5864cea8930bc5ad1048ea1 | zuxinlin/leetcode | /leetcode/94.BinaryTreeInorderTraversal.py | 1,332 | 3.96875 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
题目: 二叉树中序遍历 https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
主题: hash table & stack & tree
解题思路:
1. 深度优先遍历,左 根 右
'''
# Definition for a binary tree node.
class TreeNode(object):
def __init__(self, x):
self.val = x
self.left = None
... |
ed87906929d09c5cfa80fb0f94ad3470b06eafd4 | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 49]丑数-chou-shu-lcof.py | 1,657 | 3.8125 | 4 | #! /usr/bin/env python
# coding: utf-8
# 我们把只包含质因子 2、3 和 5 的数称作丑数(Ugly Number)。求按从小到大的顺序的第 n 个丑数。
#
#
#
# 示例:
#
# 输入: n = 10
# 输出: 12
# 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。
#
# 说明:
#
#
# 1 是丑数。
# n 不超过1690。
#
#
# 注意:本题与主站 264 题相同:https://leetcode-cn.com/problems/ugly-number-ii/
# Rel... |
5330a27b9dc92edc83b382e554775bdcdd4f98b8 | zuxinlin/leetcode | /leetcode/editor/cn/[202]快乐数-happy-number.py | 1,116 | 3.5625 | 4 | #! /usr/bin/env python
# coding: utf-8
# 编写一个算法来判断一个数 n 是不是快乐数。
#
# 「快乐数」定义为:
#
#
# 对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和。
# 然后重复这个过程直到这个数变为 1,也可能是 无限循环 但始终变不到 1。
# 如果 可以变为 1,那么这个数就是快乐数。
#
#
# 如果 n 是快乐数就返回 true ;不是,则返回 false 。
#
#
#
# 示例 1:
#
#
# 输入:19
# 输出:true
# 解释:
# 12 + 92 = 82
# 82 + 22 = 68
... |
343df813e7d0b24a99281b4a3bbb5c77baabf2ae | zuxinlin/leetcode | /leetcode/169.MajorityElement.py | 847 | 3.75 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
题目: 主要元素 https://leetcode-cn.com/problems/majority-element/
主题: array & divide and conquer & bit manipulation
解题思路:
1. 排序
'''
class Solution(object):
def majorityElement(self, nums):
'''
:type nums: List[int]
:rtype: int
'''
# re... |
f1cd2a2c2f65e75ed8e51bb80695654d0318922c | zuxinlin/leetcode | /leetcode/editor/cn/[88]合并两个有序数组-merge-sorted-array.py | 2,402 | 4.09375 | 4 | #! /usr/bin/env python
# coding: utf-8
# 给你两个有序整数数组 nums1 和 nums2,请你将 nums2 合并到 nums1 中,使 nums1 成为一个有序数组。
#
# 初始化 nums1 和 nums2 的元素数量分别为 m 和 n 。你可以假设 nums1 的空间大小等于 m + n,这样它就有足够的空间保存来自 nu
# ms2 的元素。
#
#
#
# 示例 1:
#
#
# 输入:nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
# 输出:[1,2,2,3,5,6]
#
#
# 示例... |
76b5171706f347c58c33eed212798f84c6ebcfd1 | zuxinlin/leetcode | /leetcode/350.IntersectionOfTwoArraysII.py | 1,434 | 4.1875 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
'''
class Solution(object):
'''
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].
Note:
Each element in the result should appear as many times as it shows in both a... |
438d018c965882d506f8779738bec7d716e76ed8 | zuxinlin/leetcode | /leetcode/editor/cn/[125]验证回文字符串-valid-palindrome.py | 1,127 | 3.734375 | 4 | #! /usr/bin/env python
# coding: utf-8
# 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
#
# 说明:本题中,我们将空字符串定义为有效的回文串。
#
# 示例 1:
#
# 输入: "A man, a plan, a canal: Panama"
# 输出: true
#
#
# 示例 2:
#
# 输入: "race a car"
# 输出: false
#
# Related Topics 双指针 字符串
# 👍 372 👎 0
# leetcode submit region begin(Prohib... |
28ef9964b87c016a7c38fc035839c9441a2eecd4 | zuxinlin/leetcode | /leetcode/editor/cn/[415]字符串相加-add-strings.py | 1,215 | 3.71875 | 4 | #!/bin/env python
# coding: utf-8
# 给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和。
#
#
#
# 提示:
#
#
# num1 和num2 的长度都小于 5100
# num1 和num2 都只包含数字 0-9
# num1 和num2 都不包含任何前导零
# 你不能使用任何內建 BigInteger 库, 也不能直接将输入的字符串转换为整数形式
#
# Related Topics 字符串
# 👍 360 👎 0
# leetcode submit region begin(Prohibit modification... |
18fa265d0986d4525e31166b13c334d55b3dd85c | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 32 - II]从上到下打印二叉树 II-cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.py | 1,565 | 3.921875 | 4 | #! /usr/bin/env python
# coding: utf-8
# 从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行。
#
#
#
# 例如:
# 给定二叉树: [3,9,20,null,null,15,7],
#
# 3
# / \
# 9 20
# / \
# 15 7
#
#
# 返回其层次遍历结果:
#
# [
# [3],
# [9,20],
# [15,7]
# ]
#
#
#
#
# 提示:
#
#
# 节点总数 <= 1000
#
#
# 注意:本题与主站 ... |
e3d7fd79863b8438f5aaef3fcbda61641c80ca37 | zuxinlin/leetcode | /leetcode/268.MissingNumber.py | 939 | 4.09375 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
Example 1:
Input: [3,0,1]
Output: 2
Example 2:
Input: [9,6,4,2,3,5,7,0,1]
Output: 8
连续整数数组,其中丢失一个数字,求丢失的数字
1. 求和
2. 异或
'''
class Solution(object):
... |
25d0f4a1de46904cc9db08dae89edd2d07f417ec | zuxinlin/leetcode | /leetcode/516.LongestPalindromicSubsequence.py | 1,483 | 4 | 4 | #! /usr/bin/env python
# coding: utf-8
"""
Longest Palindromic Subsequence
"""
class Solution(object):
"""
Given a string s, find the longest palindromic subsequence's length in s.
You may assume that the maximum length of s is 1000.
Example 1:
Input: "bbbab"
Output: 4
One possible longes... |
071594b3527b32d58737a50a969ed3e691a43c91 | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 10- II]青蛙跳台阶问题-qing-wa-tiao-tai-jie-wen-ti-lcof.py | 1,009 | 3.65625 | 4 | #! /usr/bin/env python
# coding: utf-8
# 一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。
#
# 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。
#
# 示例 1:
#
# 输入:n = 2
# 输出:2
#
#
# 示例 2:
#
# 输入:n = 7
# 输出:21
#
#
# 示例 3:
#
# 输入:n = 0
# 输出:1
#
# 提示:
#
#
# 0 <= n <= 100
#
#
# 注意:本题与主... |
2cb4b271197773e4b76e68c5fb60045e0648d9d6 | zuxinlin/leetcode | /amcat/CellCompete.py | 645 | 3.515625 | 4 | #! /usr/bin/env python
# coding: utf-8
import collections
def cellCompete(states, days):
# WRITE YOUR CODE HERE
n = len(states)
temp = [state for state in states]
while days > 0:
days -= 1
temp[0] = 0 ^ states[1]
temp[n - 1] = 0 ^ states[n - 2]
for i in range(1, n - ... |
dd6cb3ae7e51e31504e81eb9b01b2d58be5f8e08 | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 63]股票的最大利润-gu-piao-de-zui-da-li-run-lcof.py | 1,517 | 3.703125 | 4 | #! /usr/bin/env python
# coding: utf-8
# 假设把某股票的价格按照时间先后顺序存储在数组中,请问买卖该股票一次可能获得的最大利润是多少?
#
#
#
# 示例 1:
#
# 输入: [7,1,5,3,6,4]
# 输出: 5
# 解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。
# 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格。
#
#
# 示例 2:
#
# 输入: [7,6,4,3,1]
# 输出: 0
# 解释: 在这种情况下, 没有交易完成, 所以... |
3a1b76483d65f82c140c227ee11c7037ca44a361 | zuxinlin/leetcode | /leetcode/17.LetterCombinationsOfAPhoneNumber.py | 1,190 | 3.734375 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
题目: 电话号码字母组合
主题: string & backtracking
解题思路:
方法1:递归,dfs
方法2:回溯
'''
class Solution(object):
def letterCombinations(self, digits):
"""
:type digits: str
:rtype: List[str]
"""
key_map = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl... |
319d3ec8c62018aefd7e9fa2afae5a84ca4e27d0 | zuxinlin/leetcode | /leetcode/997.FindTheTownJudge.py | 1,286 | 3.8125 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
题目: 找出小镇法官
主题: graph
解题思路:
1. 两个字典存储
'''
class Solution(object):
'''
'''
def findJudge(self, N, trust):
"""
:type N: int
:type trust: List[List[int]]
:rtype: int
"""
# 边界
if N == 1 and trust == []:
... |
c37d715af7df27127e2c79e04331704190be7502 | zuxinlin/leetcode | /leetcode/88.MergeSortedArray.py | 1,105 | 3.953125 | 4 | #! /usr/bin/env python
# coding: utf-8
from itertools import combinations
'''
题目: 合并有序数组
主题: array & two pointers
解题思路:
1. 两个尾指针,比较大小
'''
class Solution(object):
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: ... |
37e1234e8f39adc280dc20a3c39ea86f93143b0e | zuxinlin/leetcode | /leetcode/110.BalancedBinaryTree.py | 1,342 | 4.28125 | 4 | #! /usr/bin/env python
# coding: utf-8
'''
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as:
a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
Example 1:
Given the following tree [3,9,20,null,null,15... |
738fb0bedabe6835435b64429a5038d11e4f8103 | zuxinlin/leetcode | /leetcode/editor/cn/[剑指 Offer 59 - II]队列的最大值-dui-lie-de-zui-da-zhi-lcof.py | 1,588 | 3.875 | 4 | #! /usr/bin/env python
# coding: utf-8
# 请定义一个队列并实现函数 max_value 得到队列里的最大值,要求函数max_value、push_back 和 pop_front 的均摊时间复杂度都
# 是O(1)。
#
# 若队列为空,pop_front 和 max_value 需要返回 -1
#
# 示例 1:
#
# 输入:
# ["MaxQueue","push_back","push_back","max_value","pop_front","max_value"]
# [[],[1],[2],[],[],[]]
# 输出: [null,null,null,2... |
b9f2df924557a27b03345e5fe1824fceaa96f275 | zuxinlin/leetcode | /leetcode/167.TwoSumII.py | 1,547 | 3.890625 | 4 | #! /usr/bin/env python
# coding: utf-8
"""
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.
The function twoSum should return indices of the two numbers such that they add up to
the target, where index1 must be less than index2. ... |
016268ffd0f3cf0fe5e4f98784af536ef6e44096 | jlyang1990/LeetCode | /160. Intersection of Two Linked Lists.py | 892 | 3.5 | 4 | # Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def getIntersectionNode(self, headA, headB):
"""
:type head1, head1: ListNode
:rtype: ListNode
"""
import gc
... |
7903a699ca0f6c37c0f1199f27faf3cefc2b5e63 | jlyang1990/LeetCode | /070. Climbing Stairs.py | 289 | 3.59375 | 4 | class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
# Fibonacci
current = 1
previous = 1
for i in range(n-1):
current, previous = current+previous, current
return current |
2e349c5ef936fdea0a6650bc9bad9707702c1053 | jlyang1990/LeetCode | /202. Happy Number.py | 479 | 3.5 | 4 | class Solution(object):
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
numSet = {n}
num = n
while num != 1:
num = self.getHappy(num)
if num in numSet:
return False
numSet.add(num)
return True... |
f133a17bb2e55d558ffdb96382c3546afdb740fb | jlyang1990/LeetCode | /334. Increasing Triplet Subsequence.py | 727 | 3.65625 | 4 | class Solution(object):
def increasingTriplet(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
first = float("inf") # smallest (valid) first element in triplet
# or (potential) first element in triplet (for searching for better "second")... |
d98ea080f041891a11878de57678dd7934e4e0ac | jlyang1990/LeetCode | /147. Insertion Sort List.py | 835 | 3.96875 | 4 | # Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def insertionSortList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
new_head = ListNode(None)
... |
0b964656ec5993bab9abcdf6f733ca44bda8b2f5 | jlyang1990/LeetCode | /020. Valid Parentheses.py | 550 | 3.515625 | 4 | class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
dic = {}
dic["("] = ")"
dic["{"] = "}"
dic["["] = "]"
stack = []
for current in s:
if current in dic:
stack.append(current)
... |
d7201ef1d96bf2d235c159a5422af0581c21a6ef | MadyDixit/ProblemSolver | /Dynamic Programming/Longest_Sub_Sequence.py | 2,642 | 4.09375 | 4 | '''
Find the Longest Common Subsequence Length Using Recursion.
'''
def LCSLenghtR(x, y):
'''
:param x: First String
:param y: Second String
:return: Length of Common SubSequence
'''
#If length of string is 0 then return 0
if(len(x) == 0 or len(y) == 0):
return 0
#if last elemen... |
7a750725399d333e2cd1b46add1b8cc0c02b1522 | MadyDixit/ProblemSolver | /Google/Coding/UnivalTree.py | 1,039 | 4.125 | 4 | '''
Task 1: Check weather the Given Tree is Unival or Not.
Task 2: Count the Number of Unival Tree in the Tree.
'''
'''
Task 1:
'''
class Tree:
def __init__(self,x):
self.val = x
self.left = None
self.right = None
def insert(self, data):
if self.val:
if self.val > da... |
eba5ab73e093a8be458110cc4b3dce7c40b9dbaf | Anveshan3175/RaspberriPi | /GPIOlib/button_1.py | 265 | 3.640625 | 4 | from gpiozero import Button
button = Button(2) # button is connected to BCM 2 . Connect +ve of button to GPIO2 and -ve to GND of Raspberri
while True:
if button.is_pressed:
print("BUtton is pressed")
else:
print("Button is not pressed ")
|
13f3c6634009bd5a31f8744220f1073d85a7e882 | Retzudo/invasions.retzudo.com | /invasions.py | 1,558 | 3.59375 | 4 | from datetime import datetime, timedelta
import pytz
class InvasionTimer:
invasion_delta = timedelta(hours=18, minutes=30)
invasion_duration = timedelta(hours=6)
def __init__(self, now=None):
if now is None:
now = datetime.now(tz=pytz.utc)
self.now = now
@property
de... |
795dce14cdc68a508ea2551d371008dad787024f | tsimur/crafts | /search_resize/search_and_resize.py | 640 | 3.59375 | 4 | # Search all files in folder with subfolders then resize and save in specify folder. It means that the files are images
# in the .jpeg format
import os
from PIL import Image
path = 'path to folder with subfolders'
dist = 'path to folder wherer you wont to save converted files'
dirs = [f for f in sorted(os.listdir(path)... |
074fe8b725238cbe5eb7b8735d1c873923825db8 | pldorini/python-exercises | /desafios/desafio 22.py | 365 | 3.796875 | 4 | nome = str(input('Nome completo: ')).strip()
print('Seu nome em letras maiúsculas é {}'.format(nome.upper()))
print('Seu nome em letras minusculas é {}'.format(nome.lower()))
print("Seu nome tem ao todo {} letras".format(len(nome) - nome.count(' ')))
lista = nome.split()
print('O seu primeiro nome é {} e possui {} ... |
5d1d297267c4f08716c8262af86a6a9c27949039 | pldorini/python-exercises | /desafios/desafio 20.py | 272 | 3.71875 | 4 | import random
um = str(input('Primeiro aluno: '))
dois = str(input('Segundo aluno: '))
tres = str(input('Terceiro aluno: '))
quatro = str(input('Quarto aluno: '))
lista = [um, dois, tres, quatro]
random.shuffle(lista)
print('A ordem de apresentação será ')
print(lista) |
3fdbb3af33dd04e23b0ccf2492c8f66c701d936a | pldorini/python-exercises | /desafios/desafio 65.py | 578 | 3.78125 | 4 | c = ''
a = cont = soma = maior = media = menor = 0
while c != 'n':
c = str(input('Quer digitar mais valores, [s/n]? ')).lower().strip()
if c == 's':
n = float(input('Digite um valor: '))
soma += n
cont += 1
if n < a:
menor = n
elif n > a:
maior = n... |
c7eac4a972e857fd9489d84f0f08d14f23f448c8 | pldorini/python-exercises | /desafios/desafio 18.py | 268 | 3.828125 | 4 | import math
n = float(input('Valor do ângulo: '))
sen = math.sin(math.radians(n))
cos = math.cos(math.radians(n))
tan = math.tan(math.radians(n))
print('O valor do seno de {} é {:.2f}, o valor do cosseno é {:.2f} e sua tangente é {:.2f}'.format(n, sen, cos, tan))
|
6fe89f958c96058692b1c8e2be8ef49877503f36 | pldorini/python-exercises | /desafios/desafio 30.py | 121 | 4 | 4 | n = int(input('Digite um numero inteiro: '))
if n%2==0:
print('O numero é par')
else:
print('O numero é impar') |
99d5ad9036f39ddea80b1d4178581510f9dec5b0 | pldorini/python-exercises | /desafios/desafio 40.py | 308 | 3.8125 | 4 | n1 = float(input('Nota da p1: '))
n2 = float(input('Nota da p2: '))
media = (n1 + n2) / 2
if media < 5:
print('Sua média foi de {}, REPROVADO.'.format(media))
elif media < 7:
print('Sua media foi de {}. RECUPERAÇÃO'.format(media))
else:
print('Sua média foi de {}. APROVADO'.format(media))
|
d99281def64d41d40d3264d3aabe241a14e4c3bc | pldorini/python-exercises | /desafios/desafio 87.py | 692 | 3.65625 | 4 | lista = [ [0, 0, 0 ], [0, 0, 0], [0, 0, 0] ]
spares = somac = maior = 0
for l in range(0, 3):
for c in range(0, 3):
lista[l][c] = int(input(f'Digite um valor para {l, c}: '))
print('-='*25)
for l in range(0, 3):
for c in range(0, 3):
print(f'[{lista[l][c]:^5}]', end='')
print()
print('-='*25)... |
ab46e36000c9a98face451c7e2dbc387bd09526c | pldorini/python-exercises | /desafios/desafio 103.py | 289 | 3.6875 | 4 | def ficha(nome, gol):
print(f' O jogador {nome} fez {gol} gol(s) no campeonato')
n = str(input('Nome do Jogador: '))
g = str(input('Numero de gols: '))
if g.isnumeric():
g = int(g)
else:
g = 0
if n.strip() == '':
n = '<Desconhecido>'
ficha(n, g)
else:
ficha(n, g) |
dcab7748453c619890b5472acefac45c3b2fb15b | pldorini/python-exercises | /desafios/desafio 26.py | 285 | 3.90625 | 4 | x = str(input('Digite uma frase: ')).strip().upper()
print('A letra', '"a"', 'aparece {} vezes'.format(x.count('A')))
print('A letra "a" aparece na posição {} na primeira vez'.format(x.find('A')+1))
print('A letra "a" aparece na posição {} na ultima vez'.format(x.rfind('A')+1)) |
9c749d809605b4d6342a8ff41334a4b510a28bac | pkray91/laravel | /function/p11.py | 79 | 3.53125 | 4 | def sum(*b):
c = 0
for x in b:
c = c+x
#print(c)
print(c)
sum(2,2,3,4,5) |
e5a098ea96c6ae7fa002678f3db41e24cad21731 | pkray91/laravel | /list/removelist.py | 220 | 3.71875 | 4 | list = ["apple", "banana", "cherry",'guava','banana'];
#list.pop(2);
#list.pop();will remove last value
#list.remove('banana');
#del list[0:2];To delete multiple values
#list.clear();
mylist=list.copy();
print(mylist);
|
02d2c723586f0b98c48dde041b20e5ec86809fae | pkray91/laravel | /string/string.py | 1,254 | 4.4375 | 4 | print("Hello python");
print('Hello python');
x = '''hdbvfvhbfvhbf'''
y = """mdnfbvnfbvdfnbvfvbfm"""
print(y)
print(x)
a='whO ARE you Man';
print(a);
print(a.upper());
print(a.lower());
print(len(a));
print(a[1]);
#sub string not including the given position.
print(a[4:8]);
#The strip() method removes any whitespace f... |
0bddbc86afd48fbdb488be7f1bc28d3622a6677c | pkray91/laravel | /loop/star/prime2.py | 137 | 4.125 | 4 |
num = int(input("Enter a number:-"))
for x in range(2,num):
if(num%x==0):
print('not prime')
break
else:
print('number is prime') |
122824735c955da08bc9b1a52beeddddda16d4e6 | pkray91/laravel | /cinput/p1.py | 64 | 3.5625 | 4 | print("enter your name")
x= input();
print("hello dear " + x); |
31e333d434cb484995f4cac6ba1c6617cd7286e0 | pkray91/laravel | /oops/insmethod2.py | 824 | 3.625 | 4 | #instant method which is work with instant var
#class method which is work with class var
#static method ->which not work with class or instant var and
#work for some difference purpose is callled static metod
class student:
school = "DAV"
def __init__(self,m1,m2,m3):
self.m1 = m1
self.m2 = m2
s... |
2bd8036e81a181e025079d9a7b994bdd1e3f8a95 | pkray91/laravel | /loop/table.py | 67 | 3.859375 | 4 |
for x in range(1,11):
a = "5 X {} =>"
print(a.format(x),x*5)
|
9079f259263abeb9d14d3ea21ce3aa54befdc327 | pkray91/laravel | /oops/ooverloading.py | 478 | 3.9375 | 4 |
'''a= 5;
b= 10;
c= '20'
d='50'
print(a+b);
print(int.__add__(a,b));
print(str.__add__(c,d));'''
class student:
def __init__(self,m1,m2):
self.m1 = m1
self.m2 = m2
def __add__(self,other):
m1 = self.m1 + other.m1;
m2 = self.m2 + other.m2;
s3 = student(m1,m2);
return s3;
s1= student(33,55)
s2... |
5539edcc841528d1fc071b5f0cf9745ca5a36d9a | pkray91/laravel | /oops/encapsulation.py | 499 | 3.828125 | 4 | class car:
def __init__(self,color,speed):
self.__speed = speed
self.__color = color
# def set_speed(self,value):
# self.__speed = value
# def get_speed(self):
# return self.__speed
# def set_color(self,value):
# self.__color = value
# def get_color(self):
# return self.__color
ford = ... |
e7ff13ed4f9552c927e7966a538d10d5e485cd37 | pkray91/laravel | /lambda/p1.py | 211 | 3.8125 | 4 | #A lambda function is a small anonymous function.
#lambda arguments : expression.(syntax)
#A lambda function can take any number of arguments,
# but can only have one expression
x= lambda a: a+10;
print(x(10)) |
b441974e584a0612f27557dc90fbc5c3467d375f | VISH01AL/sqlite3_learn | /Bank mangament/mainprogram.py | 6,909 | 3.875 | 4 | import sqlite3
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
except Error as e:
print(e)
return conn
def accexist(accno,c):
c.execute("""select accno from customer where accno=:accno""",{'accno':accno})
li=c.fetchone()
if li:
... |
02856d48e4fedd6645699e7fc4929e80e1ffac7e | 561nano/Python_Change_Calculator | /value-count.py | 1,299 | 3.734375 | 4 | # Provide the count of each value (highest to lowest)
countOfValue = {100: 2, 50: 10, 20: 10, 10: 10, 5: 10, 1: 10, .25: 10, .10: 1, .05: 10, .01: 10}
# Provide the change need to return
changeNeeded = 200.98
# The list that will give you the change you need, what is left in the register and if there is not enough mo... |
64b3b105be12ab35fb7f6ae74f390d12cc479da2 | PropeReferio/practice-2 | /pp16.py | 821 | 3.875 | 4 | # Write a password generator in Python. Be creative with how you generate passwords
# - strong passwords have a mix of lowercase letters, uppercase letters, numbers,
# and symbols. The passwords should be random, generating a new password every time
# the user asks for a new password. Include your run-time code in a... |
8f145d94b26e5f8fa733c0e349a5154f82b8b004 | PropeReferio/practice-2 | /try_except.py | 496 | 3.5625 | 4 |
try:
f = open('corrupt.txt')
# var = bad_var
if f.name == 'corrupt.txt':
raise Exception
except FileNotFoundError:
print('Sorry, that file doesn\'t exist.')
except NameError as e:
print('There was a problem with a variable name: ', e)
except Exception:
print('Error!')
else:
#This block fires when the try bloc... |
eb14ce689ed798211cb801ecae29892e0c23297c | PropeReferio/practice-2 | /spiral.py | 1,428 | 4.03125 | 4 | # This problem was asked by Amazon.
# Given a N by M matrix of numbers, print out the matrix in a clockwise spiral.
# For example, given the following matrix:
matrix = [[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]]
# You should print out the follow... |
d00abf93039f9475fa21b3159bc0d093bc5b2312 | janthenelli/Python-Phrase-Hunters | /phrasehunter/game.py | 2,887 | 3.859375 | 4 | # Create your Game class logic in here.
import random
import re
from phrase import Phrase
from phraseslist import RANDOM_PHRASES
class Game:
def __init__(self, phrases):
self.phrases = [Phrase(phrase) for phrase in phrases]
self.selected_phrase = random.choice(self.phrases)
self.l... |
0ee9e3d684e4a810701066ada2cc0daf04347abf | WebClub-NITK/Hacktoberfest-2k20 | /Algorithms/14_disjoint_set/disjoint-set.py | 989 | 4.1875 | 4 | # Python3 program to implement Disjoint Set Data Structure for union and find.
class DisjSet:
def __init__(self, n):
self.rank = [1] * n
self.parent = [i for i in range(n)]
# Finds set of given item x
def find(self, x):
if self.parent[x] != x:
self.parent[x] = self.find... |
e4ea5fe333cb183973ef2d48773931461168d86b | WebClub-NITK/Hacktoberfest-2k20 | /Algorithms/64_Schools_Covid_19/schools.py | 2,651 | 3.96875 | 4 | """Solution to Schools During Covid-19 problem."""
import io
import sys
from typing import Iterable, List, Set, Tuple
class NoSolutionError(Exception):
"""Raised when there is no solution."""
pass
class SchoolClass:
"""School class with number of students and friendships."""
def __init__(self, num... |
011bc9a9a3822a5d01088c5d77b0deedeedfe53a | dannydijkzeul/datascienceTest | /datascienceTest.py | 7,324 | 3.6875 | 4 | '''
Authors: Danny Dijkzeul
10554386
'''
class Article():
# Creates article object with all information of the articles content
def __init__(self, docno, docid, date, section, length, headline):
self.docno = docno
self.docid = docid
self.date = date
self.section = sectio... |
5098ab1579cf8a763bf49349ad48a14a245744bc | Hermotimos/EvaluationsDB | /db_setup.py | 5,180 | 3.84375 | 4 | """
Create 'evaluations' database with random evaluations for predefined titles.
Steps:
1. Creates database (drops one if exists).
2. Creates tables (movies_evaluations, tvseries_evaluations, pcgames_evaluations, boardgames_evaluations).
3. Populates tables with random number of random-... |
5af8b2dfcff4a09b489bf1e1dbaa3718fd41bc45 | dipprog/Competitive-Programming | /DSA/4. Divide And Conquer/binary_search_dac.py | 474 | 4.03125 | 4 | def binary_search(A, start, end, X):
if start <= end:
middle = (start + end)//2
if A[middle] == X :
return middle
if X < A[middle]:
return binary_search(A, start, middle-1, X)
if X > A[middle] :
return binary_search(A, middle+1, end, X)
return ... |
316fe989c7fda250ec21acf42374d85ce43d6e2b | dipprog/Competitive-Programming | /Sorting/insertion_sort.py | 273 | 3.90625 | 4 | def insertion_sort(A):
for i in range(len(A)):
j=i
while (j > 0) and (A[j-1] > A[j]):
A[j-1], A[j] = A[j], A[j-1]
j = j-1
if __name__ == '__main__':
ar = [4, 8, 1, 3, 10, 9, 2, 11, 5, 6]
insertion_sort(ar)
print(ar)
|
7ca1555260cf8076aa6202d3512a2267b67116e0 | dipprog/Competitive-Programming | /Heap And Priority Queue/max_priority_queue.py | 2,633 | 3.5 | 4 | heap_size = 0
tree_array_size = 20
INF = 100000
# Get right child
def get_right_child(A, index):
if ((2*index + 1) < len(A)) and (index >=1):
return (2*index + 1)
return -1
# Get left child
def get_left_child(A, index):
if ((2*index) < len(A)) and (index >=1):
return (2*index)
return -1
... |
926e03d025b30bb6437458666d62d68a8f916cdb | derekcswong/BlackJack | /tests/test_Hand.py | 751 | 3.78125 | 4 | import unittest
from Card import Card
from Hand import Hand
class TestHand(unittest.TestCase):
def test_add_card(self):
hand = Hand()
c1 = Card("Spades", "Two")
c2 = Card("Hearts", "Jack")
hand.add_card(c1)
self.assertEqual(hand.value, 2)
hand.add_card(c2)
s... |
e83a435f773d23999da8569f04e7d4c4f4a7829a | WoshoForegun/1-to-10 | /brosly.py | 57 | 3.5 | 4 | i = 1
while i<=10:
if i != 5:
print(i)
i=i+1 |
e6a64eed1788c406cc17469d221c3caa55e7d89a | zarifmahmud/DoodleMyWorld | /voice_doodle.py | 4,056 | 3.9375 | 4 | """
Functions to recognize and process voice commands
"""
import security
import azure.cognitiveservices.speech as speechsdk
from draw import grid_fill, grid_draw, erase_image
def speech_recognize() -> str:
"""
Using Microsoft Azure to convert your speech into text. It will process after you finis... |
b1ce850e7188a0ccd18b09d749deed9d4f24e16d | jnomellini/Python-For-Managers | /variables.py | 260 | 3.734375 | 4 | # Variables are just nicknames
# They're plain, lowercase words
name = "Mattan Griffel"
orphan_fee = 200
teddy_bear_fee = 121.80
total = orphan_fee + teddy_bear_fee
print(name, "the total will be", total)
print(f"{name} the total will be {total:.2f}")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.