blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
782b19c9bf441bca8e8c5ae754cbec05c0bce121
khuang7/3121-algorithms
/dynamic_programming/fib.py
838
4.125
4
''' A simple fibonacci but using memoization and dynamic programing An introduction to the basics of dynamic programming ''' memo = {} def main(): print(fib_naive(5)) print(fib_bottoms_up(4)) def fib_naive(n): ''' We used the recursive method in order to fine every combination from f(n) down the ...
false
89495c7cb55268122493bb126b1e3ea9a9c19fca
Jamilnineteen91/Sorting-Algorithms
/Merge_sort.py
1,986
4.34375
4
nums = [1,4,5,-12,576,12,83,-5,3,24,46,100,2,4,1] def Merge_sort(nums): if len(nums)<=1: return nums middle=int(len(nums)//2)#int is used to handle a floating point result. left=Merge_sort(nums[:middle])#Divises indices into singular lists. print(left)#Prints list division, lists with singular...
true
b59d828a5f75746cff11a5238a485c7cc98b594d
Expert37/python_lesson_3
/123.py
1,099
4.5
4
temp_str = 'Все счастливые семьи похожи друг на друга, каждая несчастливая семья несчастлива по-своему. Все счастливые семьи' print('1) методами строк очистить текст от знаков препинания;') for i in [',','.','!',':','?']: temp_str = temp_str.replace(i,'') print(temp_str) print() print('2) сформировать list со слов...
false
b4d3e19be67069f37487506a473ba9bce4def0be
jeffjbilicki/milestone-5-challenge
/milestone5/m5-bfs.py
631
4.1875
4
#!/usr/bin/env python # Given this graph graph = {'A': ['B', 'C', 'E'], 'B': ['A','D', 'E'], 'C': ['A', 'F', 'G'], 'D': ['B'], 'E': ['A', 'B','D'], 'F': ['C'], 'G': ['C']} # Write a BFS search that will return the shortest path def bfs_shortest_path(graph, start, ...
true
580a215b24366f1e6dcf7d3d5253401667aa1aae
afialydia/Graphs
/projects/ancestor/ancestor.py
2,127
4.125
4
from util import Queue class Graph: """Represent a graph as a dictionary of vertices mapping labels to edges.""" def __init__(self): self.vertices = {} def add_vertex(self, vertex_id): """ Add a vertex to the graph. """ if vertex_id not in self.vertices: ...
true
4e21512a276938c54dc5a26524338584d3d31673
snangunuri/python-examples
/pyramid.py
1,078
4.25
4
#!/usr/bin/python ############################################################################ #####This program takes a string and prints a pyramid by printing first character one time and second character 2 timesetc.. within the number of spaces of length of the given string### ######################################...
true
76c008e9115f338deac839e9e2dafd583377da46
pkongjeen001118/awesome-python
/generator/simple_manual_generator.py
517
4.15625
4
def my_gen(): n = 1 print('This is printed first') yield n n += 1 print('This is printed second') yield n n += 1 print('This is printed at last') yield n if __name__ == '__main__': a = my_gen() # return generator obj. print(a) print(next(a)) # it will resume t...
true
5cb87538a3b33dd04ec2d3ded59f0524c04519c4
pkongjeen001118/awesome-python
/data-strucutre/dictionaries.py
480
4.375
4
#!/usr/bin/python # -*- coding: utf-8 -*- # simple dictionary mybasket = {'apple':2.99,'orange':1.99,'milk':5.8} print(mybasket['apple']) # dictionary with list inside mynestedbasket = {'apple':2.99,'orange':1.99,'milk':['chocolate','stawbery']} print(mynestedbasket['milk'][1].upper()) # append more key myba...
false
ff8bc8c1966b5211da2cba678ef60cad9a4b225d
RossySH/Mision_04
/Triangulos.py
1,020
4.25
4
# Autor: Rosalía Serrano Herrera # Define qué tipo de triángulo corresponde a las medidas que teclea el usuario def definirTriangulo(lado1, lado2, lado3): #determina que tipo de triangulo es dependiendo sus lados if lado1 == lado2 == lado3: return "Equilátero" elif lado1 == lado2 or lado1 == l...
false
1f291ba8c19a6b242754f14b58e0d229385efe8b
JunyoungJang/Python
/Introduction/01_Introduction_python/10 Python functions/len.py
663
4.1875
4
import numpy as np # If x is a string, len(x) counts characters in x including the space multiple times. fruit = 'banana' fruit_1 = 'I eat bananas' fruit_2 = ' I eat bananas ' print len(fruit) # 6 print len(fruit_1) # 13 print len(fruit_2) # 23 # If x is a (column or row) vector, len(x) reports the length o...
true
6e8ac507b80dd1641922f895a1d06bba718065c3
ICESDHR/Bear-and-Pig
/笨蛋为面试做的准备/leetcode/Algorithms and Data Structures/sort/bubble_sort.py
343
4.15625
4
def bubble_sort(lists): if len(lists) <= 1: return lists for i in range(0, len(lists)): for j in range(i + 1, len(lists)): if lists[i] > lists[j]: lists[j], lists[i] = lists[i], lists[j] return lists if __name__ == "__main__": lists = [9, 8, 7, 6, 5] pri...
false
0ff9201f5970cca2af58757d2d855446994e0335
ICESDHR/Bear-and-Pig
/Practice/Interview/16.数值的整数次方.py
1,054
4.3125
4
# -*- coding:utf-8 -*- # 看似简单,但是情况要考虑周全 def Pow(base,exponent): if exponent == 0: return 1 elif exponent > 0: ans = base for i in range(exponent-1): ans *= base return ans else: if base == 0: return 'Error!' else: ans = base for i in range(-exponent-1): ans *= base return 1/ans # 对算法...
false
571400657495936c96d31a67b1bc2afeeeaa1bf6
ICESDHR/Bear-and-Pig
/Practice/Interview/24.反转链表.py
1,016
4.34375
4
# -*- coding:utf-8 -*- class ListNode: def __init__(self,value): self.value = value self.next = None # 没思路 def ReverseList(root): pNode,parent,pHead = root,None,None while pNode: child = pNode.next if child is None: pHead = pNode pNode.next = parent parent = pNode pNode = child return pHead # 递归...
true
c247ba288604b38dafbb692aa49acf8b74ebd353
izdomi/python
/exercise10.py
482
4.25
4
# Take two lists # and write a program that returns a list that contains only the elements that are common between the lists # Make sure your program works on two lists of different sizes. Write this using at least one list comprehension. # Extra: # Randomly generate two lists to test this import random list1 = random...
true
086daed19d3d5115b9be43430c74c52d4cda4e15
izdomi/python
/exercise24.py
1,385
4.375
4
# Ask the user what size game board they want to draw, and draw it for them to the screen using Python’s # print statement. def board_draw(height, width): top = "┌" + "┬".join(["─"*4]*width) + "┐\n" bottom = "└" + "┴".join(["─"*4]*width) + "┘" middle = "├" + "┼".join(["─"*4]*width) + "┤\n" print(top + ...
false
698212d5376c53e07b4c5410dfd77aac16e97bd2
izdomi/python
/exercise5.py
703
4.21875
4
# Take two lists, # and write a program that returns a list that contains only the elements that are common between the lists. # Make sure your program works on two lists of different sizes. # Extras: # Randomly generate two lists to test this # Write this in one line of Python lst1 = [] lst2 = [] num1 = int(input("l...
true
7b9a073898d2fcd5854326707e0ce0bd464449e1
muyisanshuiliang/python
/function/param_demo.py
2,612
4.1875
4
# 函数的参数分为形式参数和实际参数,简称形参和实参: # # 形参即在定义函数时,括号内声明的参数。形参本质就是一个变量名,用来接收外部传来的值。 # # 实参即在调用函数时,括号内传入的值,值可以是常量、变量、表达式或三者的组合: # 定义位置形参:name,age,sex,三者都必须被传值,school有默认值 def register(name, age, sex, school='Tsinghua'): print('Name:%s Age:%s Sex:%s School:%s' % (name, age, sex, school)) def foo(x, y, z=3, *args): print(...
false
3a53ab12f8144942fbfcb56bbb56d407c32bdf3e
autumnalfog/computing-class
/Week 2/a21_input_int.py
345
4.21875
4
def input_int(a, b): x = 0 while x != "": x = input() if x.isdigit(): if int(x) >= a and int(x) <= b: return x print("You should input a number between " + str(a) + " and " + str(b) + "!") print("Try once more or input empty line to cancel input check....
true
9fdc839e30c4eccbb829abfa30178545f2f3f7b3
sheayork/02A-Control-Structures
/E02a-Control-Structures-master/main06.py
719
4.5
4
#!/usr/bin/env python3 import sys assert sys.version_info >= (3,7), "This script requires at least Python 3.7" print('Greetings!') color = input("What is my favorite color? ") if (color.lower().strip() == 'red'): print('Correct!') else: print('Sorry, try again.') ##BEFORE: Same as before, but some people ma...
true
b93667bb58dfc610850d6ffa407ee418af6f44b0
Mamedefmf/Python-Dev-Course-2021
/magic_number/main.py
1,233
4.15625
4
import random def ask_number (min, max): number_int = 0 while number_int == 0: number_str = input(f"What is the magic number ?\nType a number between {min} and {max} : ") try: number_int = int(number_str) except: print("INPUT ERROR: You need to type a valid numbe...
true
2a2ae134cceba04732db0f61fb19f83221ca3f1d
pranavkaul/Coursera_Python_for_Everybody_Specialization
/Course-1-Programming for everybody-(Getting started with Python/Assignment_6.py
999
4.3125
4
#Write a program to prompt the user for hours and rate per hour using input to compute gross pay. #Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. #Put the logic to do the computation of pay in a function called computepay() and use the funct...
true
412e2228c42ecdd818ffc52c0ebad6ef7e5035ad
vid083/dsa
/Python_Youtube/type.py
241
4.1875
4
value = int(input('Input a value: ')) if type(value) == str: print(value, 'is a string') elif type(value) == int: print(value, 'is a integer') elif type(value) == list: print(value, 'is a list') else: print(value, 'is none')
false
050611de1ceb8e48c8ee2f79ca721147e5a4f0cb
zhouyuhangnju/freshLeetcode
/Sort Colors.py
1,153
4.21875
4
def sortColors(nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ def quicksort(nums): def subquicksort(nums, start, end): if start >= end: return p = nums[start] i, j, di...
false
fb801c2f3b6afaab1a64650d8a10811d0726a5e7
wohao/cookbook
/counter1_12.py
563
4.15625
4
from collections import Counter words = [ 'look', 'into', 'my', 'eyes', 'look', 'into', 'my', 'eyes', 'the', 'eyes', 'the', 'eyes', 'the', 'eyes', 'not', 'around', 'the', 'eyes', "don't", 'look', 'around', 'the', 'eyes', 'look', 'into', 'my', 'eyes', "you're", 'under' ] word_counters = Counter(word...
false
df4a4165ed70cee917e537eb19b1ed040703dbc7
Craby4GitHub/CIS129
/Mod 2 Pseudocode 2.py
2,879
4.3125
4
######################################################################################################################## # William Crabtree # # 27Feb17 ...
true
4b1ae200aa26d0259e03ec346abdb42c4671b26b
Craby4GitHub/CIS129
/Final/Final.py
2,265
4.1875
4
######################################################################################################################## # William Crabtree # # 26Apr17 ...
true
f5f85d737006dc462254a2926d4d7db88db72cb6
WarrenJames/LPTHWExercises
/exl9.py
1,005
4.28125
4
# Excercise 9: Printing, Printing, Printing # variable "days" is equal to "Mon Tue Wed Thu Fri Sat Sun" days = "Mon Tue Wed Thu Fri Sat Sun" # variable "months" is Jan Feb Mar Apr May Jun Aug seperated by \n # \n means words written next will be printed on new a line months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nAug" # p...
true
e6f1bf912c575ed81b4b0631514ee67943a26f2f
WarrenJames/LPTHWExercises
/exl18.py
1,977
4.875
5
# Excercise 18: Names, Variables, Code, Functions # Functions do three things: # They name pieces of code the way variables name strings and numbers. # They take arguments the way your scripts take argv # Using 1 and 2 they let you make your own "mini-scripts" or "tiny commands" # First we tell python we want to...
true
fd90e5312f0798ca3eb88c8139bdd2fe17786654
SaloniSwagata/DSA
/Tree/balance.py
1,147
4.15625
4
# Calculate the height of a binary tree. Assuming root is at height 1 def heightTree(root): if root is None: return 0 leftH = heightTree(root.left) rightH = heightTree(root.right) H = max(leftH,rightH) # height of the tree will be the maximum of the heights of left subtree and right subtr...
true
4af84efdf7b997185c340f2b69e7873d5b87df73
SaloniSwagata/DSA
/Tree/BasicTree.py
1,377
4.1875
4
# Creating and printing a binary tree # Creating a binary tree node class BinaryTreeNode: def __init__(self,data): self.left = None self.data = data self.right = None # Creating a tree by taking input tree wise (i.e, root - left subtree - right subtree) # For None, the user enters -1 def ...
true
c868093ac8ba3e14bad9835728fcc45598e0dfd5
SaloniSwagata/DSA
/Tree/levelOrder.py
1,309
4.25
4
# Taking input level order wise using queue # Creating a binary tree node class BinaryTreeNode: def __init__(self,data): self.left = None self.data = data self.right = None import queue # Taking Level Order Input def levelInput(): rootData = int(input("Enter the root node data: ")) ...
true
dbd90779db40037c1cdf29d85485c84b397405fc
Sudeep-K/hello-world
/Automating Tasks/Mad Libs.py
1,445
4.5
4
#! python ''' Create a Mad Libs program that reads in text files and lets the user add their own text anywhere the word ADJECTIVE, NOUN, ADVERB, or VERB appears in the text file. The program would find these occurrences and prompt the user to replace them. The results should be printed to the screen and saved to...
true
e10c4cd35fce90bc44dbb4dd3ffaf75b13adcaa9
harishvinukumar/Practice-repo
/Break the code.py
1,503
4.28125
4
import random print('''\t\t\t\t\t\t\t\t### --- CODEBREAKER --- ### \t\t\t\t\t1. The computer will think of 3 digit number that has no repeating digits. \t\t\t\t\t2. You will then guess a 3 digit number \t\t\t\t\t3. The computer will then give back clues, the possible clues are: \t\t\t\t\tClose: You've guessed a corre...
true
af069f0404ed5594b2fb77da8613ebda76b8c040
DreamHackchosenone/python-algorithm
/binary_tree/traversing.py
1,311
4.1875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/3/19 22:10 class TreeNode(object): # 定义树结构 def __init__(self, root=None, left=None, right=None): self.root = root self.left = left self.right = right def preorder_traverse(tree): # 递归遍历顺序:根->左->右 if tree is None:...
false
2b25649637cefbdec2e8e389202a08fd82dbf1f0
ramyagoel98/acadview-assignments
/assignment11.py
651
4.28125
4
#Regular Expressions: #Question 1: Valid Emaild Address: import re as r email = input("Enter the E-mail ID: ") matcher = r.finditer('^[a-z][a-zA-Z0-9]*[@](gmail.com|yahoo.com)', email) count = 0 for i in matcher: count += 1 if count == 1: print('Valid E-mail Address') else: print('Inval...
false
97aa8452a4bab355d139eed764ebfd5f692ab06b
shaikzia/Classes
/yt1_cor_classes.py
691
4.21875
4
# Program from Youtube Videos - corey schafer """ Tut1 - Classes and Instances """ #Defining the class class Employee: def __init__(self,first,last,pay): self.first = first self.last = last self.pay = pay self.email = first + '.' + last + '@company.com' def fullname(self): ...
true
94d737b1eb5d4fa7d9714e85c7c3fd2f925077a0
lukasbindreiter/enternot-pi
/enternot_app/pi/distance.py
774
4.125
4
from math import sin, cos, sqrt, atan2, radians def calculate_distance(lon1: float, lat1: float, lon2: float, lat2: float) -> float: """ Calculate the distance in meters between the two given geo locations. Args: lon1: Longitude from -180 to 180 lat1: Latitude from ...
false
4e592149e3f98f2d428bb5a37dd85431ad7be763
Deepkumarbhakat/Python-Repo
/factorial.py
206
4.25
4
#Write a program to find the factorial value of any number entered through the keyboard n=5 fact=1 for i in range(0,n,-1): if i==1 or i==0: fact=fact*1 else: fact=fact*i print(fact)
true
866d38f72f63b3d2d1ec87bfd1b330f04cf33635
Deepkumarbhakat/Python-Repo
/Write a program to check if a year is leap year or not. If a year is divisible by 4 then it is leap year but if the year is century year like 2000, 1900, 2100 then it must be divisible by 400..py
320
4.28125
4
#Write a program to check if a year is leap year or not. y=int(input('enter any year : ')) if (y % 4 == 0): if (y % 100 == 0): if (y % 400 == 0): print('leap year') else: print('not a leap year') else: print('leap year') else: print('not a leap year')
false
27cd32606dddc864ce68c35f824a533e1467419d
Deepkumarbhakat/Python-Repo
/function3.py
243
4.28125
4
# Write a Python function to multiply all the numbers in a list. # Sample List : (8, 2, 3, -1, 7) # Expected Output : -336 def multiple(list): mul = 1 for i in list: mul =mul * i print(mul) list=[8,2,3,-1,7] multiple(list)
true
3a98e9a55e3217f3f4faa76b71ab08a75adf1d8e
Deepkumarbhakat/Python-Repo
/function9.py
434
4.25
4
# Write a Python function that takes a number as a parameter and check the number is prime or not. # Note : A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors # other than 1 and itself. def prime(num): for i in range(2,num//2): if num % i == 0: print...
true
63507dcd1e550687bbc7d6108211bd15cf2164af
Deepkumarbhakat/Python-Repo
/string15.py
282
4.15625
4
# Write a Python program that accepts a comma separated sequence of words as input # and prints the unique words in sorted form (alphanumerically). # Sample Words : red, white, black, red, green, black # Expected Result : black, green, red, white,red st=("input:"," , ") print(st)
true
5ed7472af54b4e92e4f8b8160dbdfa42fc8a0c7b
deepabalan/byte-of-python
/functions/function_varargs.py
720
4.15625
4
# When we declare a starred parameter such as *param, then all the # positional arguments from that point till the end are collected as # a tuple called 'param'. # Similarly, when we declare a double-starred parameter such as **param, # then all the keyword arguments from that point till end are collected # as a dict...
true
e2f198706079a03d282121a9959c8e913229d07c
hazydazyart/OSU
/CS344/Homework2/Problem4.py
959
4.15625
4
#Megan Conley #conleyme@onid.oregonstate.edu #CS344-400 #Homework 2 import os import sys import getopt import math #Function to check if a number is prime #Arguments: int #Return: boolean #Notes: a much improved function to find primes using the sieve, this time using the #square root hint from Homework 1. def isPrim...
true
a5b0bcd93668247dbaeaa869de1e1f136aa32f28
emilyscarroll/MadLibs-in-Python
/MadLibs.py
593
4.21875
4
# Story: There once was a very (adjective) (animal) who lived in (city). He loved to eat (type of candy). #1) print welcome #2) ask for input for each blank #3) print story print("Hello, and welcome to MadLibs! Please enter the following words to complete your story.") adj = input("Enter an adjective: ") animal = inp...
true
4f82dfb7a6b951b9a5fed1546d0743adb4109fbd
kkeller90/Python-Files
/newton.py
335
4.375
4
# newtons method # compute square root of 2 def main(): print("This program evaluates the square root of 2 using Newton's Method") root = 2 x = eval(input("Enter number of iterations: ")) for i in range(x): root = root - (root**2 - 2)/(2*root) print(root) main() ...
true
35a1dde2f54c79e8bdb80f5cd0b0d727c3ee1e4f
Rurelawati/pertemuan_12
/message.py
1,000
4.1875
4
# message = 'Hello World' # print("Updated String :- ", message[:6] + 'Python') # var1 = 'Hello World!' # penggunaan petik tunggal # var2 = "Python Programming" # penggunaan petik ganda # print("var1[0]: ", var1[0]) # mengambil karakter pertama # print("var2[1:5]: ", var2[1:5]) # karakter ke-2 s/d ke-5 # Nama ...
false
bb83df21cb7dc89440d61876288bfd6bafce994d
ZzzwyPIN/python_work
/chapter9/Demo9_2.py
1,137
4.28125
4
class Car(): """一次模拟汽车的简单尝试""" def __init__(self,make,model,year): self.make = make self.model = model self.year = year self.odometer_reading = 0 def get_descriptive_name(self): """返回整洁的描述性信息""" long_name = str(self.year)+' '+self.make+' '+self.model return long_name.title() def read_odometer(s...
true
2785927c8c0c73534d66a3e2742c334e3c9c67bd
rocksolid911/lucky13
/weight_change.py
314
4.21875
4
weight = int(input("enter your weight: ")) print(f'''your weight is {weight} is it in pound or kilos ?''') unit = input("(l)pound or (k)kilogram: ") if unit.upper() == "L": convert = weight * 0.45 print(f"you are {convert} kilos") else: convert = weight / 0.45 print(f"you are {convert} pound")
false
eac160ec897eed706fd6924ef2c55bef93159034
AlirieGray/Tweet-Generator
/qu.py
1,052
4.21875
4
from linkedlist import LinkedList from linkedlist import Node class Queue(LinkedList): def __init__(self, iterable=None): super().__init__(iterable) def enqueue(self, item): """Add an object to the end of the Queue.""" self.append(item) def dequeue(self): """Remove and ret...
true
09a979bccf9cce42b1fa77cf88cf8fa889037879
michaelworkspace/AdventOfCode2020
/day01.py
1,277
4.40625
4
from typing import List def find_product(inputs: List[int]) -> int: """Given a list of integers, if the sum of two element is 2020, return it's product.""" # This is the classic Two Sum problem # This is not good solution because it is O(n^2) # for x in INPUTS: # for y in INPUTS: # ...
true
0ad185da2701617e9580000faad35f2c31df8c9a
YasmineCodes/Interview-Prep
/recursion.py
2,641
4.3125
4
# Write a function fib, that finds the nth fibonacci number def fib(n): assert n >= 0 and int(n) == n, "n must be a positive integer" if n == 1: return 0 elif n == 2: return 1 else: return fib(n-1) + fib(n-2) print("The 4th fibonacci number is: ", fib(4)) # 2 print("The 10th ...
true
e3382c4e700995d5decef3245d859372123decae
b21727795/Programming-with-Python
/Quiz2/quiz2_even_operation.py
596
4.3125
4
import sys def choose_evens(input_string): evens = [int(element) for element in input_string.split(',') if(int(element)> 0 and int(element) % 2 == 0) ] all_numbers = [int(element) for element in input_string.split(',') if int(element)> 0] even_number_rate = sum(evens) / sum(all_numbers) print("Ev...
false
aa92573b123c0f334eca8304adae5b1410f108e5
Xia-Sam/hello-world
/rock paper scissors game against computer.py
1,714
4.3125
4
import random rand_num=random.randint(1,3) if rand_num==1: com_side="rock" elif rand_num==2: com_side="paper" else: com_side="scissors" i=0 while i<5: print("You can input 'stop' at anytime to stop the game but nothing else is allowed.") user_side=input("Please input your choice (R P S stands for r...
true
2d30aaf0eddd3a054f84063e3d6971b4933097af
irosario1999/30days-of-python
/day_2/variables.py
1,014
4.125
4
from math import pi print("Day 2: 30 days of python") firstName = "ivan" lastName = "Rosario" fullName = firstName + " " + lastName country = "US" city = "miami" age = "21" year = "2020" is_married = False is_true = True is_light_on = False i, j = 0, 3 print(type(firstName)) print(type(lastName)) print(type(fullName...
false
55ae7ae4ad64c690800e9d2a9d37684eb3069bb9
andkoc001/pands-problem-set
/06-secondstring.py
1,379
4.15625
4
# Title: Second Strig # Description: Solution to problem 6 - program that takes a user input string and outputs every second word. # Context: Programming and Scripting, GMIT, 2019 # Author: Andrzej Kocielski # Email: G00376291@gmit.ie # Date of creation: 10-03-2019 # Last update: 10-03-2019 ### # Prompt for the user;...
true
3cc0fcee11a7eea3411f26afebac5fea6eebd6b1
BlackJimmy/SYSU_QFTI
/mateig.py
427
4.15625
4
#this example shows how to compute eigen values of a matrix from numpy import * #initialize the matrix n = 5 a = zeros( (n, n) ) for i in range(n): a[i][i] = i if(i>0): a[i][i-1] = -1 a[i-1][i] = -1 #print the matrix print "The matrix is:" for i in range(n): print a[i] #compute the eigen ...
true
d7d9550e9acb11727564ba122a9427139f47a5e3
ode2020/bubble_sort.py
/bubble.py
388
4.1875
4
def bubble_sort(numbers): for i in range (len(numbers) - 1, 0, -1): for j in range (i): if numbers[j] > numbers[j+1]: temp = numbers[j] numbers[j] = numbers[j+1] numbers[j+1] = temp print(numbers) numbers = [5, 3, 8, 6, 7, 2] bubble_s...
true
aa83f5258b80e1c403a25d30aeb96f2a8125ec73
ravalrupalj/BrainTeasers
/Edabit/Day 3.3.py
459
4.125
4
#Get Word Count #Create a function that takes a string and returns the word count. The string will be a sentence. #Examples #count_words("Just an example here move along") ➞ 6 #count_words("This is a test") ➞ 4 #count_words("What an easy task, right") ➞ 5 def count_words(txt): t = txt.split() return len(t) prin...
true
9975f7dc75b81bbbe7cfdcd701f2e09335a3ce54
ravalrupalj/BrainTeasers
/Edabit/Emptying_the_values.py
1,532
4.4375
4
#Emptying the Values #Given a list of values, return a list with each value replaced with the empty value of the same type. #More explicitly: #Replace integers (e.g. 1, 3), whose type is int, with 0 #Replace floats (e.g. 3.14, 2.17), whose type is float, with 0.0 #Replace strings (e.g. "abcde", "x"), whose type is st...
true
60a84a613c12d723ba5d141e657989f33930ab74
ravalrupalj/BrainTeasers
/Edabit/Powerful_Numbers.py
615
4.1875
4
#Powerful Numbers #Given a positive number x: #p = (p1, p2, …) # Set of *prime* factors of x #If the square of every item in p is also a factor of x, then x is said to be a powerful number. #Create a function that takes a number and returns True if it's powerful, False if it's not. def is_powerful(num): i=1 l=...
true
4dd2faade46f718a07aeba94270ea71ff90b5996
ravalrupalj/BrainTeasers
/Edabit/Is_the_Number_Symmetrical.py
462
4.4375
4
#Create a function that takes a number as an argument and returns True or False depending on whether the number is symmetrical or not. A number is symmetrical when it is the same as its reverse. def is_symmetrical(num): t=str(num) return t==t[::-1] print(is_symmetrical(7227) ) #➞ True print(is_symmetrical(125...
true
885a0a3ce15dbf2504dd24ce14552a4e245b3790
ravalrupalj/BrainTeasers
/Edabit/Big_Countries.py
1,652
4.53125
5
#Big Countries #A country can be said as being big if it is: #Big in terms of population. #Big in terms of area. #Add to the Country class so that it contains the attribute is_big. Set it to True if either criterea are met: #Population is greater than 250 million. #Area is larger than 3 million square km. #Also, crea...
true
a22a66ffd651519956fc0f1ea0eb087a4146e8dd
ravalrupalj/BrainTeasers
/Edabit/Loves_Me_Loves_Me.py
1,034
4.25
4
#Loves Me, Loves Me Not... #"Loves me, loves me not" is a traditional game in which a person plucks off all the petals of a flower one by one, saying the phrase "Loves me" and "Loves me not" when determining whether the one that they love, loves them back. #Given a number of petals, return a string which repeats the p...
true
13b3a8a4d538ca1404902f5cc9d0d4cb5380f231
ravalrupalj/BrainTeasers
/Edabit/sum_of_even_numbers.py
698
4.1875
4
#Give Me the Even Numbers #Create a function that takes two parameters (start, stop), and returns the sum of all even numbers in the range. #sum_even_nums_in_range(10, 20) ➞ 90 # 10, 12, 14, 16, 18, 20 #sum_even_nums_in_range(51, 150) ➞ 5050 #sum_even_nums_in_range(63, 97) ➞ 1360 #Remember that the start and stop value...
true
7801a9735e3d51e4399ee8297d719d86eb44bc58
ravalrupalj/BrainTeasers
/Edabit/Recursion_Array_Sum.py
440
4.15625
4
#Recursion: Array Sum #Write a function that finds the sum of a list. Make your function recursive. #Return 0 for an empty list. #Check the Resources tab for info on recursion. def sum_recursively(lst): if len(lst)==0: return 0 return lst[0]+sum_recursively(lst[1:]) print(sum_recursively([1, 2, 3, 4])...
true
207c144e096524b8de5e6d9ca11ce5cb4969d8e1
ravalrupalj/BrainTeasers
/Edabit/Letters_Only.py
496
4.25
4
#Letters Only #Write a function that removes any non-letters from a string, returning a well-known film title. #See the Resources section for more information on Python string methods. def letters_only(string): l=[] for i in string: if i.isupper() or i.islower(): l.append(i) return ''.jo...
true
4fad5f1ab4362dbc1119d1f72a85d6c91abdfa8f
ravalrupalj/BrainTeasers
/Edabit/The_Fibonacci.py
368
4.3125
4
#The Fibonacci Number #Create a function that, given a number, returns the corresponding Fibonacci number. #The first number in the sequence starts at 1 (not 0). def fibonacci(num): a=0 b=1 for i in range(1,num+1): c=a+b a=b b=c return c print(fibonacci(3) ) #➞ 3 print(fibonac...
true
5182829f043490134cb86a3962b07a791e7ae0cb
ravalrupalj/BrainTeasers
/Edabit/How_many.py
601
4.15625
4
#How Many "Prime Numbers" Are There? #Create a function that finds how many prime numbers there are, up to the given integer. def prime_numbers(num): count=0 i=1 while num: i=i+1 for j in range(2,i+1): if j>num: return count elif i%j==0 and i!=j: ...
true
f07bfd91788707f608a580b702f3905be2bf201b
ravalrupalj/BrainTeasers
/Edabit/One_Button_Messagin.py
650
4.28125
4
# One Button Messaging Device # Imagine a messaging device with only one button. For the letter A, you press the button one time, for E, you press it five times, for G, it's pressed seven times, etc, etc. # Write a function that takes a string (the message) and returns the total number of times the button is pressed. #...
true
d9acdd4825dfd641d4eac7dd92d15b428b0e07f0
ravalrupalj/BrainTeasers
/Edabit/Iterated_Square_Root.py
597
4.5
4
#Iterated Square Root #The iterated square root of a number is the number of times the square root function must be applied to bring the number strictly under 2. #Given an integer, return its iterated square root. Return "invalid" if it is negative. #Idea for iterated square root by Richard Spence. import math def i_sq...
true
edb6aaff5ead34484d01799aef3df830208b574c
ravalrupalj/BrainTeasers
/Edabit/Identical Characters.py
460
4.125
4
#Check if a String Contains only Identical Characters #Write a function that returns True if all characters in a string are identical and False otherwise. #Examples #is_identical("aaaaaa") ➞ True #is_identical("aabaaa") ➞ False #is_identical("ccccca") ➞ False #is_identical("kk") ➞ True def is_identical(s): return ...
true
da002bf4a8ece0c60f4103e5cbc92f641d27f573
ravalrupalj/BrainTeasers
/Edabit/Stand_in_line.py
674
4.21875
4
#Write a function that takes a list and a number as arguments. Add the number to the end of the list, then remove the first element of the list. The function should then return the updated list. #For an empty list input, return: "No list has been selected" def next_in_line(lst, num): if len(lst)>0: t=lst.po...
true
b5255591c5a67f15767deee268a1972ca61497cd
ravalrupalj/BrainTeasers
/Edabit/Emphasise_the_Words.py
617
4.21875
4
#Emphasise the Words #The challenge is to recreate the functionality of the title() method into a function called emphasise(). The title() method capitalises the first letter of every word. #You won't run into any issues when dealing with numbers in strings. #Please don't use the title() method directly :( def emphasis...
true
6eceebf49b976ec2b757eee0c7907f2845c65afd
ravalrupalj/BrainTeasers
/Edabit/Is_String_Order.py
405
4.25
4
#Is the String in Order? #Create a function that takes a string and returns True or False, depending on whether the characters are in order or not. #You don't have to handle empty strings. def is_in_order(txt): t=''.join(sorted(txt)) return t==txt print(is_in_order("abc")) #➞ True print(is_in_order("edabit")) #...
true
56bf743185fc87230c9cb8d0199232d393757809
ravalrupalj/BrainTeasers
/Edabit/Day 2.5.py
793
4.53125
5
#He tells you that if you multiply the height for the square of the radius and multiply the result for the mathematical constant π (Pi), you will obtain the total volume of the pizza. Implement a function that returns the volume of the pizza as a whole number, rounding it to the nearest integer (and rounding up for num...
true
d9d1a7dbd41fea7d00f7299ae6708fc46e21d42d
ravalrupalj/BrainTeasers
/Edabit/Day 4.4.py
510
4.46875
4
#Is It a Triangle? #Create a function that takes three numbers as arguments and returns True if it's a triangle and False if not. #is_triangle(2, 3, 4) ➞ True #is_triangle(3, 4, 5) ➞ True #is_triangle(4, 3, 8) ➞ False #Notes #a, b and, c are the side lengths of the triangles. #Test input will always be three positive n...
true
a055bcd166678d801d9f2467347d9dfcd0e49254
ravalrupalj/BrainTeasers
/Edabit/Count_and_Identify.py
832
4.25
4
#Count and Identify Data Types #Given a function that accepts unlimited arguments, check and count how many data types are in those arguments. Finally return the total in a list. #List order is: #[int, str, bool, list, tuple, dictionary] def count_datatypes(*args): lst=[type(i) for i in args] return [lst.count...
true
fde94a7ba52fa1663a992ac28467e42cda866a9b
ravalrupalj/BrainTeasers
/Edabit/Lexicorgraphically First_last.py
762
4.15625
4
#Lexicographically First and Last #Write a function that returns the lexicographically first and lexicographically last rearrangements of a string. Output the results in the following manner: #first_and_last(string) ➞ [first, last] #Lexicographically first: the permutation of the string that would appear first in the E...
true
5c503edd8d4241b5e674e0f88b5c0edbe0888235
ravalrupalj/BrainTeasers
/Edabit/Explosion_Intensity.py
1,312
4.3125
4
#Explosion Intensity #Given an number, return a string of the word "Boom", which varies in the following ways: #The string should include n number of "o"s, unless n is below 2 (in that case, return "boom"). #If n is evenly divisible by 2, add an exclamation mark to the end. #If n is evenly divisible by 5, return the s...
true
bc123a73adc60347bc2e8195581e6d556b27c329
ravalrupalj/BrainTeasers
/Edabit/Check_if_an_array.py
869
4.28125
4
#Check if an array is sorted and rotated #Given a list of distinct integers, create a function that checks if the list is sorted and rotated clockwise. If so, return "YES"; otherwise return "NO". def check(lst): posi = sorted(lst) for i in range(0,len(lst)-1): first=posi.pop(0) posi.append(firs...
true
a3b5f7ffe220bd211b6fde53c99b9bcb086dbf39
ravalrupalj/BrainTeasers
/Edabit/Reverse_the_odd.py
656
4.4375
4
#Reverse the Odd Length Words #Given a string, reverse all the words which have odd length. The even length words are not changed. def reverse_odd(string): new_lst=string.split() s='' for i in new_lst: if len(i)%2!=0: t=i[::-1] s=s+t+' ' else: s=s+i+' ' ...
true
8124f901f1650f94c89bdae1eaf3f837925effde
ravalrupalj/BrainTeasers
/Edabit/Balancing_Scales.py
944
4.5
4
#Balancing Scales #Given a list with an odd number of elements, return whether the scale will tip "left" or "right" based on the sum of the numbers. The scale will tip on the direction of the largest total. If both sides are equal, return "balanced". #The middle element will always be "I" so you can just ignore it. #As...
true
d183ee49cc90ee2ede5a0d6383404edd9f08a4a8
nicolaespinu/LightHouse_Python
/spinic/Day14.py
1,572
4.15625
4
# Challenge # Dot's neighbour said that he only likes wine from Stellenbosch, Bordeaux, and the Okanagan Valley, # and that the sulfates can't be that high. The problem is, Dot can't really afford to spend tons # of money on the wine. Dot's conditions for searching for wine are: # # Sulfates cannot be higher than 0.6. ...
true
3a419523fb1fc6bbef5cf3da4ad3d07cc3d77b34
PranavDev/Sorting-Techniques
/RadixSort.py
803
4.15625
4
# Implementing Radix Sort using Python # Date: 01/04/2021 # Author: Pranav H. Deo import numpy as np def RadixSort(L, ord): Reloader_List = [] temp = [] for i in range(0, 10): Reloader_List.append([]) for i in range(0, ord): print('Iteration ', i, ' : ', L) for ele in L: ...
false
dc34b77a678caff2ce7b611f21ed210d55321225
humanwings/learngit
/python/coroutine/testCoroutine_01.py
894
4.25
4
''' 协程(Coroutine)测试 - 生产者和消费者模型 ''' def consumer(): r = '' # print('*' * 10, '1', '*' * 10) while True: # print('*' * 10, '2', '*' * 10) n = yield r if not n: # print('*' * 10, '3', '*' * 10) return # print('[CONSUMER] Consuming %s...' % n) ...
false
afdf0666b5d24b145a7fee65bf489fd01c4baa8c
OaklandPeters/til
/til/python/copy_semantics.py
1,348
4.21875
4
# Copy Semantics # ------------------------- # Copy vs deep-copy, and what they do # In short: copy is a pointer, and deep-copy is an entirely seperate data structure. # BUT.... this behavior is inconsistent, because of the way that attribute # setters work in Python. # Thus, mutations of attributes is not shared...
true
761768971347ca71abb29fcbbaccf6ef92d4df86
Varobinson/python101
/tip-calculator.py
998
4.28125
4
#Prompt the user for two things: #The total bill amount #The level of service, which can be one of the following: # good, fair, or bad #Calculate the tip amount and the total amount(bill amount + tip amount). # The tip percentage based on the level of service is based on: #good -> 20% #fair -> 15% # bad -> 10% try: ...
true
94bdd2d96de22c8911e7c22e46405558785fc25e
chhikara0007/intro-to-programming
/s2-code-your-own-quiz/my_code.py
1,211
4.46875
4
# Investigating adding and appending to lists # If you run the following four lines of codes, what are list1 and list2? list1 = [1,2,3,4] list2 = [1,2,3,4] list1 = list1 + [5] list2.append(5) # to check, you can print them out using the print statements below. print list1 print list2 # What is the difference betw...
true
592e186d9725f23f98eaf990116de6c572757063
Lobo2008/LeetCode
/581_Shortest_Unsorted_ContinuousSubarray.py
1,749
4.25
4
""" Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find the shortest such subarray and output its length. Example 1: Input: [2, 6, 4, 8, 10, 9, 15] Output: 5 Explanation:...
true
eff175292e48ca133ae5ca276a679821ebae0712
soumilshah1995/Data-Structure-and-Algorithm-and-Meta-class
/DataStructure/Deque/DEQChallenge.py
1,505
4.15625
4
""" DEQUE Abstract Data Type DEQUE = Double ended Queue High level its combination of stack and queue you can insert item from front and back You can remove items from front and back we can use a list for this example. we will use methods >----- addfront >----- add rear >----- remove front >----- remove rear we...
true
5d37cc5141b7f47ec6991ffa4800055fef50eab8
soumilshah1995/Data-Structure-and-Algorithm-and-Meta-class
/DataStructure/Queue/Queue.py
786
4.125
4
class Queue(object): def __init__(self): self.item = [] def enqueue(self, item): self.item.insert(0, item) def dequeue(self): if self.item: self.item.pop() else: return None def peek(self): if self.item: return self.item[-1...
false
c4765e62289e7318c56271e9f27942544b572842
Oldby141/learning
/day6/继承.py
1,397
4.375
4
#!_*_coding:utf-8_*_ # class People:#经典类 class People(object):#新式类写法 Object 是基类 def __init__(self,name,age): self.name = name self.age = age self.friends = [] print("Run in People") def eat(self): print("%s is eating...."%self.name) def talk(self): print("...
false
f1b55b29f5091414848893f10f636c509ce57ce7
WU731642061/LeetCode-Exercise
/python/code_189.py
1,986
4.375
4
#!/usr/bin/env python3 """ link: https://leetcode-cn.com/problems/rotate-array/ 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 """ def rotate1(nums, k): """ 第一种思路是利用数组拼接,向右移动N位其实就是将[-n:]位数组拼接到[:-n]数组的前面 需要注意的是k可能会大于数组本身的长度,那么每移动len(nums)位,数组与原数组重合, 所以只需要计算 k % len(nums)后需要移动的结果 """ length = len(nums) ...
false
56b78459da8cd4ca3b2bc16de38822105f02c82c
WU731642061/LeetCode-Exercise
/python/code_234.py
2,578
4.15625
4
#!/usr/bin/env python3 """ link: https://leetcode-cn.com/problems/palindrome-linked-list/ 请判断一个链表是否为回文链表。 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶: 你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题? """ # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # ...
false
2b803b5c53b0fc9cc03049f7b8eb61f39d38125d
thSheen/pythonaz
/Basic/Variables.py
479
4.125
4
greeting = "Hello" Greeting = "World" _NAME = "Thiago" Thiago34 = "What" t123 = "Wonderful" print(greeting + ' ' + _NAME) print(Greeting + ' ' + Thiago34 + ' ' + t123) a = 12 b = 3 print(a + b) print(a - b) print(a * b) print(a / b) print(a // b) # // to whole numbers, it's important use it to prevent future errors ...
false
b777cc4d1682a6a3c1e5a450c282062c4a0514da
jrobind/python-playground
/games/guessing_game.py
755
4.21875
4
# Random number CLI game - to run, input a number to CLI, and a random number between # zero and the one provided will be generated. The user must guess the correct number. import random base_num = raw_input('Please input a number: ') def get_guess(base_num, repeat): if (repeat == True): return raw_input(...
true
e88333ce7bd95d7fb73a07247079ae4f5cb12d11
graciofilipe/differential_equations
/udacity_cs222/final_problems/geo_stat_orb.py
2,907
4.375
4
# PROBLEM 3 # # A rocket orbits the earth at an altitude of 200 km, not firing its engine. When # it crosses the negative part of the x-axis for the first time, it turns on its # engine to increase its speed by the amount given in the variable called boost and # then releases a satellite. This satellite will ascend t...
true
ddc0bf0fdf77f46bf646a5ee2654d391e031647d
rojiani/algorithms-in-python
/dynamic-programming/fibonacci/fib_top_down_c.py
978
4.21875
4
""" Fibonacci dynamic programming - top-down (memoization) approach Using Python's 'memo' decorator Other ways to implement memoization in Python: see Mastering Object-Oriented Python, p. 150 (lru_cache) """ def fibonacci(n): # driver return fib(n, {}) def fib(n, memo= {}): if n == 0 or n == 1: ...
false
75c14cfafe64264b72186017643b6c3b3dacb42f
Malak-Abdallah/Intro_to_python
/main.py
866
4.3125
4
# comments are written in this way! # codes written here are solutions for solving problems from Hacker Rank. # ------------------------------------------- # Jenan Queen if __name__ == '__main__': print("Hello there!! \nThis code to practise some basics in python. \n ") str = "Hello world" print(str[2:]) ...
true