blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
3b343e3551776f7ea952f039008577bdfc36ae9c
ewertonews/learning_python
/inputs.py
222
4.15625
4
name = input("What is your name?\n") age = input("How old are you?\n") live_in = input("Where do you live?\n") string = "Hello {}! Good to know you are {} years old and live in {}" print(string.format(name, age, live_in))
true
9c3254d781dda926a1050b733044a62dd1325ec7
kevinsu628/study-note
/leetcode-notes/easy/array/27_remove_element.py
2,103
4.1875
4
''' Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond th...
true
880f3286c2b5052bd5972a9803db32fd1581c68d
devilsaint99/Daily-coding-problem
/product_of_array_exceptSelf.py
680
4.3125
4
"""Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], ...
true
d997ee82822d758eddcedd6d47059bae5b7c7cac
akassharjun/basic-rsa-algorithm
/app.py
1,320
4.15625
4
# To create keys for RSA, one does the following steps: # 1. Picks (randomly) two large prime numbers and calls them p and q. # 2. Calculates their product and calls it n. # 3. Calculates the totient of n ; it is simply ( p −1)(q −1). # 4. Picks a random integer that is coprime to ) φ(n and calls this e. A simple way i...
true
5d6d8d557279b809dba055dc702c186c0a5abebd
carlson9/KocPython2020
/in-classMaterial/day4/exception.py
375
4.1875
4
raise Exception print("I raised an exception!") raise Exception('I raised an exception!') try: print(a) except NameError: print("oops name error") except: print("oops") finally: print("Yes! I did it!") for i in range(1,10): if i==5: print("I found five!") continue print("Here is five!") else: pr...
true
5dfd71362ded3403b553bc743fab89bab02e2d38
BluFox2003/RockPaperScissorsGame
/RockPaperScissors.py
1,684
4.28125
4
#This is a Rock Paper Scissors game :) import random def aiChoice(): #This function generates the computers choice of Rock, Paper or Scissors x = random.randint(0,2) if x == 0: choice = "rock" if x == 1: choice = "paper" if x == 2: choice = "scissors" return choice def gam...
true
690c1fc35fdd3444d8e27876d9acb99e471b296b
gridl/cracking-the-coding-interview-4th-ed
/chapter-1/1-8-rotated-substring.py
686
4.34375
4
# Assume you have a method isSubstring which checks if one # word is a substring of another. Given two strings, s1 and # s2, write code to check if s2 is a rotation of s1 using only # one call to isSubstring (i.e., "waterbottle" is a rotation of # "erbottlewat"). # # What is the minimum size of both strings? # ...
true
f4890c20a78d87556d0136d38d1a1a40ac18c087
AlbertGithubHome/Bella
/python/list_test.py
898
4.15625
4
#list test print() print('list test...') classmates = ['Michael','Bob', 'Tracy'] print('classmates =', classmates) print('len(classmates) =', len(classmates)) print('classmates[1] =', classmates[1]) print('classmates[-1] =', classmates[-1]) print(classmates.append('Alert'), classmates) print(classmates.insert(2,'...
true
4740f88aedeb28db6bfb615af36dfed7d76fda0f
vincent-kangzhou/LeetCode-Python
/380. Insert Delete GetRandom O(1).py
1,434
4.1875
4
import random class RandomizedSet(object): def __init__(self): """ Initialize your data structure here. """ self.valToIndex = dict() self.valList = list() def insert(self, val): """ Inserts a value to the set. Returns true if the set did not already cont...
true
b3b008d706062e0b068dd8287cfb101a7e268dd9
vincent-kangzhou/LeetCode-Python
/341. Flatten Nested List Iterator.py
2,132
4.21875
4
# """ # This is the interface that allows for creating nested lists. # You should not implement it, or speculate about its implementation # """ # class NestedInteger(object): # def isInteger(self): # """ # @return True if this NestedInteger holds a single integer, rather than a nested list. # :r...
true
eb36a1f18bb74176c9e5d3739f2a7b7353af4afe
bhavin-rb/Mathematics-1
/Multiplication_table_generator.py
655
4.6875
5
''' Multiplication generator table is cool. User can specify both the number and up to which multiple. For example user should to input that he/she wants to seea table listing of the first 15 multiples of 3. Because we want to print the multiplication table from 1 to m, we have a foor loop at (1) that iterates over ...
true
4bde10e50b2b57139aed6f6f74b915a0771062dd
Ayesha116/cisco-assignments
/assigment 5/fac1.py
869
4.6875
5
# Write a Python function to calculate the factorial of a number (a non-negative # integer). The function accepts the number as an argument. def fact(number): factorial = 1 for i in range(1,number+1): factorial = factorial*i print(factorial) fact(4) # ...
true
4801ff9cb5d83bd385b3f650a3ba808d7f3cf229
Ayesha116/cisco-assignments
/assigment 5/market6.py
670
4.34375
4
# Question: 6 # Suppose a customer is shopping in a market and you need to print all the items # which user bought from market. # Write a function which accepts the multiple arguments of user shopping list and # print all the items which user bought from market. # (Hint: Arbitrary Argument concept can make this ta...
true
d7f20fbdee7d28a99591ab6bc4d3baf14f4a1920
aarizag/Challenges
/LeetCode/Algorithms/longest_substring.py
747
4.1875
4
""" Given a string, find the length of the longest substring without repeating characters. """ """ Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. """ def lengthOfLongestSubstring(s: str) -> int: letter_locs = {} cur, best, from_ind = 0, 0, 0 ...
true
052bcd3e8b2293371303450d3281f56c98498521
harish-515/Python-Projects
/Tkinter/script1.py
1,203
4.375
4
from tkinter import * #GUI are generated using window & widgets window = Tk() """ def km_to_miles(): print(e1_value.get()) miles = float(e1_value.get())*1.6 t1.insert(END,miles) b1=Button(window,text="Execute",command=km_to_miles) # pack & grid are used to make these button to visible b1.grid(row=0,c...
true
51f27da75c6d55eeddacaa9cef05a3d1d97bb0db
r-fle/ccse2019
/level3.py
1,500
4.21875
4
#!/usr/bin/env python3 from pathlib import Path import string ANSWER = "dunno_yet" ########### # level 3 # ########### print("Welcome to Level 3.") print("Caeser cipher from a mysterious text file") print("---\n") """ There is text living in: files/mysterious.txt You've got to try and figure out what the secret mes...
true
59b53e13a6f8bb9d2d606de898fc92738e5bd10b
imyoungmin/cs8-s20
/W3/p6.py
692
4.125
4
''' Write a program which takes 5 strings as inputs and appends them to a list l. Swap each element in l with its mirror - that is, for some element at index i, swap l[i] with l[4-i] if i < 3. For instance, if l = ['Alex', 'Bob', 'Charlie', 'David', 'Ethan'], then after swapping, l should read ['Ethan', 'David', 'Char...
true
c46fc22351db7e3fdafadde09aea6ae45b7c6789
rajatthosar/Algorithms
/Sorting/qs.py
1,682
4.125
4
def swap(lIdx, rIdx): """ :param lIdx: Left Index :param rIdx: Right Index :return: nothing """ temp = array[lIdx] array[lIdx] = array[rIdx] array[rIdx] = temp def partition(array, firstIdx, lastIdx): """ :param array: array being partitioned :param firstIdx: head of the...
true
68fc5fd6c86607595d5eb547218c7a55781f3389
manjulive89/JanuaryDailyCode2021
/DailyCode01092021.py
1,381
4.5625
5
# ------------------------------------------- # Daily Code 01/09/2021 # "Functions" Lesson from learnpython.org # Coded by: Banehowl # ------------------------------------------- # Functions are a convenient way to divide your code into useful blocks, allowing order in the code, make it # more readable, reu...
true
9d1b835fd8b5e6aeadb4ff23d54c2bc0b5435b2f
manjulive89/JanuaryDailyCode2021
/DailyCode01202021.py
1,831
4.3125
4
# ----------------------------------------------- # Daily Code 01/20/2021 # "Serialization" Lesson from learnpython.org # Coded by: Banehowl # ----------------------------------------------- # Python provides built-in JSON libraries to encode and decode JSON # Python 2.5, the simplejson module is used, wher...
true
5cac576e1c3b2e1ecd67bfd71ab20bc765b4eee3
jtm192087/Assignment_8
/ps1.py
960
4.46875
4
#!/usr/bin/python3 #program for adding parity bit and parity check def check(string): #function to check for a valid string p=set(string) s={'0','1'} if s==p or p=={'0'} or p=={'1'}: print("It is a valid string") else: print("please enter again a valid binary string") if __name__ == "_main...
true
578f3caf2d4247460b9331ae8f8b2a9cc56a4a74
EgorVyhodcev/Laboratornaya4
/PyCharm/individual.py
291
4.375
4
print("This program computes the volume and the area of the side surface of the Rectangular parallelepiped") a, b, c = input("Enter the length of 3 sides").split() a = int(a) b = int(b) c = int(c) print("The volume is ", a * b * c) print("The area of the side surface is ", 2 * c * (a + b))
true
2531327f966f606597577132fa9e54f7ed0be407
Rotondwatshipota1/workproject
/mypackage/recursion.py
930
4.1875
4
def sum_array(array): for i in array: return sum(array) def fibonacci(n): '''' this funtion returns the nth fibonacci number Args: int n the nth position of the sequence returns the number in the nth index of the fibonacci sequence '''' if n <= 1: return n else: ...
true
338f94f012e3c673777b265662403e5ef05a5366
alyssaevans/Intro-to-Programming
/Problem2-HW3.py
757
4.3125
4
#Author: Alyssa Evans #File: AlyssaEvans-p2HW3.py #Hwk #: 3 - Magic Dates month = int(input("Enter a month (MM): ")) if (month > 12) or (month < 0): print ("Months can only be from 01 to 12.") day = int(input("Enter a day (DD): ")) if (month % 2 == 0) and (day > 30) or (day < 0): print("Incorrect amount of d...
true
3b0f3bd8d100765ae7cb593a791c9f2908b1ce76
rossvalera/inf1340_2015_asst2
/exercise1.py
2,159
4.1875
4
#!/usr/bin/env python """ Assignment 2, Exercise 1, INF1340, Fall, 2015. Pig Latin This module converts English words to Pig Latin words """ __author__ = 'Sinisa Savic', 'Marcos Armstrong', 'Susan Sim' __email__ = "ses@drsusansim.org" __copyright__ = "2015 Susan Sim" __license__ = "MIT License" def pig_latinify(w...
true
a00293978a88a612e4b7a3ea532d334f43a279d5
CooperMetts/comp110-21f-workspace
/sandbox/dictionaries.py
1,329
4.53125
5
"""Demonstrations of dictonary capabilities.""" # Declaring the type of a dictionary schools: dict[str, int] # Intialize to an empty dictonary schools = dict() # set a key value pairing in the dictionary schools["UNC"] = 19400 schools["Duke"] = 6717 schools["NCSU"] = 26150 # Print a dictonary literal representati...
true
590cab46ee48d2e7380fd4025683f4321d9a1a34
dipak-pawar131199/pythonlabAssignment
/Introduction/SetA/Simple calculator.py
642
4.1875
4
# Program to make simple calculator num1=int(input("Enter first number: ")) num2=int(input("Enter second number: ")) ch=input(" Enter for opration symbol addition (+),substraction (-),substraction (*),substraction (/), % (get remainder) and for exit enter '$' ") if ch=='+': print("Sum is : ",num1+num2) ...
true
86c83cf3af2c57cc3250540ec848a3d5924b6d4b
dipak-pawar131199/pythonlabAssignment
/Functions/Sumdigit.py
691
4.15625
4
(""" 1) Write a function that performs the sum of every element in the given number unless it comes to be a single digit. Example 12345 = 6 """) def Calsum(num): c=0;sum=0 while num>0: # loop for calcuating sum of digits of a number lastdigit=num%10 sum+=lastdigit ...
true
df13a154e79b15d5a9b58e510c72513f8f8e2fa0
dipak-pawar131199/pythonlabAssignment
/Conditional Construct And Looping/SetB/Fibonacci.py
550
4.1875
4
'''4) Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: a. 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... b. By considering the terms in the Fibonacci sequence whose values do not exceed four hundred, find the sum of the even-valued t...
true
10e021531d1b56e1375e898e7599422de0ce5c9a
RobStepanyan/OOP
/Random Exercises/ex5.py
776
4.15625
4
''' An iterator ''' class Iterator: def __init__(self, start, end, step=1): self.index = start self.start = start self.end = end self.step = step def __iter__(self): # __iter__ is called before __next__ once print(self) # <__main__.Iterator object at 0x0000014...
true
9de5002aa797d635547bb7ca1989a435d4a97256
altvec/lpthw
/ex32_1.py
571
4.46875
4
the_count = [1, 2, 3, 4, 5] fruits = ['apples', 'oranges', 'pears', 'apricots'] change = [1, 'pennies', 2, 'dimes', 3, 'quarters'] # this first kind of for-loop goes through a list for number in the_count: print "This is count {0}".format(number) # same as above for fruit in fruits: print "A fruit of type: {0...
true
b8e6af4affac0d2ae50f36296cc55f52c6b44af3
PacktPublishing/Software-Architecture-with-Python
/Chapter04/defaultdict_example.py
1,374
4.1875
4
# Code Listing #7 """ Examples of using defaultdict """ from collections import defaultdict counts = {} text="""Python is an interpreted language. Python is an object-oriented language. Python is easy to learn. Python is an open source language. """ word="Python" # Implementations with simple dictionary for word ...
true
97b15762af24ba6fb59fc4f11320e99ffcec6cf4
rxxxxxxb/PracticeOnRepeat
/Python Statement/practice1.py
540
4.125
4
# Use for, .split(), and if to create a Statement that will print out words that start with 's' st = 'Print only the words that start with s in this sentence' for word in st.split(): if word[0] == 's': print(word) # even number using range li = list(range(1,15,2)) print(li) #List comprehension to ...
true
70c96ccdda8fec43e4dc2d85ba761bae2c4de876
heyimbarathy/py_is_easy_assignments
/pirple_functions.py
978
4.15625
4
# ----------------------------------------------------------------------------------- # HOMEWORK #2: FUNCTIONS # ----------------------------------------------------------------------------------- '''create 3 functions (with the same name as those attributes), which should return the corresponding value for the attrib...
true
910185af5c3818d848aa569d6e57de868c9cb790
heyimbarathy/py_is_easy_assignments
/pirple_lists.py
1,311
4.15625
4
# ----------------------------------------------------------------------------------- # HOMEWORK #4: LISTS # ----------------------------------------------------------------------------------- '''Create a function that allows you to add things to a list. Anything that's passed to this function should get added to myUni...
true
5045f39041869fd81a8c406159a1bec39e4b7372
abdelilah-web/games
/Game.py
2,707
4.15625
4
class Game: ## Constractor for the main game def __init__(self): print('Welcome to our Games') print('choose a game : ') print('press [1] to play the Even-odd game') print('Press [2] to play the Average game') print('Press [3] to play the Multiplication') self.ch...
true
b9b5e983017845ef38400a7d8ad8c9e35333d405
bghoang/coding-challenge-me
/leetcode/Other (not caterogize yet)/maxProductThreeNumbers.py
1,411
4.25
4
''' Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: Input: [1,2,3] Output: 6 Example 2: Input: [1,2,3,4] Output: 24 ''' ''' First solution: O(nlogn) runtime/ O(logn) space caus of sortings Sort the array, Find the product of the last 3 numbers Find the...
true
17756e03f8022ead554e7ec67add12ea22a45cb5
lj015625/CodeSnippet
/src/main/python/stack/minMaxStack.py
1,932
4.125
4
""" Write a class for Min Max Stack. Pushing and Popping value from the stack; Peeking value at top of the stack; Getting both minimum and maximum value in the stack at any time. """ from collections import deque class MinMaxStack: def __init__(self): # doubly linked list deque is more efficient to imple...
true
f2e670471bfa9bcac1e5f983ecdb0240eeaaf1f2
lj015625/CodeSnippet
/src/main/python/array/sumOfTwoNum.py
1,598
4.125
4
"""Given an array and a target integer, write a function sum_pair_indices that returns the indices of two integers in the array that add up to the target integer if not found such just return empty list. Note: even though there could be many solutions, only one needs to be returned.""" def sum_pair_indices(array, targ...
true
153468d2ee32d18c1fe7cd6ee705d0f2e38c6ac2
lj015625/CodeSnippet
/src/main/python/string/anagram.py
626
4.28125
4
"""Given two strings, write a function to return True if the strings are anagrams of each other and False if they are not. A word is not an anagram of itself. """ def is_anagram(string1, string2): if string1 == string2 or len(string1) != len(string2): return False string1_list = sorted(string1) str...
true
ce33d6bb0f0db42a8a0b28543f1ea6895da0d00c
lj015625/CodeSnippet
/src/main/python/tree/binarySearch.py
1,055
4.1875
4
def binary_search_iterative(array, target): if not array: return -1 left = 0 right = len(array)-1 while left <= right: mid = (left + right) // 2 # found the target if array[mid] == target: return mid # if target is in first half then search from the st...
true
0ecfc8d40c1d7eba616676d03f04bb9bf187dc09
xamuel98/The-internship
/aliceAndBob.py
414
4.4375
4
# Prompt user to enter a string username = str(input("Enter your username, username should be alice or bob: ")) ''' Convert the username to lowercase letters and compare if the what the user entered correlates with accepted string ''' if username.lower() == "alice" or username.lower() == "bob": pr...
true
ed4ebe2d41a2da81d843004f32223f0662e59053
ParulProgrammingHub/assignment-1-kheniparth1998
/prog10.py
308
4.125
4
principle=input("enter principle amount : ") time=input("enter time in years : ") rate=input("enter the interest rate per year in percentage : ") def simple_interest(principle,time,rate): s=(principle*rate*time)/100 return s print "simple interest is : ",simple_interest(principle,rate,time)
true
8e73474a9ac03600fee353f5f64259dae9840592
Sachey-25/TimeMachine
/Python_variables.py
1,234
4.21875
4
#Practice : Python Variables #Tool : Pycharm Community Edition #Platform : WINDOWS 10 #Author : Sachin A #Script starts here '''Greet'='This is a variable statement' print(Greet)''' #Commentning in python # -- Single line comment #''' ''' or """ """ multiline comment print('We are learning python script...
true
1e8e3b23f03923e87e1910f676cda91e93bc02c8
skyesyesyo/AllDojo
/python/typelist.py
929
4.25
4
#input one = ['magical unicorns',19,'hello',98.98,'world'] #output "The array you entered is of mixed type" "String: magical unicorns hello world" "Sum: 117.98" # input two = [2,3,1,7,4,12] #output "The array you entered is of integer type" "Sum: 29" # input three = ['magical','unicorns'] #output "The array you enter...
true
584c4e36f9801a63fd17adae4c750647d0afeec8
linth/learn-python
/class/specificMethod-3.py
606
4.3125
4
''' specific method - __str__() and __repr__() - __repr__() magic method returns a printable representation of the object. - The __str__() magic method returns the string Reference: - https://www.geeksforgeeks.org/python-__repr__-magic-method/?ref=rp ''' class GFG: def __init__(self, name): ...
true
a7ab0d16e3266d89e3119cfe59447d30062a9140
kelly4strength/intCakes
/intCake3.py
2,264
4.40625
4
# Given a list_of_ints, # find the highest_product you can get from three of the integers. # The input list_of_ints will always have at least three integers. # find max, pop, add popped to a new list_of_ints # add those ints bam! # lst = [11,9,4,7,13, 21, 55, 17] # returns [55, 21, 17] # 93 # lst = [0, 9, 7] # retu...
true
d0434e4c42c139b85ec28c175749bb189d2a19bf
Francisco-LT/trybe-exercices
/bloco36/dia2/reverse.py
377
4.25
4
# def reverse(list): # reversed_list = [] # for item in list: # reversed_list.insert(0, item) # print(reversed_list) # return reversed_list def reverse(list): if len(list) < 2: return list else: print(f"list{list[1:]}, {list[0]}") return reverse(list[1:]) + ...
true
d2d8f309a900c4642f0e7c66b3d33e26cabaf4e9
synaplasticity/py_kata
/ProductOfFibNumbers/product_fib_num.py
597
4.34375
4
def fibonacci(number): if number == 0 or number == 1: return number*number else: return fibonacci(number - 1) + fibonacci(number - 2) def product_fib_num(product): """ Returns a list of the two consecutive fibonacci numbers that give the provided product and a boolean indcating if ...
true
1687b77c4b2d3c44b6871e653a974153db7d3f96
ntuthukojr/holbertonschool-higher_level_programming-6
/0x07-python-test_driven_development/0-add_integer.py
578
4.125
4
#!/usr/bin/python3 """Add integer module.""" def add_integer(a, b=98): """ Add integer function. @a: integer or float to be added. @b: integer or float to be added (default set to 98). Returns the result of the sum. """ if not isinstance(a, int) and not isinstance(a, float): raise...
true
53bf0300d334909355777fa043e37beb823bd7d2
NixonRosario/Encryption-and-Decryption
/main.py
2,772
4.1875
4
# This is a sample Python script. # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. # The Encryption Function def cipher_encrypt(plain_text, key): # key is used has an swifting value encrypted...
true
29d0f0a5b83dbbcee5f053a2455f9c8722b6cb51
MrYsLab/pseudo-microbit
/neopixel.py
2,943
4.21875
4
""" The neopixel module lets you use Neopixel (WS2812) individually addressable RGB LED strips with the Microbit. Note to use the neopixel module, you need to import it separately with: import neopixel Note From our tests, the Microbit Neopixel module can drive up to around 256 Neopixels. Anything above that and yo...
true
638715d691110084c104bba50daefd5675aea398
baif666/ROSALIND_problem
/find_all_substring.py
501
4.25
4
def find_all(string, substr): '''Find all the indexs of substring in string.''' #Initialize start index i = -1 #Creat a empty list to store result result = [] while True: i = string.find(substr, i+1) if i < 0: break result.append(i) return result ...
true
b0cad0b1e60d45bc598647fa74cb1c584f23eeaa
JGMEYER/py-traffic-sim
/src/physics/pathing.py
1,939
4.1875
4
from abc import ABC, abstractmethod from typing import Tuple import numpy as np class Trajectory(ABC): @abstractmethod def move(self, max_move_dist) -> (Tuple[float, float], float): """Move the point along the trajectory towards its target by the specified distance. If the point woul...
true
d45df8bc1090aee92d3b02bb4e1d42fc93c402a0
dheerajkjha/PythonBasics_Udemy
/programmingchallenge_addition_whileloop.py
285
4.25
4
number = int(input("Please enter an Integer number.")) number_sum = 0 print("Entered number by the user is: " + str(number)) while number > 0: number_sum = number_sum + number number = number - 1 print("Sum of the numbers from the entered number and 1 is: " + str(number_sum))
true
e96f81fc4967ca2dbb9993097f2653632b08a613
dheerajkjha/PythonBasics_Udemy
/programmingchallenge_numberofcharacters_forloop.py
258
4.34375
4
user_string = input("Please enter a String.") number_of_characters = 0 for letter in user_string: number_of_characters = number_of_characters + 1 print(user_string) print("The number of characters in the input string is: " + str(number_of_characters))
true
5e865b5a2ac4f087c4fe118e0423ef05908a4a09
reedless/dailyinterviewpro_answers
/2019_08/daily_question_20190827.py
528
4.5
4
''' You are given an array of integers. Return the largest product that can be made by multiplying any 3 integers in the array. Example: [-4, -4, 2, 8] should return 128 as the largest product can be made by multiplying -4 * -4 * 8 = 128. ''' def maximum_product_of_three(lst): lst.sort() cand1 =...
true
5e9bb62185611666f43897fd2033bae28d91ee18
reedless/dailyinterviewpro_answers
/2019_08/daily_question_20190830.py
806
4.21875
4
''' Implement a queue class using two stacks. A queue is a data structure that supports the FIFO protocol (First in = first out). Your class should support the enqueue and dequeue methods like a standard queue. ''' class Queue: def __init__(self): self.head = [] self.stack = [] def ...
true
f1d328556b13e5d99c75d43cd750585184d9d9fa
deltahedge1/decorators
/decorators2.py
1,008
4.28125
4
import functools #decorator with no arguments def my_decorator(func): @functools.wraps(func) def function_that_runs_func(*args, **kwargs): #need to add args and kwargs print("in the decorator") func(*args, **kwargs) #this is the original function, dont forget to add args and kwargs pri...
true
0ac3a65fea58acea5bc8ae4b1bbf9a4fb45b9f87
Hilamatu/cse210-student-nim
/nim/game/board.py
1,548
4.25
4
import random class Board: """A board is defined as a designated playing surface. The responsibility of Board is to keep track of the pieces in play. Stereotype: Information Holder Attributes: """ def __init__(self): self._piles_list = [] self._prepare() ...
true
686e53872c553c6dedc03dac6cf19806cc10b19e
NenadPantelic/Cracking-the-coding-Interview
/LinkedList/Partition.py
1,985
4.375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Mar 3 16:45:16 2020 @author: nenad """ """ Partition: Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only nee...
true
886195fb51ac965a88f3ad3c3d505548638cc6bd
JadsyHB/holbertonschool-python
/0x06-python-classes/102-square.py
2,010
4.59375
5
#!/usr/bin/python3 """ Module 102-square Defines Square class with private attribute, size validation and area accessible with setters and getters comparison with other squares """ class Square: """ class Square definition Args: size: size of side of square, default size is 0 Functions: ...
true
55ffa8c32622c42f6d3a314018a0adaf0e1c0d18
JadsyHB/holbertonschool-python
/0x06-python-classes/1-square.py
373
4.125
4
#!/usr/bin/python3 """ Module 1-square class Square defined with private attribute size """ class Square: """ class Square Args: size: size of a side in a square """ def __init__(self, size): """ Initialization of square Attributes: size: size of a sid...
true
96384a26d49430e18697d080c49f3341e7b13834
23o847519/Python-Crash-Course-2nd-edition
/chapter_08/tryityourself814.py
874
4.4375
4
# 8-14. Cars: Write a function that stores information about # a car in a dictionary. The function should always receive # a manufacturer and a model name. It should then accept an # arbitrary number of keyword arguments. Call the function # with the required information and two other name-value # pairs, such as a colo...
true
e0f7b4c472500360a03266df6e35031cd4534dc4
23o847519/Python-Crash-Course-2nd-edition
/chapter_07/tryityourself7.1.py
334
4.15625
4
# Ex 7.1 Rental Car # Write a program that asks the user what kind of rental car they # would like. Print a message about that car, such as # “Let me see if I can find you a Subaru.” print("\nEx 7.1") rental_car = input("What kind of rental car would you like?\n") print(f"\nLet me see if I can find you a {rental_car.t...
true
9cca96cb78e6ae2772c76f81ccf6a2106ee0ac99
23o847519/Python-Crash-Course-2nd-edition
/chapter_03/cars.py
604
4.28125
4
#Sorting print("\nSorting") cars = ['bmw', 'audi', 'toyota', 'subaru'] print(cars) cars.sort() print(cars) #Reverse sorting print("\nReverse sorting") cars.sort(reverse=True) print(cars) #Sort tạm thời print("\n Sorted()") cars = ['bmw', 'audi', 'toyota', 'subaru'] print("Original list:") print(cars) print("\nSorted...
true
44f55bae68ae6fa0fddd6628dea0c92e1f0d81fe
23o847519/Python-Crash-Course-2nd-edition
/chapter_10/tryityourself106.py
726
4.3125
4
# 10-6. Addition: One common problem when prompting for numerical input # occurs when people provide text instead of numbers. When you try to # convert the input to an int, you’ll get a ValueError. Write a program # that prompts for two numbers. Add them together and print the result. # Catch the ValueError if either i...
true
6ba1d02a2025378d11c0cfbf8a11055e0593e3ca
radishmouse/06-2017-cohort-python
/104/n_to_m.py
629
4.375
4
n = int(raw_input("Start from: ")) m = int(raw_input("End on: ")) # Let's use a while loop. # Every while loop requires three parts: # - the while keyword # - the condition that stops the loop # - a body of code that moves closer to the "stop condition" # our loop counts up to a value. # let's declare a counter vari...
true
50cbb178c40d42e83aed3f936feef223eca8a865
radishmouse/06-2017-cohort-python
/dictionaries/dictionary1.py
534
4.21875
4
phonebook_dict = { 'Alice': '703-493-1834', 'Bob': '857-384-1234', 'Elizabeth': '484-584-2923' } #Print Elizabeth's phone number. print phonebook_dict['Elizabeth'] #Add a entry to the dictionary: Kareem's number is 938-489-1234. phonebook_dict['Kareem'] = '938-489-1234' #Delete Alice's phone entry. del phoneb...
true
6ebffaee162c491cc4f2289845a1bf7bbcd33604
flub78/python-tutorial
/examples/conditions.py
374
4.1875
4
#!/usr/bin/python # -*- coding:utf8 -* print ("Basic conditional instructions\n") def even(a): if ((a % 2) == 0): print (a, "is even") if (a == 0): print (a, " == 0") return True else: print (a, "is odd") return False even(5) even(6) even(0) bln = even(6) ...
true
0e531d7c0b4da023818f02265ab9e009420eaec6
flub78/python-tutorial
/examples/test_random.py
1,395
4.1875
4
#!/usr/bin/python # -*- coding:utf8 -* """ How to use unittest execution: python test_random.py or python -m unittest discover """ import random import unittest class RandomTest(unittest.TestCase): """ Test case for random """ def test_choice(self): """ given: a list ...
true
38081fd73316e20f6361d835d710dd379e8c78ea
andremmfaria/exercises-coronapython
/chapter_06/chapter_6_6_4.py
823
4.375
4
# 6-4. Glossary 2: Now that you know how to loop through a dictionary, clean up the code from Exercise 6-3 (page 102) by replacing your series of print statements with ía loop that runs through the dictionary’s keys and values. When you’re sure that your loop works, add five more Python terms to your glossary. When you...
true
8c5498b935164c457447729c6de1553b390664e5
andremmfaria/exercises-coronapython
/chapter_06/chapter_6_6_8.py
522
4.34375
4
# 6-8. Pets: Make several dictionaries, where the name of each dictionary is the name of a pet. In each dictionary, include the kind of animal and the owner’s name. Store these dictionaries in a list called pets. Next, loop through your list and as you do print everything you know about each pet. pet_0 = { 'kind' ...
true
7bc98b1c9a50acb1e7ff7fe3ce2781ace3a56eb8
andremmfaria/exercises-coronapython
/chapter_07/chapter_7_7_1.py
257
4.21875
4
# 7-1. Rental Car: Write a program that asks the user what kind of rental car they would like. Print a message about that car, such as “Let me see if I can find you a Subaru.” message = input("Let me see whether I can find you a Subaru") print(message)
true
5cb4a583ec8a49434d41500e142cb79879070d1a
mkccyro-7/Monday_test
/IF.py
226
4.15625
4
bis = int(input("enter number of biscuits ")) if bis == 3: print("Not eaten") elif 0 < bis < 3: print("partly eaten") elif bis == 0: print("fully eaten") else: print("Enter 3 or any other number less than 3")
true
4ccb729ebdb80510424aa920666f6b4f0acb5a2a
ErenEla/PythonSearchEngine
/Unit_1/Unit1_Hw3.py
1,060
4.1875
4
# IMPORTANT BEFORE SUBMITTING: # You should only have one print command in your function # Given a variable, x, that stores the # value of any decimal number, write Python # code that prints out the nearest whole # number to x. # If x is exactly half way between two # whole numbers, round up, so # 3.5 rounds to ...
true
4ed0dc77c6784f2006ca437568f80a73a8d51438
ErenEla/PythonSearchEngine
/Unit_3/Unit3_Quiz1.py
504
4.15625
4
# Define a procedure, replace_spy, # that takes as its input a list of # three numbers, and modifies the # value of the third element in the # input list to be one more than its # previous value. spy = [1,2,2] def replace_spy(x): x[0] = x[0] x[1] = x[1] x[2] = x[2]+1 return x # In the test below, ...
true
66c4d00e9ce49d8570cd7a703d04aef1b6b4d3f6
iSabbuGiri/Control-Structures-Python-
/qs_17.py
962
4.21875
4
#Python program that serves as a basic calculator def add(x,y): return x+y def subtract(x,y): return x-y def multiply(x,y): return x*y def divide(x,y): return x/y print("Select operation:") print("1.Add") print("2.Subtract") print("3.Multiply") print("4.Divide") while True: choice = input...
true
3ba2ea80dcc916bf8e245a2ab518042b9ee55e3e
richardrcw/python
/guess.py
270
4.1875
4
import random highest = 10 num = random.randint(1, highest) guess = -1 while guess != num: guess = int(input("Guess number between 1 and {}: ".format(highest))) if guess > num: print("Lower...") elif guess < num: print("Higher....") else: print("Got it!")
true
efabcf8f6f413c833a75c8cc5e57e556c2d12823
prathamarora10/guessingNumber
/GuessingNumber.py
561
4.21875
4
print('Number Guessing Game') print('Guess a Number (between 1 and 9):') import random number = random.randint(1,9) print(number) for i in range(0,5,1): userInput = int(input('Enter your Guess :- ')) if userInput < 3: print('Your guess was too low: Guess a number higher than 3') elif userInput < 5...
true
39cebe0780b8532517dadf4fd04517b9ba79f207
Carterhuang/sql-transpiler
/util.py
922
4.375
4
def standardize_keyword(token): """ In returned result, all keywords are in upper case.""" return token.upper() def join_tokens(lst, token): """ While joining each element in 'lst' with token, we want to make sure each word is separated with space. """ _token = token.strip(' ') if ...
true
8c9890c843a63d8b2fa90098b28594ba1e012d99
justinhohner/python_basics
/datatypes.py
1,042
4.34375
4
#!/usr/local/bin/python3 # https://www.tutorialsteacher.com/python/python-data-types # """ Numeric Integer: Positive or negative whole numbers (without a fractional part) Float: Any real number with a floating point representation in which a fractional component is denoted by a decimal symbol or scientifi...
true
9acddfa9dc609fbb3aad91d19c4348dda1aee239
jsanon01/100-days-of-python
/resources/day4/area_circumference_circle.py
427
4.59375
5
""" Fill out the functions to calculate the area and circumference of a circle. Print the result to the user. """ import math def area(r): return math.pi * r ** 2 def circumference(r): return math.pi * 2 * r radius = float(input("Circle radius: ")) circle_area = area(radius) circle_circumference = circu...
true
e2ca488af3efc7e4d8f5bc72be4ac0a3f139edd9
saumyatiwari/Algorithm-of-the-day
/api/FirstAPI.py
790
4.125
4
import flask app=flask.Flask(__name__) #function name is app # use to create the flask app and intilize it @app.route("/", methods =['GET']) #Defining route and calling methods. GET will be in caps intalized as an arrya # if giving the giving any configuration then function name will proceed with @ else it will use n...
true
1544a910a16011cc302ba6bcb449c0c8887c05ee
msvrk/frequency_dict
/build/lib/frequency_dict/frequency_dict_from_collection.py
557
4.53125
5
def frequency_dict_from_collection(collection): """ This is a useful function to convert a collection of items into a dictionary depicting the frequency of each of the items. :param collection: Takes a collection of items as input :return: dict """ assert len(collection) > 0, "Cannot perform the ope...
true
660a467f0428f2564fdeec4da7f5dc171b7a2e65
DivijeshVarma/CoreySchafer
/Decorators2.py
2,922
4.46875
4
# first class functions allow us to treat functions like any other # object, for example we can pass functions as arguments to another # function, we can return functions and we can assign functions to # variable. Closures-- it will take advantage of first class functions # and return inner function that remembers and ...
true
b1ebc3eeeceebdf1eb6760c88d00be6b40d9e5cd
DivijeshVarma/CoreySchafer
/generators.py
809
4.28125
4
def square_nums(nums): result = [] for i in nums: result.append(i * i) return result sq_nums = square_nums([1, 2, 3, 4, 5]) print(sq_nums) # square_nums function returns list , we could convert # this to generator, we no longer get list # Generators don't hold entire result in memory # it yield ...
true
e328a29edf17fdeed4d8e6c620fc258d9ad28890
DivijeshVarma/CoreySchafer
/FirstclassFunctions.py
1,438
4.34375
4
# First class functions allow us to treat functions like # any other object, i.e we can pass functions as argument # to another function and returns functions, assign functions # to variables. def square(x): return x * x f1 = square(5) # we assigned function to variable f = square print(f) print(f(5)) print(f1) ...
true
4f9c1ddb562de274a644e6d41e73d70195929274
sairamprogramming/learn_python
/book4/chapter_1/display_output.py
279
4.125
4
# Program demonstrates print statement in python to display output. print("Learning Python is fun and enjoy it.") a = 2 print("The value of a is", a) # Using keyword arguments in python. print(1, 2, 3, 4) print(1, 2, 3, 4, sep='+') print(1, 2, 3, 4, sep='+', end='%') print()
true
64c62c53556f38d9783de543225b11be87304daf
sairamprogramming/learn_python
/pluralsight/core_python_getting_started/modularity/words.py
1,204
4.5625
5
# Program to read a txt file from internet and put the words in string format # into a list. # Getting the url from the command line. """Retrive and print words from a URL. Usage: python3 words.py <url> """ import sys def fetch_words(url): """Fetch a list of words from a URL. Args: url: The...
true
99bd7e715f504ce64452c252ac93a026f426554d
gotdang/edabit-exercises
/python/factorial_iterative.py
414
4.375
4
""" Return the Factorial Create a function that takes an integer and returns the factorial of that integer. That is, the integer multiplied by all positive lower integers. Examples: factorial(3) ➞ 6 factorial(5) ➞ 120 factorial(13) ➞ 6227020800 Notes: Assume all inputs are greater than or equal to 0. """ def facto...
true
30d9fe50769150b3efcaa2a1628ef9c7c05984fa
gotdang/edabit-exercises
/python/index_multiplier.py
428
4.125
4
""" Index Multiplier Return the sum of all items in a list, where each item is multiplied by its index (zero-based). For empty lists, return 0. Examples: index_multiplier([1, 2, 3, 4, 5]) ➞ 40 # (1*0 + 2*1 + 3*2 + 4*3 + 5*4) index_multiplier([-3, 0, 8, -6]) ➞ -2 # (-3*0 + 0*1 + 8*2 + -6*3) Notes All items in the lis...
true
36f7db179bcc0339c7969dfa9f588dcd51c6d904
adarshsree11/basic_algorithms
/sorting algorithms/heap_sort.py
1,200
4.21875
4
def heapify(the_list, length, i): largest = i # considering as root left = 2*i+1 # index of left child right = 2*i+2 # index of right child #see if left child exist and greater than root if left<length and the_list[i]<the_list[left]: largest = left #see if right child exist and greater than root if rig...
true
88bf240c30c8373b3779a459698223ec3cb74e24
mliu31/codeinplace
/assn2/khansole_academy.py
836
4.1875
4
""" File: khansole_academy.py ------------------------- Add your comments here. """ import random def main(): num_correct = 0 while num_correct != 3: num1 = random.randint(10,99) num2 = random.randint(10,99) sum = num1 + num2 answer = int(input("what is " + str(num1) + " + " +...
true
346d3af90d21411c4265d7e232786fc4078f82fc
Tanay-Gupta/Hacktoberfest2021
/python_notes1.py
829
4.4375
4
print("hello world") #for single line comment '''for multi line comment''' #for printing a string of more than 1 line print('''Twinkle, twinkle, little star How I wonder what you are Up above the world so high Like a diamond in the sky Twinkle, twinkle little star How I wonder what you are''') a=20 b...
true
f284bdf3b3929131be1fe943b3bd5761119f4c2e
sydney0zq/opencourses
/byr-mooc-spider/week4-scrapy/yield.py
1,088
4.53125
5
#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ The first time the for calls the generator object created from your function, it will run the code in your function from the beginning until it hits yield, then it'll return the first value of the loop. Then, each other call will run the loop you have written in the ...
true
88806f1c3ee74fe801b26a11b0f66a3c7d6c881d
Kajabukama/bootcamp-01
/shape.py
1,518
4.125
4
# super class Shape which in herits an object # the class is not implemented class Shape(object): def paint(self, canvas): pass # class canvas which in herits an object # the class is not implemented class Canvas(object): def __init__(self, width, height): self.width = width self.heigh...
true
157b4ad717a84f91e60fb5dc108bcab8b2a21a12
jwu424/Leetcode
/RotateArray.py
1,275
4.125
4
# Given an array, rotate the array to the right by k steps, where k is non-negative. # 1. Make sure k < len(nums). We can use slice but need extra space. # Time complexity: O(n). Space: O(n) # 2. Each time pop the last one and inset it into the beginning of the list. # Time complexity: O(n^2) # 3. Reverse the list t...
true
da8890ff1f941e97b8174bc6e111272b6ffa0b20
OliverMorgans/PythonPracticeFiles
/Calculator.py
756
4.25
4
#returns the sum of num1 and num 2 def add(num1, num2): return num1 + num2 def divide(num1, num2): return num1 / num2 def multiply(num1, num2): return num1 * num2 def minus (num1, num2): return num1 - num2 #*,-,/ def main(): operation = input("what do you want to do? (+-*/): ") if(operation != "+" and opera...
true
261a8ec6e763de736e722338241d2cf39a34c9b0
Rggod/codewars
/Roman Numerals Decoder-6/decoder.py
1,140
4.28125
4
'''Problem: Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the left...
true