blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
76e2f2d3c49bdf893496282eb9dc1a08b0826bee
aggies99/Lego-Mindstorms
/ms4/multitask/iteratorstudy/study2.py
2,144
4.4375
4
#!/usr/bin/python import random print("study2 - stand-alone iterator") # This class creates a random permutation (of size `num`). # The object is iterable; it has a stand-alone iterator. # Advantage: can have two iterators at the same time, disadvantage: extra class class Perm : def __init__(self,num) : ...
true
932a9de16a89dd0222fd70e35a44be4bff47a302
anjana24-r/projects
/abc/functional programming/demo.py
1,779
4.1875
4
#functional programming #used to reduce length of a code #they are:- #1.lambda functon #2.map fn #3.filter #4.list comprehension #.... #1.lambda function #..... #they are anonymous fn(nameless fn) # # def add(n1,n2): # return n1+n2 # print(add(10,30)) #use lambda fn # # f=lambda n1,n2 :n1+n2 # print(f(1,2)...
true
31fdfc3fd7ca164453ce9281decfa042d059546c
aliciawyy/sheep
/notes/iterator.py
1,229
4.1875
4
""" # Iterable vs Iterator vs Generator - s is an iterable whose method __iter__ instantiates a new iterator every time. - t is an iterator for whom the method __iter__ returns self ## Generator Any Python function that has the `yield` keyword in its body is a generator function, which, when called, returns a genera...
true
c6c401260547cb1695540d33cc385c6b14d03324
jeffcore/algorithms-udacity
/P2/problem_1.py
1,934
4.53125
5
""" Finding the Square Root of an Integer Find the square root of the integer without using any Python library. You have to find the floor value of the square root. For example if the given number is 16, then the answer would be 4. If the given number is 27, the answer would be 5 because sqrt(5) = 5.196 whose floor ...
true
441378f7b9f3a7ae741c8c13570f2bdf64fa447e
jeffcore/algorithms-udacity
/P2/problem_4.py
1,991
4.28125
4
""" Dutch National Flag Problem Given an input array consisting on only 0, 1, and 2, sort the array in a single traversal. You're not allowed to use any sorting function that Python provides. Note: O(n) does not necessarily mean single-traversal. For e.g. if you traverse the array twice, that would still be an O(n...
true
e2228b4580103d45835671159deb80f758a11971
lisu1222/Leetcode
/isPalindrome.py
239
4.21875
4
#Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. def isPalindrome(x): if x <0: return False else: if x == int(str(x)[::-1]): return True else: return False
true
3e496c9eec959b6fef4c84a094583c0b95193563
kgalloway2/Project-Euler-stuff
/Exercises 1-20/ex20.py
1,017
4.21875
4
# this loads the argv modules from sys from sys import argv # this defines our argv inputs script, input_file = argv # this defines the print_all function to just print the entire file def print_all(f): print f.read() # this defines the rewind function which takes the text file back to the beginning def rewind(f...
true
7b7740be47dc7cec49f5b53a7129d000e13fc165
waterFlowin/Python-Projects
/Bike.py
681
4.1875
4
class Bike(object): def __init__(self, price, max_speed, miles = 0): self.price = price self.max_speed = max_speed self.miles = miles def displayInfo(self): print self.price print self.max_speed print self.miles def ride(self): print "Riding" self.miles += 10 return self def reverse(self): pr...
true
6dfd06ab46e309218004e0f930e4383be9a3ba63
michaelFavre/cloudio-endpoint-python
/src/cloudio/interface/uuid.py
1,522
4.1875
4
# -*- coding: utf-8 -*- from abc import ABCMeta, abstractmethod class Uuid(object): """Interface to represent an object as a uuid (Universally Unique Identifier). An object implementing the UniqueIdentifiable interface has to return an object implementing the Uuid interface as return value of the method ...
true
5860016638f2b63075bcdae494cd83f1e521539e
moshekagan/Computational_Thinking_Programming
/frontal_exersices/recitation_solutions_2/ex2.py
442
4.40625
4
number = int(input("Insert a 3 digits number: ")) first_digit = number // 100 second_digit = number // 10 % 10 third_digit = number % 10 is_middle_greater = second_digit > first_digit and second_digit > third_digit is_middle_smaller = second_digit < first_digit and second_digit < third_digit if is_middle_greater or ...
true
783326ccec31dc7a0ff46c5e4b69806e99aeda57
chrislockard/toyprograms
/CourseraPython/guessnumber.py
2,709
4.25
4
# template for "Guess the number" mini-project # input will come from buttons and an input field # all output for the game will be printed in the console import simplegui import random import math # initialize global variables used in your code range = 100 guesses_made = 0 guesses_remaining = 0 highest_guess = 0 lowes...
true
bea639c7d5f0989b60dcbb827e5dabd9397bcb57
01Eddie/holbertonschool-higher_level_programming
/0x06-python-classes/3-square.py
720
4.625
5
#!/usr/bin/python3 """ define or write class Square""" class Square: """Define the variable or attribute in the principal method""" def __init__(self, size=0): """if type of size if is integer""" if type(size) is not int: """print the error""" raise TypeError("size must...
true
7646debb97f133e988015a558fbaadf8e61f6678
Abhyudaya100/my-projects
/averageusingvarsrgs.py
413
4.40625
4
#program to calculate average of list of values using function def average(arg1, *values): total = arg1 for value in values: total += value return total / (len(values) + 1) def convert(value): return float(value) if value.find(".")!=-1 else int(value) list1 = [convert(element) for el...
true
4426d57f4acd4316c14aa28eb40631ffe5aab3e3
calvinhaensel/HuffmanEncoding
/priorityqueue.py
2,968
4.25
4
import linkedlist class PriorityQueue: def __init__(self): self.items = linkedlist.LinkedList() def enqueue(self, item, priority): ''' Enqueues the item, a, on the queue, q; complexity O(1). ''' cursor = self.items crsr = cursor.front crsrnew = crsr crsrnxt ...
true
e8ea3f836cfbaff29f01f95610f65cf6310730ee
ParisGharbi/Wave-1
/even or odd.py
286
4.625
5
#Determine and display whether an integer entered by the user is even or odd #Read integer from user num = int(input("Enter an integer: ")) #Determine whether it is even or odd by using the remainder operator if num % 2 == 1: print(num, "is odd.") else: print(num, "is even.")
true
2012c701ecd374474f04345bfd49b248dbd57af5
Rahonam/algorithm-syllabus
/array/duplicate_numbers.py
1,417
4.34375
4
def duplicate_numbers(arr: list): """ Find duplicates in the given array using: iteration, map, time O(n) space O(n) Args: arr: array of integers Returns: array: the duplicate numbers """ number_map = {} duplicate_numbers = [] for i in arr: if i in num...
true
759d066d88dc0c693bfb24ee643a2722656fcd6b
Rahonam/algorithm-syllabus
/array/rearrange_array.py
854
4.34375
4
def rearrange_array(arr:list): """ Rearrange the array such that A[i]=i if A[i] exists, otherwise -1 using: iteration, time O(n) space O(1) Args: arr: array of integers Returns: array: the rearranged array """ for i in range(0, len(arr) - 1): if arr[i] != -1 a...
true
c45452604287a2e6f68da9734d696b41a58a0491
Rahonam/algorithm-syllabus
/array/count_given_sum_pairs.py
958
4.1875
4
def sum_pairs(arr: list, sum: int): """ Count the number of pairs with a given sum using: iteration, dictionary Args: arr: array of integers sum: target sum of pairs Returns: int: count of possible pairs """ pair_count = 0 count_map = {} for i in arr: ...
true
ea164553afee5cc5928fa5eabd2434ca7936ddef
Rahonam/algorithm-syllabus
/array/two_missing_numbers.py
990
4.1875
4
from functools import reduce import math def two_missing_numbers(arr:list): """ Find two missing numbers from unsorted consecutive numbers using: iteration/sum, sum property time O(n) Args: arr: array of unsorted consecutive numbers Returns: array: two missing numbers from g...
true
9c465c534adac3189d79af4157e35a689cd74971
shirbrosh/Intro-Python-ex10
/asteroid.py
2,159
4.5
4
class Asteroid: TEN = 10 FIVE = 5 def __init__(self, x, y, v_x, v_y, size): """ A constructor for a Asteroid object :param x: A int representing the asteroid's location on the axis x :param y: A int representing the asteroid's location on the axis y :param v...
true
d1f3d1d85558e82a98670e52964f390e0e683213
acemodou/dev
/algorithms/bubbleSort.py
621
4.46875
4
""" objective sort the array in increasing order 1. Scan the array and compare A[i] and A[i + 1] 2. If index is out of order we swap 3. Time complexity is O(n^2) since we are comparing everything 4. Space complexity is O(n) """ def swap(a, b): temp = a a = b b = temp def bubbleSort(arr): for i...
true
11c38bc9dd67fc8148edd675dee31a6eb44c057f
acemodou/dev
/geeksforgeeks/algorithmDataStructure/fibonacci.py
1,008
4.40625
4
"""1 1 2 3 5 8 13 The sum of the previous two values At the end of the nth month, the number of pairs of rabbits is equal to the number of new pairs (which is the number of pairs in month n - 2) plus the number of pairs alive last month (n - 1). This is the nth Fibonacci number. This is the Fibonacci sequence in math...
true
0f5f9dd6cfc082f3d00a4f0457b8cc4413032507
ussherk03/Py
/times_table.py
704
4.625
5
# The multiplication times_table_generator generates a list of the multiples of a particular number, x. # By default, x = 0. def times_table_generator(x=0): a = [] # Null list collects all multiples after being generated by the for-loop n = 0 # Initialises the loop: [n = 0 + x, n = (0 + x) + x, n = ...
true
de0485501843230bdc5590ef6129aa9eb4c7c220
shawnstaggs/Fibonacci-Generator
/Fibonacci Generator/Fibonacci_Generator.py
841
4.375
4
# The generator that produces the fibonacci sequence def genfibon(n): a = 0 # Beginning seed of the sequence b = 1 # First number after the seed for i in range(n): yield a # The output from the generator. is the sum of the previous iteration + the current number a,b = b,a+b # Sets a to the n...
true
2e7e1ce6a5bf98cccc4ddd5fc0b7807d92894b8e
wrosko/EXDS
/Week 3/sortingAlgorithms.py
2,482
4.21875
4
''' File: sortingAlgorithms Author: CS 1510 Description: This file gives sample implementations for three sorting algorithms discussed in class: bubble sort, insertion sort, and selection sort. All of these sorting algorithms are big Oh value of n squared ''' # Some lists to play with ordered = [1, 2, 3, 4, 5, 6, 7, ...
true
5819d0197de9de3223c959a338c3b1ba5a6f8076
iamrobinhood12345/data-structures
/src/queue_ds.py
1,877
4.25
4
"""This module defines Queue Data Structure. A Queue works based on the FIFO principle which is based in accounting and it describes the method of the first item/person/inventory to enter something to also be the first to leave it. An example would be a line in a bank where the first customer in the line will be the ...
true
950acf32e9e72977f6f1b771fb2dea9f846c69ff
SofiaSmile/LeetCode
/src/7_ReverseInteger.py
1,008
4.15625
4
""" 7. Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,...
true
ea874d59a2b74ef1c024c9f8cccd1c920f797bfa
Fuerfenf/Basic_things_of_the_Python_language
/python_operators/bitwise_operators.py
1,001
4.40625
4
#-> & # Operator copies a bit to the result if it exists in both operands print(2 & 4) # return 0 (2=0b10, 4=0b100 -> 010 & 100 = 000 (0)) #-> | # It copies a bit if it exists in either operand. print(2 | 4) # return 6 (2=0b10, 4=0b100 -> 010 | 100 = 110 (6)) #-> ~ # It copies the bit if it is set in one operand but ...
true
ded5e9702956b2f0cfeba0e631b9b33385af7ecd
Fuerfenf/Basic_things_of_the_Python_language
/oop/encapsulation.py
1,256
4.4375
4
# Protected members -> , just follow the convention by prefixing the name of the member by a single underscore “_” class Base: def __init__(self): # Protected member self._a = 2 # Creating a derived class class Derived(Base): def __init__(self): # Calling constructor of # Base ...
true
a7310dae4012063b4fcfc1db01c540fa69df146c
jason-weirather/py-seq-tools
/seqtools/statistics/__init__.py
2,084
4.15625
4
"""This module contains many list-based functions to calculate descriptive statistics.""" from math import sqrt from collections import Counter def mode(arr): """get the most frequent value""" return max(set(arr),key=arr.count) def average(arr): """average of the values, must have more than 0 entries. :pa...
true
80cb6294c2502d384729234907a5f3890b8b2292
Notesong/Data-Structures
/stack/stack.py
1,477
4.15625
4
""" A stack is a data structure whose primary purpose is to store and return elements in Last In First Out order. 1. Implement the Stack class using an array as the underlying storage structure. Make sure the Stack tests pass. 2. Re-implement the Stack class, this time using the linked list implementation as th...
true
197c6da9ae620306ebcc64debe7f8845a17b0888
TomekPk/Python-Crash-Course
/Chapter 7/7.8.Deli/deli.py
731
4.28125
4
''' 7-8. Deli: Make a list called sandwich_orders and fill it with the names of various sandwiches. Then make an empty list called finished_sandwiches. Loop through the list of sandwich orders and print a message for each order, such as I made your tuna sandwich. As each sandwich is made, move it to the list of finishe...
true
75715f01c699c17f4c74e7c5665701c072cd2d6b
TomekPk/Python-Crash-Course
/Chapter 7/7.4.Pizza Toppings/pizza_toppings.py
562
4.1875
4
''' 7-4. Pizza Toppings: Write a loop that prompts the user to enter a series of pizza toppings until they enter a 'quit' value. As they enter each topping, print a message saying you’ll add that topping to their pizza. ''' Question = "\nWhat topping do you want add to your pizza?" Question += "\nPlease write topping ...
true
513234216a77a52c8039281b59652ec77243874f
TomekPk/Python-Crash-Course
/Chapter 6/6.3.Glossary/glossary.py
942
4.53125
5
''' 6-3. Glossary: A Python dictionary can be used to model an actual dictionary. However, to avoid confusion, let’s call it a glossary. • Think of five programming words you’ve learned about in the previous chapters. Use these words as the keys in your glossary, and store their meanings as values. • Print each word an...
true
006f9bc05ab8e04c7806b5c38e416a9277abcfbf
TomekPk/Python-Crash-Course
/Chapter 7/7.2.Restaurant Seating/restaurant_seating.py
475
4.5
4
''' 7-2. Restaurant Seating: Write a program that asks the user how many people are in their dinner group. If the answer is more than eight, print a message saying they’ll have to wait for a table. Otherwise, report that their table is ready. ''' Question = input("Hello. Welcome in our restaurant. How many people are ...
true
aef7ac0ea6992cef72ddbc904b0f9ef7bd974ee8
TomekPk/Python-Crash-Course
/Chapter 4/4.8.Cubes/cubes.py
563
4.65625
5
''' 4-8. Cubes: A number raised to the third power is called a cube. For example, the cube of 2 is written as 2**3 in Python. Make a list of the first 10 cubes (that is, the cube of each integer from 1 through 10), and use a for loop to print out the value of each cube. ''' numbers_list=list(range(1,11)) print(number...
true
80e88bc6cf202201e1c6800073b17bcb1e13bb84
TomekPk/Python-Crash-Course
/Chapter 4/4.10.Slices/slices.py
950
5
5
''' 4-10. Slices: Using one of the programs you wrote in this chapter, add several lines to the end of the program that do the following: 1)• Print the message, The first three items in the list are:. Then use a slice to print the first three items from that program’s list. 2)• Print the message, Three items from the m...
true
cd2ee8b63cde2545b7848e58b320c06fea840776
TomekPk/Python-Crash-Course
/Chapter 7/7.10.Dream Vacation/dream_vacation.py
757
4.28125
4
''' 7-10. Dream Vacation: Write a program that polls users about their dream vacation. Write a prompt similar to If you could visit one place in the world, where would you go? Include a block of code that prints the results of the poll. ''' question = "If you could visit one place in the world, where would you go?" qu...
true
3fa9a4e81c80bda5d1d50017a89a7f3c6c4a91c0
TomekPk/Python-Crash-Course
/Chapter 10/10.8.Cats and Dogs/cats_and_dogs.py
1,921
4.34375
4
''' 10-8. Cats and Dogs: Make two files, cats.txt and dogs.txt. Store at least three names of cats in the first file and three names of dogs in the second file. Write a program that tries to read these files and print the contents of the file to the screen. Wrap your code in a try-except block to catch the FileNotFound...
true
f741c0b9bb52fb597b2372f66ce9cf178b17aa97
TomekPk/Python-Crash-Course
/Chapter 10/10.1.Learning Python/learning_python.py
1,421
4.9375
5
''' 10-1. Learning Python: Open a blank file in your text editor and write a few lines summarizing what you’ve learned about Python so far. Start each line with the phrase In Python you can.... Save the file as learning_python.txt in the same directory as your exercises from this chapter. Write a program that reads the...
true
4e3dc30d2a53f5156fc62f51583820dfdf5aa30c
TomekPk/Python-Crash-Course
/Chapter 10/10.3.Guest/guest.py
615
4.34375
4
''' 10-3. Guest: Write a program that prompts the user for their name. When they respond, write their name to a file called guest.txt. ''' my_text = "guest.txt" name_message = input("Hello. Please enter Your name below: \n") class User(): def __init__(self,name_message): self.name_message = name_message ...
true
b4ebd5389f9b0193e83536ac499a2a1de6af0e90
shalinrox123/Spring-2021-Masters-Project
/top_sort.py
2,577
4.125
4
# This code is contributed by Neelam Yadav # Python program to print topological sorting of a DAG from collections import defaultdict # topolicical sort was implimented from from https://www.geeksforgeeks.org/topological-sorting/ # start of Neelam Yadev's code #Class to represent a graph class Graph: ...
true
54f12930cd86ef6f94123a70fe2df240ce069f0a
monaug5/Data-Science-Coursework-Aaron-Adeniran
/import Task 1.py
209
4.125
4
import random #Gathers the users name and asks the question "What is your name?" user_input = input("What is your name? ") number=random.randint(1,10) print(user_input, "Guess the number between 1 and 10")
true
cd145a5f7d57cc4ee9e039696bf126b4a413c530
deshunin/binder
/week 9-10/fibonacci.py
1,513
4.21875
4
# fibonacci numbers and memoization # standart regursion form (for n = 34 it takes 1.6 sec) def fibonacci(n): if n <= 2: return 1 return fibonacci(n-2) + fibonacci(n-1) # fastest so far mine form using list operations (for n = 34 it takes 43 microsec) def fib(n): fib_lst = [0,1] for k in range...
true
f684e9b9c718f255083759e2cb638d96db623c3e
praveenchs/LPTHW
/ex18.py
1,181
4.5625
5
#First we tell Python we want to make a function using def for ”define”. #On the same line as def we give the function a name called "print_two" #Then we tell it we want *args (asterisk args), which is a lot like your argv parameter but for #functions. This has to go inside () parentheses to work. def print_two(*args)...
true
d9deca92fd1d626938f077f93e617fb821c71996
IsaacLSK/python_simple_algo
/sorting/bulit_in_sort.py
589
4.15625
4
def built_in_sort(): # using the function sorted # the function returns the sorted list listA = [10, 5, 2, 8, 3, 4, 9, 1] newlist = sorted(listA) print(newlist) # using the function sorted # the function returns the sorted list listA = [10, 5, 2, 8, 3, 4, 9, 1] newlist = sorted(lis...
true
90597944fa6a087ee66dc343ed3f846b332390da
jaliagag/21_python
/pirple/08/second.py
2,601
4.21875
4
# Project #1: A Simple Game #Details: #Have you ever played "Connect 4"? It's a popular kid's game by the Hasbro company. In this project, your task is create a Connect 4 game in Python. Before you get started, please watch this video on the rules of Connect 4: #https://youtu.be/utXzIFEVPjA # Rules # 2 players 6 r...
true
46c442fc739b7e287d01a43d467013b5d92138c3
All3yp/Daily-Coding-Problem-Solutions
/Solutions/206.py
752
4.46875
4
""" Problem: A permutation can be specified by an array P, where P[i] represents the location of the element at i in the permutation. For example, [2, 1, 0] represents the permutation where elements at the index 0 and 2 are swapped. Given an array and a permutation, apply the permutation to the array. For example, gi...
true
4e89662b7935b081c2812eab1e621b3a1eae69b1
All3yp/Daily-Coding-Problem-Solutions
/Solutions/153.py
1,502
4.21875
4
""" Problem: Find an efficient algorithm to find the smallest distance (measured in number of words) between any two given words in a string. For example, given words "hello", and "world" and a text content of "dog cat hello cat dog dog hello cat world", return 1 because there's only one word "cat" in between the two...
true
936693bb7143edab3a6cd7e8768839cddf955f8b
All3yp/Daily-Coding-Problem-Solutions
/Solutions/103.py
1,969
4.125
4
""" Problem: Given a string and a set of characters, return the shortest substring containing all the characters in the set. For example, given the string "figehaeci" and the set of characters {a, e, i}, you should return "aeci". If there is no substring containing all the characters in the set, return null. """ fr...
true
a01b0ff284ec23054811211c269826e0d43221b4
All3yp/Daily-Coding-Problem-Solutions
/Solutions/056.py
1,066
4.125
4
""" Problem: Given an undirected graph represented as an adjacency matrix and an integer k, write a function to determine whether each vertex in the graph can be colored such that no two adjacent vertices share the same color using at most k colors. """ from typing import List def can_color(adjacency_matrix: List[L...
true
95f8ac695131eb49055717f7fa9704e45f9da577
All3yp/Daily-Coding-Problem-Solutions
/Solutions/027.py
1,289
4.21875
4
""" Problem: Given a string of round, curly, and square open and closing brackets, return whether the brackets are balanced (well-formed). For example, given the string "([])", you should return true. Given the string "([)]" or "((()", you should return false. """ from typing import Dict from DataStructures.Stack ...
true
b98e12ef4e9cd729ddaaac08d491330a0c1fe87a
All3yp/Daily-Coding-Problem-Solutions
/Solutions/129.py
785
4.1875
4
""" Problem: Given a real number n, find the square root of n. For example, given n = 9, return 3. """ TOLERENCE = 10 ** (-6) def almost_equal(num1: float, num2: float) -> bool: return num1 - TOLERENCE < num2 < num1 + TOLERENCE def get_sqrt(num: int) -> float: # using binary search to get the sqaure-root ...
true
8c93d2ab457003f16a47c40ca1058cdb06a61d6e
All3yp/Daily-Coding-Problem-Solutions
/Solutions/083.py
989
4.15625
4
""" Problem: Invert a binary tree. For example, given the following tree: a / \ b c / \ / d e f should become: a / \ c b \ / \ f e d """ from DataStructures.Tree import BinaryTree, Node def invert_helper(node: Node) -> None: node.right, node.left = node.left, node.right # recursi...
true
6c9b7bc41eb453dea54279f479e91d0415eb00cd
All3yp/Daily-Coding-Problem-Solutions
/Solutions/258.py
1,837
4.375
4
""" Problem: In Ancient Greece, it was common to write text with the first line going left to right, the second line going right to left, and continuing to go back and forth. This style was called "boustrophedon". Given a binary tree, write an algorithm to print the nodes in boustrophedon order. For example, given t...
true
b680d98973d1ae1bbce673b95533fa98ea0cbfa6
All3yp/Daily-Coding-Problem-Solutions
/Solutions/342.py
1,187
4.15625
4
""" Problem: reduce (also known as fold) is a function that takes in an array, a combining function, and an initial value and builds up a result by calling the combining function on each element of the array, left to right. For example, we can write sum() in terms of reduce: def add(a, b): return a + b def sum(l...
true
4ad27acf7b2b4ee7a28ccd5dd3f0dc77148dbb2b
All3yp/Daily-Coding-Problem-Solutions
/Solutions/191.py
1,208
4.1875
4
""" Problem: Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Intervals can "touch", such as [0, 1] and [1, 2], but they won't be considered overlapping. For example, given the intervals (7, 9), (2, 4), (5, 8), return 1 as the...
true
9a3698e9e19924e0ef4781ec89d9f0228ef4394c
All3yp/Daily-Coding-Problem-Solutions
/Solutions/349.py
2,032
4.21875
4
""" Problem: Soundex is an algorithm used to categorize phonetically, such that two names that sound alike but are spelled differently have the same representation. Soundex maps every name to a string consisting of one letter and three numbers, like M460. One version of the algorithm is as follows: Remove consecuti...
true
5ecbeed93255cb3c8d57aa53d05f2834d0a00aea
All3yp/Daily-Coding-Problem-Solutions
/Solutions/182.py
1,714
4.1875
4
""" Problem: A graph is minimally-connected if it is connected and there is no edge that can be removed while still leaving the graph connected. For example, any binary tree is minimally-connected. Given an undirected graph, check if the graph is minimally-connected. You can choose to represent the graph as either an...
true
f0800fbf4e22a4cff89344fe365e41e235a41b1d
All3yp/Daily-Coding-Problem-Solutions
/Solutions/123.py
2,587
4.1875
4
""" Problem: Given a string, return whether it represents a number. Here are the different kinds of numbers: "10", a positive integer "-10", a negative integer "10.1", a positive real number "-10.1", a negative real number "1e5", a number in scientific notation And here are examples of non-numbers: "a" "x 1" "a -2" ...
true
b27d136b1b597c64f89e1487080cb866f2160b07
All3yp/Daily-Coding-Problem-Solutions
/Solutions/177.py
971
4.21875
4
""" Problem: Given a linked list and a positive integer k, rotate the list to the right by k places. For example, given the linked list 7 -> 7 -> 3 -> 5 and k = 2, it should become 3 -> 5 -> 7 -> 7. Given the linked list 1 -> 2 -> 3 -> 4 -> 5 and k = 3, it should become 3 -> 4 -> 5 -> 1 -> 2. """ from DataStructure...
true
2eb04c62a087d65891257394bd67d25d7e7d50cb
All3yp/Daily-Coding-Problem-Solutions
/Solutions/234.py
1,783
4.125
4
""" Problem: Recall that the minimum spanning tree is the subset of edges of a tree that connect all its vertices with the smallest possible total edge weight. Given an undirected graph with weighted edges, compute the maximum weight spanning tree. """ from typing import Set from DataStructures.Graph import GraphUnd...
true
23777a53212dab0229f75bb35ddf2f64973c515a
All3yp/Daily-Coding-Problem-Solutions
/Solutions/096.py
1,081
4.25
4
""" Problem: Given a number in the form of a list of digits, return all possible permutations. For example, given [1,2,3], return [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]. """ from copy import deepcopy from typing import List, Optional def generate_all_permutations( arr: List[int], l: int = 0, r: Opti...
true
667cf6f76fd33d22a444047490d68124ae9a94cd
All3yp/Daily-Coding-Problem-Solutions
/Solutions/181.py
1,568
4.28125
4
""" Problem: Given a string, split it into as few strings as possible such that each string is a palindrome. For example, given the input string "racecarannakayak", return ["racecar", "anna", "kayak"]. Given the input string "abc", return ["a", "b", "c"]. """ from typing import List def is_palindrome(string: str)...
true
305b0b5717f0b2a43894e4d4f5b3af868947481f
All3yp/Daily-Coding-Problem-Solutions
/Solutions/108.py
480
4.15625
4
""" Problem: Given two strings A and B, return whether or not A can be shifted some number of times to get B. For example, if A is abcde and B is cdeab, return true. If A is abc and B is acb, return false. """ def can_shift(A: str, B: str) -> bool: return (A and B) and (len(A) == len(B)) and (B in A * 2) if _...
true
ed1d2b7d94c117c94668a2e544640ed66c3bfe43
xDhairyax/GuessingGame
/guessinggame.py
414
4.1875
4
import random chances=0 number=random.randint(1,10) while chances < 5: guess=int(input("Guess a Number between 1 and 10:")) if guess == number: print("YOU WIN!!") break elif guess > number: print("GUESS LOWER,TRY AGAIN") else: print("GUESS HIGHER,TRY AGAIN") ...
true
be3699af387e756b570c7ca0845471d5ddda01ac
prosales95/PythonInterm
/Comprehensions.py
1,171
4.4375
4
print('List comprehension Examples with multiples of 3 until 30') multiples = [i for i in range(30) if i % 3 == 0] print(multiples) print('Awesome the same applies for divisors if we just remember that range is') print('only considering from 1 until n-1, then we have to adjust limits') n = int(input('Divisors of n = ...
true
214d51b996f0ea1c707881d7e470f8697e03a71a
bolivaralejandro/py4e
/ex102.py
877
4.15625
4
# Exercise 2: This program counts the distribution of the hour of the day for each # of the messages. You can pull the hour from the “From” line by finding the time # string and then splitting that string into parts using the colon character. Once # you have accumulated the counts for each hour, print out the counts, o...
true
97ff069eb351b6699ff8359fe2a6d0240ee53353
ncapps/python-workout
/ch01_numeric_types/hexadecimal_output.py
235
4.1875
4
def hex_output(): decnum = 0 user_input = input("Enter a hex number to convert: ") for power, digit in enumerate(reversed(user_input)): decnum += int(digit, base=16) * (16 ** power) print(decnum) hex_output()
true
8bee369b096de5e0111d0ae398b5d7102e87b615
AceHW/LearningPython3
/guessing_game.py
826
4.28125
4
import random number_of_guesses = 4 user_won = False print("Welcome to the guessing game!") # Computer guesses a random number between 1 and 10 correct_answer = random.randint(1, 10) while number_of_guesses > 0: # User guesses the number user_guess = input("Guess my number: ") user_guess = int(user_guess) ...
true
be673d5726ab2addac1cf198fec4be9da96301f1
oscos/codewars
/python/factorial.py
1,071
4.34375
4
# https://www.codewars.com/kata/54ff0d1f355cfd20e60001fc def multiply(ls): prod = 1 for x in ls: prod *= x return prod def factorial(n): if n > 12 or n < 0: raise ValueError("Invalid Number") # ls = list(range(n + 1))[1:] ls = list(range(1, n + 1)) return multiply(ls) # Other user subm...
true
c356e338ff5db79ffa15aa157da311e9c504ec12
srihariprasad-r/workable-code
/Practice problems/foundation/recursion/printzigzagsequence.py
514
4.28125
4
""" Pre sequence is peformed while going up recursive stack In sequence is performed between left and right call Post sequence is performed while coming down recursive stack """ def printzigzagsequence(n): if n == 0: return print("pre sequence:", n) # pre-sequence printzigzagsequence(n-1) # ...
true
c95871a5975f3bdd05ff34cc4698252a8499d62e
srihariprasad-r/workable-code
/500_Practise Problems/arrange_get_largest_number.py
613
4.125
4
""" this function will arrange them in such way that the arrangement will form the largest value. Input = {3, 1, 13, 34, 8} Output = 8343131 """ def arrangeNumber(array): n = len(array) for i in range(n): for j in range(n): if str(array[i]) + str(array[j]) > str(array[j]) + str(array[i]): ...
true
a5341ff34dfd047fde4caa06f67612442ca47f43
SparshGautam/Lists
/Lists2.py
716
4.59375
5
digits = ("apple","microsoft","google","Tata") # assigning list to digits print(digits[-1]) # as +ve is opposite of-ve here -1 represents to get output from backside of our list here "Tata" will be printed print(digits[:3]) # here you can use co...
true
c3ddb968fab6d302986a4a373a54abfcfd153da1
starizwan/projects-python
/[mini-project]-guess-the-number-computer/guess-number-user.py
947
4.46875
4
# Computer will generate some random number and user has to guess it in 3 attempts # Computer should generate some hints on the range of number import random def guess(maximum): secret_number = random.randint(1, maximum) guessed_number = 0 max_guess_count = 3 guess_count = max_guess_count print(f...
true
e0e1366da7b0d30a305d7b917dcbb92b438f8ba0
WillDutcher/project-2-data-visualization
/exercises/cubes_colormap.py
765
4.125
4
""" A number raised to the third power is a cube. Plot the first five cubic numbers and then plot the first 5000 cubic numbers. """ import matplotlib.pyplot as plt # First 5000 x_values = range(1, 5001) y_values = [x**3 for x in x_values] plt.style.use('seaborn-deep') fig, ax = plt.subplots() ax.scatter...
true
b33dc48efd5c551bcd376554e99f6ca9bcbf96e7
iamreebika/Python-Assignment2
/Examples/4.py
585
4.25
4
""" 4. Create a list. Append the names of your colleagues and friends to it. Has the id of the list changed? Sort the list. What is the first item on the list? What is the second item on the list? """ names = [] inital_id = id(names) names.append('Tanu') names.append('Aruna') names.append('Kisa') id_after_append = id(...
true
dc53865bed03df415d3b9a21ce47eb711d2f7461
iamreebika/Python-Assignment2
/Examples/7.py
893
4.28125
4
""" 7. Create a list of tuples of first name, last name, and age for your friends and colleagues. If you don't know the age, put in None. Calculate the average age, skipping over any None values. Print out each name, followed by old or young if they are above or below the average age. """ from functools import reduce ...
true
3033dfa221491e4794c5b458811abd9e84e4f98a
Minu94/PythonWorkBook1
/python_oops/4.py
561
4.25
4
# Write a program to print the area of two rectangles having # sides (4,5) and (5,8) respectively by creating a class named # 'Rectangle' with a method named 'Area' which returns the area # and length and breadth passed as parameters to its constructor. class Rectangle: def __init__(self,atr_tuple): s...
true
ef4700af074c40d83ad2c914ec8c04c3c6e13a56
AragondaJyosna/chainladder-python
/docs/auto_examples/plot_triangle_from_pandas.py
1,643
4.1875
4
""" ======================= Basic Triangle Creation ======================= This example demonstrates the typical way you'd ingest data into a Triangle. Data in tabular form in a pandas DataFrame is required. At a minimum, columns specifying origin and development, and a value must be present. Note, you can include ...
true
5c4adfede4c268ae5d631bb1c432925c660a83ce
maelfosso/dailycodingproblem
/dcp537.py
1,255
4.15625
4
""" This is your coding interview problem for today. This problem was asked by Apple. A Collatz sequence in mathematics can be defined as follows. Starting with any positive integer: if n is even, the next number in the sequence is n / 2 if n is odd, the next number in the sequence is 3n + 1 It is conjectured that e...
true
047897d1046a53fa92955cdc850b0cc767f95af9
inotives/python-learnings
/common-data-structures/_2_array_data_structures.py
1,947
4.53125
5
#!/usr/bin/python ''' list - mutable dynamic arrays (can be added or removed ''' print('LIST EXAMPLE::') arr = ['one', 'two', 'three'] print(arr[0]) print(arr) print('list are mutable:') arr[1] = 'Changed' print(arr) del arr[1] print(arr) print("list can hold arbitrary data types:") arr.append(23) print(arr) ''' tu...
true
78347f1d003d3ef66daacebdef2e74c452c24539
inotives/python-learnings
/classes-and-oop/_4_cloning_objects.py
1,186
4.34375
4
#!/usr/bin/python ''' Shallow Copy ------- Constructing new collection of objects and then populating it with references to the child objects found in the original. This mean it is only 1-level deep which the copying process does not recurse and child objects copies wont be created. ''' xs = [[1,2,3], [4,5,6], [7,8,9...
true
6daa5d960fbe319b3faefd6159aa177dc2cfc34e
justin-crabtree/uni_mich_getting-started-python
/romeo_text_sort.py
591
4.1875
4
# Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and pri...
true
4b6cc71ac5978188c2d9c90227d9ef2da3586435
alecodigo/Python
/validateakey.py
1,447
4.15625
4
# -*- coding: utf-8 -*- import sys PASSWORD = '' def create_password(): global PASSWORD pwd = input("Enter your new password: ") confir_pwd = input("Confirm you password: ") if pwd == confir_pwd: print("Success") PASSWORD = confir_pwd else: print("Error in password try a...
true
3bfe8c3e58412724d29d594d153bc8240163f2be
mgalactico/substring
/substring.py
1,177
4.15625
4
# Prints longest substring in which letters appear in alphabetical order s = 'azcbobobegghakl' n = len(s) i = 1 currentString = '' largestString = s[i - 1] # initializes string to first char in string currentLetter = '' nextLetter = '' # Loop over length of s while i < n: currentLetter = s[i - 1] nextLetter =...
true
3b7039d8350ee851d294cb4b07e02df5db75a72d
MmeKelain/interview-solver
/overused-coding-questions/linked_list_cycle.py
1,582
4.21875
4
def overused_linked_list_cycle(linked_list): "" Returns true if a cycle exists, false otherwise. Arguments: linked_list -- a data structure that should never contain a cycle. Assume a linked_list is an object comprised of node objects, each containing a pointer to the next node called 'next'. "" ...
true
1c2b0e507fb4e431235ed56484b47743a26310e4
hdmcspadden/CS5010
/Module05/primes_fail1.py
1,154
4.5
4
# File: primes_fail1.py # CS 5010 # Learning Python (Python version: 3) # Topics: # - Unit testing / debugging code # - Using primes example # - **inserting errors to show how primes_test can fail** def is_prime(number): # Return True if *number* is prime #if number < 0: # Negative numbers are not ...
true
8317695c37f954c11bb04810a427b47d0bd518e5
Arup-Paul8509/Python_Tutorials
/Tkinter/Tutorial/03_2_Grid_method.py
1,680
4.5
4
''' ***Python Tkinter grid() method*** The grid() geometry manager organizes the widgets in the tabular form. We can specify the rows and columns as the options in the method call. We can also specify the column span ( width) or rowspan(height) of a widget. This is a more organized way to place the widgets to the py...
true
90574be944f57d47ea1fdf12b31825eebc77659b
Arup-Paul8509/Python_Tutorials
/NumPy/1_NumPy Array/02_NumPy_Array_function_Creation.py
360
4.125
4
''' NumPy is used to work with arrays. The array object in NumPy is called ndarray. We can create a NumPy ndarray object by using the array() function. ''' import numpy as np arr1=np.array([1,2,3,4,5])#array created with list arr2=np.array((1,3,5,7,9))#array created with tuple print(arr2) print(type(arr2))#ty...
true
9a031cf6a2566bc4742ec04abbd2ed9748f4140a
Arup-Paul8509/Python_Tutorials
/NumPy/1_NumPy Array/17_Sorting _arrays.py
234
4.125
4
''' The NumPy ndarray object has a function called sort() that will sort a specified array. ''' import numpy as np arr1=np.array([3,2,0,1]); print(np.sort(arr1)) #sorting 2D array arr2=np.array([[3,2,4],[5,0,1]]) print(np.sort(arr2))
true
302df82f6aeed33ff02b005d78ad44a4fd479b61
kedar-naik/markets
/sorting/selection.py
2,024
4.375
4
""" this script implements selection sort """ import numpy as np # -----------------------------------------------------------------------------# def selection_sort(numbers): """ given a list or array of numbers, this function will sort the numbers in ascending order using selection sort. this algorithm i...
true
169df8953d7cd778e2a02ecaf36e66ce944ec4a1
Chinon93/python-programming
/Unit1/variables.py
1,428
4.1875
4
def main(): first_name = "Chinonso" last_name = "Ibekwe" full_name = first_name + " " + last_name print(full_name) #boolean variable neha_has_a_big_head = True #null/none variable (no value; value is missing completely) cars = None #modulus operator (mostly used with integers; ...
true
da0715ca6d97b1121682ebd9b316712e13e6bb8c
firasbk/python_samples
/numbers_exercise.py
282
4.5
4
radius = float ( input ( "Please enter the radius of the circle: ") ) import math area = math.pi * ( radius ** 2 ) circumference = 2 * math.pi * radius print("The area of the circle is: ", round(area,2) ) print("The circumference of the circle is: ", round(circumference,2) )
true
8d2424953443ae31cc9765c1622e74545ba2a254
KyleADeGuzman/UHSComputerScience1
/Assignment1/KyleD.Assignment1.py
2,417
4.34375
4
# 1 lastName= raw_input("what is your lastname? ") firstname= raw_input("what is your first name? ") print("Hello there! " + lastName + ", " + firstname) # 2 # Write a program that asks the user to enter their name and their age. # Print out a message addressed to them that tells them # the year that they will turn...
true
3a5870bc34171034bbea4b5d93d6c1bd626fa8ad
MohamadHaziq/100-days-of-python
/day_1-10/day_7/hangman.py
745
4.125
4
import random import hangman_art from word_list import word_list stages = hangman_art.stages ## List of possible words chosen_word = random.choice(word_list) display = ['_'] * len(chosen_word) lives = 6 print(lives) while "_" in display and lives > 0: letter = input('Guess a letter !').lower() for positio...
true
c6f8149d9eb4d3d70c10625c13d9f451031c33f1
Neminem1203/Puzzles
/DailyCodingProblem/29-runLengthEncode.py
1,279
4.34375
4
''' Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character. For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A". Implement run-length encoding and decoding. You can assume the string to be en...
true
3573f19ab381bb02ff542b2647463d905bfea570
Neminem1203/Puzzles
/DailyCodingProblem/49-maxContiguousSum.py
710
4.1875
4
''' Given an array of numbers, find the maximum sum of any contiguous subarray of the array. For example, given the array [34, -50, 42, 14, -5, 86], the maximum sum would be 137, since we would take elements 42, 14, -5, and 86. Given the array [-5, -1, -8, -9], the maximum sum would be 0, since we would not take any ...
true
a7458f83f76e499b5189c46e751c160218e1cf87
Neminem1203/Puzzles
/DailyCodingProblem/32-currencyConversion.py
1,817
4.1875
4
''' Suppose you are given a table of currency exchange rates, represented as a 2D array. Determine whether there is a possible arbitrage: that is, whether there is some sequence of trades you can make, starting with some amount A of any currency, so that you can end up with some amount greater than A of that currency. ...
true
ecda9a22b4d510e8c8ad3908a4c372b9ea0a467d
Neminem1203/Puzzles
/DailyCodingProblem/34-palindromeInsert.py
2,170
4.25
4
''' Given a string, find the palindrome that can be made by inserting the fewest number of characters as possible anywhere in the word. If there is more than one palindrome of minimum length that can be made, return the lexicographically earliest one (the first one alphabetically). For example, given the string "race"...
true