blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
3c41155cbab16bb91e4387aa35d49e1832ce5b72
codedsun/LearnPythonTheHardWay
/ex32.py
525
4.25
4
#Exercise 32: Loops and List the_count = [1,2,3,4,5] fruits = ['apples','oranges','pears','apricots'] change = [1,'pennies',2,'dimes',3,'quaters'] #for loop in the list for number in the_count: print("This is %d count"%number) for fruit in fruits: print("A fruit of type %s"%fruit) for i in change: print...
true
8c3788b2fc95ce08c9dc6165b6f5de91e7d7d448
semihyilmazz/Rock-Paper-Scissors
/Rock Paper Scissors.py
2,933
4.40625
4
import random print "********************************************************" print "Welcome to Rock Paper Scissors..." print "The rules are simple:" print "The computer and user choose from Rock, Paper, or Scissors." print "Rock crushes scissors." print "Paper covers rock." print "and" print "Scissors cut p...
true
9a6fe2ffbb280d239d50001e637783520b8d4aef
songseonghun/kagglestruggle
/python3/201-250/206-keep-vowels.py
272
4.1875
4
# take a strign. remove all character # that are not vowels. keep spaces # for clarity import re s = 'Hello, World! This is a string.' # sub = substitute s2 = re.sub( '[^aeiouAEIOU ]+', #vowels and # a space '', #replace with nothing s ) print(s2)
true
b5363f3d6c5b6e55b3d7607d055a266b215c28ab
dianamenesesg/HackerRank
/Interview_Preparation_Kit/String_manipulation.py
2,979
4.28125
4
""" Strings: Making Anagrams Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact fre...
true
c5d1e2535e6e8d9ac0218f06a44e437b3358049b
michaelschung/bc-ds-and-a
/Unit1-Python/hw1-lists-loops/picky-words-SOLUTION.py
543
4.3125
4
''' Create a list of words of varying lengths. Then, count the number of words that are 3 letters long *and* begin with the letter 'c'. The count should be printed at the end of your code. • Example: given the list ['bat', 'car', 'cat', 'door', 'house', 'map', 'cyst', 'pear', 'can', 'spike'], there are exactly 3 qualif...
true
c9a7bdeb85a94afc6b17c2b6ddf3be0d78de6206
yangju2011/udacity-coursework
/Programming-Foundations-with-Python/turtle/squares_drawing.py
755
4.21875
4
import turtle def draw_square(some_turtle): i = 0 while i<4: # repeat for squares some_turtle.forward(100) some_turtle.right(90) i=i+1 def draw_shape():#n stands for the number of edge windows = turtle.Screen()#create the background screen for the drawing w...
true
1bb3d699d6d1e7ef8ea39a5cdc7d55f79ac4ed3d
theelk801/pydev-psets
/pset_lists/list_manipulation/p5.py
608
4.25
4
""" Merge Lists with Duplicates """ # Use the two lists below to solve this problem. Print out the result from each section as you go along. list1, list2 = [2, 8, 6], [10, 4, 12] # Double the items in list1 and assign them to list3. list3 = None # Combine the two given lists and assign them to list4. list4 = No...
true
d7aa917a00b2f582c7b15c8b40de0462ca274a66
theelk801/pydev-psets
/pset_classes/fromagerie/p6.py
1,200
4.125
4
""" Fromagerie VI - Record Sales """ # Add an instance method called "record_sale" to the Cheese class. Hint: You will need to add instance attributes for profits_to_date and sales (i.e. number of items sold) to the __init__() method in your Cheese class definition BEFORE writing the instance method. # The record_sa...
true
1859b100bd9711dfa564f8d3a697202bc42d96c2
theelk801/pydev-psets
/pset_conditionals/random_nums/p2.py
314
4.28125
4
""" Generate Phone Number w/Area Code """ # import python randomint package import random # generate a random phone number of the form: # 1-718-786-2825 # This should be a string # Valid Area Codes are: 646, 718, 212 # if phone number doesn't have [646, 718, 212] # as area code, pick one of the above at random
true
278cfd9000b17eaf249eebad07b11d078e934c35
theelk801/pydev-psets
/pset_classes/bank_accounts/solutions/p2.py
1,377
4.21875
4
""" Bank Accounts II - Deposit Money """ # Write and call a method "deposit()" that allows you to deposit money into the instance of Account. It should update the current account balance, record the transaction in an attribute called "transactions", and prints out a deposit confirmation message. # Note 1: You can for...
true
9d9d044b0bff764cc3a8f4e31634f1138f05e2b4
Arin-py07/Python-Programms
/Problem-11.py
888
4.1875
4
Python Program to Check if a Number is Positive, Negative or 0 Source Code: Using if...elif...else num = float(input("Enter a number: ")) if num > 0: print("Positive number") elif num == 0: print("Zero") else: print("Negative number") Here, we have used the if...elif...else statement. We can do the same t...
true
5b428c1de936255d8a787f6939528031fa3ddc9b
Arin-py07/Python-Programms
/Problem-03.py
1,464
4.5
4
Python Program to Find the Square Root Example: For positive numbers # Python Program to calculate the square root # Note: change this value for a different result num = 8 # To take the input from the user #num = float(input('Enter a number: ')) num_sqrt = num ** 0.5 print('The square root of %0.3f is %0.3f'%(nu...
true
e6dead53cca8e5bef774435616a2dd02452e6389
ejoconnell97/Coding-Exercises
/test2.py
1,671
4.15625
4
def test_2(A): # write your code in Python 3.6 ''' Loop through S once, saving each value to a new_password When a numerical character is hit, or end of S, check the new_password to make sure it has at least one uppercase letter - Yes, return it - No, reset string to null and con...
true
0860ed14b0d55e8a3c09aeb9e56075354d1e1298
npandey15/CatenationPython_Assignments
/Task1-Python/Task1_Python/Q3.py
547
4.15625
4
Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license()" for more information. >>> x=6 >>> y=10 >>> >>> Resultname=x >>> x=y >>> y=Resultname >>> print("The value of x after swapping: {}".format(x)) The value of x after swapping:...
true
8a99191f6780e06be6e14501b671cc981f42bf0d
npandey15/CatenationPython_Assignments
/Passwd.py
1,188
4.34375
4
# Passwd creation in python def checker_password(Passwd): "Check if Passwd is valid" Specialchar=["$","#","@","*","%"] return_val=True if len(passwd) < 8: print("Passwd is too short, length of the password should be at least 8") return_val=False if len(passwd) > 30: print...
true
6da25701a40c8e6fce75d9ab89aaf63a45e2ecfe
aparna-narasimhan/python_examples
/Strings/shortest_unique_substr.py
1,322
4.15625
4
''' Smallest Substring of All Characters Given an array of unique characters arr and a string str, Implement a function getShortestUniqueSubstring that finds the smallest substring of str containing all the characters in arr. Return "" (empty string) if such a substring doesn’t exist. Come up with an asymptotically op...
true
0111fd00103f42a032074e0c3b4d40006f1029f9
aparna-narasimhan/python_examples
/Arrays/missing_number.py
866
4.28125
4
''' If elements are in range of 1 to N, then we can find the missing number is a few ways: Option 1 #: Convert arr to set, for num from 0 to n+1, find and return the number that does not exist in set. Converting into set is better for lookup than using original list itself. However, space complexity is also O(N). Opti...
true
8d401a11b4ea284f9bb08c2e2615b9414fd3d3ac
aparna-narasimhan/python_examples
/Misc/regex.py
2,008
4.625
5
#https://www.tutorialspoint.com/python/python_reg_expressions.htm import re line = "Cats are smarter than dogs"; searchObj = re.search( r'(.*) are (.*?) .*', line, re.M|re.I) if searchObj: print "searchObj.group() : ", searchObj.group() print "searchObj.group(1) : ", searchObj.group(1) print "searchObj.grou...
true
ac26b98728ecf7d49aa79f70aa5dd5e3238ef10d
aparna-narasimhan/python_examples
/pramp_solutions/get_different_number.py
1,319
4.125
4
''' Getting a Different Number Given an array arr of unique nonnegative integers, implement a function getDifferentNumber that finds the smallest nonnegative integer that is NOT in the array. Even if your programming language of choice doesn’t have that restriction (like Python), assume that the maximum value an integ...
true
93354f664979d327f700a7f5ed4a28d92b978b16
premraval-pr/ds-algo-python
/data-structures/queue.py
1,040
4.34375
4
# FIFO Structure: First In First Out class Queue: def __init__(self): self.queue = [] # Insert the data at the end / O(1) def enqueue(self, data): self.queue.append(data) # remove and return the first item in queue / O(n) Linear time complexity def dequeue(self): if self....
true
d73c7a9bec4f30251d31d42a17dfa7fde9a48f8e
danieltapp/fcc-python-solutions
/Basic Algorithm Scripting Challenges/caesars-cipher.py
848
4.21875
4
#One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount. #A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on. #W...
true
2248f6b4e815240d85ee37a6af3dc6c58d44d2d7
danieltapp/fcc-python-solutions
/Basic Algorithm Scripting Challenges/reverse-a-string.py
313
4.4375
4
#Reverse the provided string. #You may need to turn the string into an array before you can reverse it. #Your result must be a string. def reverse_string(str): return ''.join(list(reversed(str))) print(reverse_string('hello')) print(reverse_string('Howdy')) print(reverse_string('Greetings from Earth'))
true
759f39154fc321a20f84850be8482262b21b427e
oluwaseunolusanya/al-n-ds-py
/chapter_4_basic_data_structures/stackDS.py
967
4.375
4
class Stack: #Stack implementation as a list. def __init__(self): self._items = [] #new stack def is_empty(self): return not bool(self._items) def push(self, item): self._items.append(item) def pop(self): return self._items.pop() def peek(self): ...
true
33c05d544f56bec9699add58b0a26673d41e974a
shubee17/Algorithms
/Array_Searching/search_insert_delete_in_unsort_arr.py
1,239
4.21875
4
# Search,Insert and delete in an unsorted array import sys def srh_ins_del(Array,Ele): # Search flag = 0 for element in range(len(Array)): if Array[element] == int(Ele): flag = 1 print "Element Successfully Found at position =>",element + 1 break else: flag = 0 if flag == 0: print "Element Not F...
true
b1ec062d544dfb65fbd8f09e67bb03dce65aeef6
betta-cyber/leetcode
/python/208-implement-trie-prefix-tree.py
784
4.125
4
#!/usr/bin/env python # encoding: utf-8 class Trie(object): def __init__(self): self.root = {} def insert(self, word): p = self.root for c in word: if c not in p: p[c] = {} p = p[c] p['#'] = True def search(self, word): nod...
true
9f7a5977df4e57f7c7c5518e4e3bc42f517d1856
matthew-lu/School-Projects
/CountingQueue.py
1,823
4.125
4
# This program can be called on to create a queue that stores pairs (x, n) where x is # an element and n is the count of the number of occurences of x. # Included are methods to manipulate the Counting Queue. class CountingQueue(object): def __init__(self): self.queue = [] def __repr__(s...
true
8949fd91df9d848465b03c7024e7516738e72c8e
jtew396/InterviewPrep
/linkedlist2.py
1,651
4.21875
4
# Linked List Data Structure # HackerRank # # # Node class class Node: # Function to initialize the node object def __init__(self, data): self.data = data self.next = None # LinkedList class class LinkedList: # Function to initialize the LinkedList class def __init__(self): s...
true
a624e3d14acd2154c5dc156cfaa092ab1767d6a5
jtew396/InterviewPrep
/search1.py
1,154
4.25
4
# Cracking the Coding Interview - Search # Depth-First Search (DFS) def search(root): if root == None: return print(root) root.visited = True for i in root.adjacent: if i.visited == false: search(i) # Breadth-First Search (BFS) - Remember to use a Queue Data Structure def ...
true
ffbd1535e7f9c25e817c10e31e0e6812a7645724
knpatil/learning-python
/src/dictionaries.py
686
4.25
4
# dictionary is collection of key-value pairs # students = { "key1":"value1", "key2": "value2", "key3": "value3" } # color:point alien = {} # empty dictionary alien = {"green":100} alien['red'] = 200 alien['black'] = 90 print(alien) # access the value print(alien['black']) # modify the value alien['red'] = 500 p...
true
7b3f5e98d0ec4f94764e65e70a68c542f44ea966
knpatil/learning-python
/src/lists2.py
2,077
4.46875
4
cars = ['bmw', 'audi', 'toyota', 'subaru'] print(cars) # sort a list by alphabetical order # cars.sort() # print(cars) # # cars.sort(reverse=True) # reverse order sort # print(cars) print(sorted(cars)) # temporarily sort a list print(cars) cars.reverse() print(cars) print(len(cars)) # print(cars[4]) # exception...
true
a87bf15fb1e4f742f5f31be7a1af84276ffe6fc2
MaxAttax/maxattax.github.io
/resources/Day1/00 - Python Programming/task4.py
808
4.40625
4
# Task 4: Accept comma-separated input from user and put result into a list and into a tuple # The program waits until the user inputs a String into the console # For this task, the user should write some comma-separated integer values into the console and press "Enter" values = input() # Use for Python 3 # After ...
true
e829a743405b49893446c705272db2f7323bb329
Sharanhiremath02/C-98-File-Functions
/counting_words_from_file.py
281
4.375
4
def count_words_from_file(): fileName=input("Enter the File Name:") file=open(fileName,"r") num_words=0 for line in file: words=line.split() num_words=num_words+len(words) print("number of words:",num_words) count_words_from_file()
true
7c821b9a5102495f8f22fc21e29dd9812c77b3bd
chetanDN/Python
/AlgorithmsAndPrograms/02_RecursionAndBacktracking/01_FactorialOfPositiveInteger.py
222
4.125
4
#calculate the factorial of a positive integer def factorial(n): if n == 0: #base condition return 1 else: return n * factorial(n-1) #cursive condition print(factorial(6))
true
9bbcd87d994a200ebe11bc09ff79995dd74eac0a
GBaileyMcEwan/python
/src/hello.py
1,863
4.5625
5
#!/usr/bin/python3 print("Hello World!\n\n\n"); #print a multi-line string print( ''' My Multi Line String ''' ); #concatinate 2 words print("Pass"+"word"); #print 'Ha' 4 times print("Ha" * 4); #get the index of the letter 'd' in the word 'double' print("double".find('d')); #print a lower-case version of the stri...
true
34ad45e897f4b10154ccf0f0585c29e1e51ad2f8
EwarJames/alx-higher_level_programming
/0x0B-python-input_output/3-to_json_string.py
315
4.125
4
#!/usr/bin/python3 """Define a function that returns a json.""" import json def to_json_string(my_obj): """ Function that convert json to a string. Args: my_obj (str): Object to be converted. Return: JSON representation of an object (string) """ return json.dumps(my_obj)
true
431384abd81af78ff79355d261528645cf9c100b
pi408637535/Algorithm
/com/study/algorithm/daily/diameter-of-binary-tree.py
1,370
4.15625
4
''' 树基本是递归。 递归:四要素 本题思路:left+right=diameter https://www.lintcode.com/problem/diameter-of-binary-tree/description ''' #思路: #Definition of TreeNode: class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None class Solution: """ @param root: a r...
true
8661d933bf731b111cda9345752a0307ff4adca8
rodrigomanhaes/model_mommy
/model_mommy/generators.py
1,794
4.34375
4
# -*- coding:utf-8 -*- __doc__ = """ Generators are callables that return a value used to populate a field. If this callable has a `required` attribute (a list, mostly), for each item in the list, if the item is a string, the field attribute with the same name will be fetched from the field and used as argument fo...
true
6c036ab3ae9e679019d589fbd8de8be45486773f
gbrough/python-projects
/palindrome-checker.py
562
4.375
4
# Ask user for input string # Reverse the string # compare if string is equal # challenge - use functions word = None def wordInput(): word = input("Please type a word you would like to see if it's a palindrome\n").lower() return word def reverseWord(): reversedWord = word[::-1] return reversedWord def palin...
true
5ebe1f88e466c99ba52f3dd43a17e692b30c96b2
chena/aoc-2017
/day12.py
2,625
4.21875
4
""" part 1: Each program has one or more programs with which it can communicate, and they are bidirectional; if 8 says it can communicate with 11, then 11 will say it can communicate with 8. You need to figure out how many programs are in the group that contains program ID 0. For example, suppose you go door-to-door...
true
6e33fd4e81dcfdce22916bd20d4230e472490dae
chena/aoc-2017
/day05.py
1,882
4.53125
5
""" part 1: The message includes a list of the offsets for each jump. Jumps are relative: -1 moves to the previous instruction, and 2 skips the next one. Start at the first instruction in the list. The goal is to follow the jumps until one leads outside the list. In addition, these instructions are a little strange;...
true
164dda3ecb9d27c153dbc9d143ba05437c47f656
luisprooc/data-structures-python
/src/bst.py
1,878
4.1875
4
from binary_tree import Node class BST(object): def __init__(self, root): self.root = Node(root) def insert(self, new_val): current = self.root while current: if new_val >= current.value: if not current.right: current.right = Node(new_...
true
757cfb65fc22c1f8f9326a25018defb7aafbad56
2FLing/CSCI-26
/codewar/camel_case.py
531
4.25
4
# Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case). # Examples # to_camel_case("the-stealth-warrior") # r...
true
5a5581ad8604d9d61d579ab1661be5c7d70cdcb6
rodrigocamarena/Homeworks
/sess3&4ex4.py
2,915
4.5
4
print("Welcome to the universal pocket calculator.") print("1. Type <+> if you want to compute a sum." "\n2. Type <-> if you want to compute a rest." "\n3. Type <*> if you want to compute a multiplication." "\n4. Type </> if you want to compute a division." "\n5. Type <quit> if you want to exit....
true
7536d2a8c16cc9bda41d4a4d3894c0a8a0911446
artemis-beta/phys-units
/phys_units/examples/example_2.py
1,160
4.34375
4
############################################################################## ## Playing with Measurements ## ## ## ## In this example the various included units are explored in a fun and ## ## ...
true
3c419f360e36ed45af7d7935aa2f824bb2dc472a
Cleancode404/ABSP
/Chapter8/input_validation.py
317
4.1875
4
import pyinputplus as pyip while True: print("Enter your age:") age = input() try: age = int(age) except: print("Please use numeric digits.") continue if age < 0: print("Please enter a positive number.") continue break print('Your age is', age)
true
bf005c98b3c7beabc0e2000cfd0cfd404010a9a9
AlexRoosWork/PythonScripts
/delete_txts.py
767
4.15625
4
#!/usr/bin/env python3 # given a directory, go through it and its nested dirs to delete all .txt files import os def main(): print(f"Delete all text files in the given directory\n") path = input("Input the basedir:\n") to_be_deleted = [] for dirpath, dirnames, filenames in os.walk(path): for...
true
8ae3f309e572b41a3ff5205692f0ae4c90f11962
Trenchevski/internship
/python/ex6.py
867
4.21875
4
# Defining x with string value x = "There are %d types of people." % 10 # Binary variable gets string value with same name binary = "binary" # Putting string value to "don't" do_not = "don't" # Defining value of y variable using formatters y = "Those who know %s and those who %s." % (binary, do_not) # Printing value of...
true
6cd204d47bb1937a024c1afa0c25527316453468
Soares/natesoares.com
/overviewer/utilities/string.py
633
4.5
4
def truncate(string, length, suffix='...'): """ Truncates a string down to at most @length characters. >>> truncate('hello', 12) 'hello' If the string is longer than @length, it will cut the string and append @suffix to the end, such that the length of the resulting string is @length. ...
true
066bcfb00c4f01528d79d8a810a65d2b64e8a8a2
bchaplin1/homework
/week02/03_python_homework_chipotle.py
2,812
4.125
4
''' Python Homework with Chipotle data https://github.com/TheUpshot/chipotle ''' ''' BASIC LEVEL PART 1: Read in the data with csv.reader() and store it in a list of lists called 'data'. Hint: This is a TSV file, and csv.reader() needs to be told how to handle it. https://docs.python.org/2/library/csv.html ''' ...
true
90af163267b8d485c28169c9aeb149df021e3509
hemenez/holbertonschool-higher_level_programming
/0x07-python-test_driven_development/0-add_integer.py
423
4.3125
4
#!/usr/bin/python3 def add_integer(a, b): """Module will add two integers """ total = 0 if type(a) is not int and type(a) is not float: raise TypeError('a must be an integer') if type(b) is not int and type(b) is not float: raise TypeError('b must be an integer') if type(a) is fl...
true
ba2c8e1e768b24f7ad7a4c00ee6ed4116d31a21a
kjigoe/Earlier-works
/Early Python/Fibonacci trick.py
866
4.15625
4
dic = {0:0, 1:1} def main(): n = int(input("Input a number")) ## PSSST! If you use 45 for 'n' you get a real phone number! counter = Counter() x = fib(n,counter) print("Fibonacci'd with memoization I'd get",x) print("I had to count",counter,"times!") y = recursivefib(n, counter) print("And with recusion I stil...
true
e996c9bff605c46d30331d13e44a49c04a2e29be
Kaylotura/-codeguild
/practice/greeting.py
432
4.15625
4
"""Asks for user's name and age, and greets them and tells them how old they'll be next year""" # 1. Setup # N/A # 2. Input name = input ("Hello, my name is Greetbot, what's your name? ") age = input(name + ' is a lovely name! How old are you, ' + name + '? ') # 3. Transform olderage = str(int(age) + 1) # 4. Output...
true
922c0d74cf538e3a28a04581b9f57f7cfb7377e4
BstRdi/wof
/wof.py
1,573
4.25
4
from random import choice """A class that can be used to represent a wheel of fortune.""" fields = ('FAIL!', 'FAIL!', 100, 'FAIL!', 'FAIL!', 500, 'FAIL!', 250, 'FAIL!', 'FAIL!', 'FAIL!', 'FAIL!', 1000, 'FAIL!', 'FAIL!', 'FAIL!', 'FAIL!', 'FAIL!', 'FAIL!') score = [] class WheelOfFortune: """A simple at...
true
b63879f6a16ae903c1109d3566089e47d0212200
idahopotato1/learn-python
/01-Basics/005-Dictionaries/dictionaries.py
1,260
4.375
4
# Dictionaries # A dictionary is an associative array (also known as hashes). # Any key of the dictionary is associated (or mapped) to a value. # The values of a dictionary can be any Python data type. # So dictionaries are unordered key-value-pairs. # Constructing a Dictionary my_dist = {'key1': 'value1', 'key2': 10...
true
b5dbb2bc21aca13d23b3d3f87569877ce9951eec
idahopotato1/learn-python
/04-Methods-Functions/001-methods.py
736
4.34375
4
# Methods # The other kind of instance attribute reference is a method. # A method is a function that “belongs to” an object. # (In Python, the term method is not unique to class instances: # other object types can have methods as well. # For example, list objects have methods called append, insert, remove, sort, an...
true
4afb88e53ccddb16c631b2af181bb0e607a2b37b
Evakung-github/Others
/381. Insert Delete GetRandom O(1).py
2,170
4.15625
4
''' A hashmap and an array are created. Hashmap tracks the position of value in the array, and we can also use array to track the appearance in the hashmap. The main trick is to swap the last element and the element need to be removed, and then we can delete the last element at O(1) cost. Afterwards, we need to update ...
true
c57eab0302c15814a5f51c2cbc0fa104910eef08
hihihien/nrw-intro-to-python
/lecture-06/solutions/exponent.py
261
4.28125
4
base = float(input('What is your base?')) exp = float(input('What is your exponent?')) num = exp result = 1 while num > 0: result = result * base num = num - 1 print(f'{base} raised to the power of {exp} is: {result}. ({base} ** {exp} = {base**exp})')
true
ef2e1747c49dca4e17fe558704d05d50b2a11506
kengbailey/interview-prep
/selectionsort.py
1,507
4.28125
4
# Selection Sort Implementation in Python ''' How does it work? for i = 1:n, k = i for j = i+1:n, if a[j] < a[k], k = j → invariant: a[k] smallest of a[i..n] swap a[i,k] → invariant: a[1..i] in final position end What is selection sort? The selection sort algorithm is a combination of searching ...
true
6c612b3a3904a9710b3f47c0174edf1e0f15545b
spots1000/Python_Scripts
/Zip File Searcher.py
2,412
4.15625
4
from zipfile import ZipFile import sys import os #Variables textPath = "in.txt" outPath = "out.txt" ## Announcements print("Welcome to the Zip Finder Program!") print("This program will take a supplied zip file and locate within said file any single item matching the strings placed in an accompanying text...
true
77ee96c305f1d7d21ddae8c1029639a50627382b
SamuelHealion/cp1404practicals
/prac_05/practice_and_extension/electricity_bill.py
1,317
4.1875
4
""" CP1404 Practice Week 5 Calculate the electricity bill based on provided cents per kWh, daily use and number of billing days Changed to use dictionaries for the tariffs """ TARIFFS = {11: 0.244618, 31: 0.136928, 45: 0.385294, 91: 0.374825, 33: 0.299485} print("Electricity bill estimator 2.0") print("Which tariff a...
true
823282e7460b9d11b4d4127fa68a87352a5543ce
SamuelHealion/cp1404practicals
/prac_02/practice_and_extension/word_generator.py
2,154
4.25
4
""" CP1404/CP5632 - Practical Random word generator - based on format of words Another way to get just consonants would be to use string.ascii_lowercase (all letters) and remove the vowels. """ import random VOWELS = "aeiou" CONSONANTS = "bcdfghjklmnpqrstvwxyz" def first_version(): """Requires c and v only""" ...
true
d2539727c20ffae59e81cccadb78648b10797a5d
SamuelHealion/cp1404practicals
/prac_06/guitar.py
730
4.3125
4
""" CP1404 Practical 6 - Classes Define the class Guitar """ VINTAGE_AGE = 50 CURRENT_YEAR = 2021 class Guitar: """Represent a Guitar object.""" def __init__(self, name='', year=0, cost=0): """Initialise a Guitar instance.""" self.name = name self.year = year self.cost = cost...
true
6339d40839889e191b3ef8dae558cf3266b08ba8
jamieboyd/neurophoto2018
/code/simple_loop.py
407
4.46875
4
#! /usr/bin/python #-*-coding: utf-8 -*- """ a simple for loop with conditionals % is the modulus operator, giving the remainder of the integer division of the left operand by the right operand. If a number divides by two with no remainder it is even. """ for i in range (0,10,1): if i % 2 == 1: print (str ...
true
86dec63990bd3ae55a023380af8ce0f38fcdf3e2
CQcodes/MyFirstPythonProgram
/Main.py
341
4.25
4
import Fibonacci import Check # Driver Code print("Program to print Fibonacci series upto 'n'th term.") input = input("Enter value for 'n' : ") if(Check.IsNumber(input)): print("Printing fibonacci series upto '" + input + "' terms.") Fibonacci.Print(int(input)) else: print("Entered value is not a valid inte...
true
f193bf10635f1b1cc9f4f7aa0ae7a209e5f041db
Yashs744/Python-Programming-Workshop
/if_else Ex-3.py
328
4.34375
4
# Nested if-else name = input('What is your name? ') # There we can provide any name that we want to check with if name.endswith('Sharma'): if name.startswith('Mr.'): print ('Hello,', name) elif name.startswith('Mrs.'): print ('Hello,', name) else: print ('Hello,', name) else: print ('Hello, St...
true
012cc0af4adbfa714a4f311b729d89a9ba446d35
Tagirijus/ledger-expenses
/general/date_helper.py
1,213
4.1875
4
import datetime from dateutil.relativedelta import relativedelta def calculateMonths(period_from, period_to): """Calculate the months from two given dates..""" if period_from is False or period_to is False: return 12 delta = relativedelta(period_to, period_from) return abs((delta.years * 12) ...
true
b5a66fd0978895aaabb5cb93de5a7cfabd57ad8e
yosef8234/test
/python_simple_ex/ex28.py
477
4.3125
4
# Write a function find_longest_word() that takes a list of words and # returns the length of the longest one. # Use only higher order functions. def find_longest_word(words): ''' words: a list of words returns: the length of the longest one ''' return max(list(map(len, words))) # test print(fin...
true
b787971db2b58732d63ea00aaac8ef233068b822
yosef8234/test
/python_simple_ex/ex15.py
443
4.25
4
# Write a function find_longest_word() that takes a list of words and # returns the length of the longest one. def find_longest_word(words): longest = "" for word in words: if len(word) >= len(longest): longest = word return longest # test print(find_longest_word(["i", "am", "python...
true
9b22d6e5f777384cd3b88f9d44b7f2711346fc74
yosef8234/test
/pfadsai/07-searching-and-sorting/notes/sequential-search.py
1,522
4.375
4
# Sequential Search # Check out the video lecture for a full breakdown, in this Notebook all we do is implement Sequential Search for an Unordered List and an Ordered List. def seq_search(arr,ele): """ General Sequential Search. Works on Unordered lists. """ # Start at position 0 pos = 0 # Targ...
true
720f5fa949f49b1fa20d7c0ae08ae397fc6fc225
yosef8234/test
/pfadsai/03-stacks-queues-and-deques/notes/implementation-of-stack.py
1,537
4.21875
4
# Implementation of Stack # Stack Attributes and Methods # Before we implement our own Stack class, let's review the properties and methods of a Stack. # The stack abstract data type is defined by the following structure and operations. A stack is structured, as described above, as an ordered collection of items where ...
true
5d1b9a089f9f4c0e6b8674dafffa486f4698cdb4
yosef8234/test
/toptal/python-interview-questions/4.py
1,150
4.5
4
# Q: # What will be the output of the code below in Python 2? Explain your answer. # Also, how would the answer differ in Python 3 (assuming, of course, that the above print statements were converted to Python 3 syntax)? def div1(x,y): print "%s/%s = %s" % (x, y, x/y) def div2(x,y): print "%s//%s = %s" % (x, ...
true
3c39888213a9dcc78c1c0a641b9ab70c87680c0a
yosef8234/test
/pfadsai/04-linked-lists/questions/linked-list-reversal.py
2,228
4.46875
4
# Problem # Write a function to reverse a Linked List in place. The function will take in the head of the list as input and return the new head of the list. # You are given the example Linked List Node class: class Node(object): def __init__(self,value): self.value = value self.nextnode = None #...
true
9041e5cb16518965f170e82bdac4929e93ab0273
yosef8234/test
/hackerrank/30-days-of-code/day-24.py
2,826
4.375
4
# # -*- coding: utf-8 -*- # Objective # Check out the Tutorial tab for learning materials and an instructional video! # Task # A Node class is provided for you in the editor. A Node object has an integer data field, datadata, and a Node instance pointer, nextnext, pointing to another node (i.e.: the next node in a lis...
true
756868b809716f135bb1a27a9c35791e116a902a
yosef8234/test
/pfadsai/04-linked-lists/questions/implement-a-linked-list.py
952
4.46875
4
# Implement a Linked List - SOLUTION # Problem Statement # Implement a Linked List by using a Node class object. Show how you would implement a Singly Linked List and a Doubly Linked List! # Solution # Since this is asking the same thing as the implementation lectures, please refer to those video lectures and notes for...
true
6eb333b658f76812126d0fefdb33a39e66f608bf
yosef8234/test
/pfadsai/10-mock-interviews/ride-share-company/on-site-question3.py
2,427
4.3125
4
# On-Site Question 3 - SOLUTION # Problem # Given a binary tree, check whether it’s a binary search tree or not. # Requirements # Use paper/pencil, do not code this in an IDE until you've done it manually # Do not use built-in Python libraries to do this, but do mention them if you know about them # Solution # The f...
true
0d349d0708bdb56ce5da09f585eaf41d8f9952c3
yosef8234/test
/python_essential_q/q8.py
2,234
4.6875
5
# Question 8 What does this stuff mean: *args, **kwargs? And why would we use it? # Answer # Use *args when we aren't sure how many arguments are going to be passed to a function, or if we want to pass a stored list or tuple of arguments to a function. **kwargs is used when we dont know how many keyword arguments wi...
true
ec8296cf056afef1f3ad97123c852b66f25d75cb
yosef8234/test
/pfadsai/04-linked-lists/notes/singly-linked-list-implementation.py
1,136
4.46875
4
# Singly Linked List Implementation # In this lecture we will implement a basic Singly Linked List. # Remember, in a singly linked list, we have an ordered list of items as individual Nodes that have pointers to other Nodes. class Node(object): def __init__(self,value): self.value = value self.ne...
true
09da1340b227103c7eb1bc9800c714907939bfde
yosef8234/test
/python_ctci/q1.4_permutation_of_palindrom.py
1,097
4.21875
4
# Write a function to check if a string is a permutation of a palindrome. # Permutation it is "abc" == "cba" # Palindrome it is "Madam, I'm Adam' # A palindrome is word or phrase that is the same backwards as it is forwards. (Not limited to dictionary words) # A permutation is a rearrangement of letters. import string...
true
c117f5f321a25493ee9c3811a51e6c28d6487392
imjching/playground
/python/practice_python/11_check_primality_functions.py
730
4.21875
4
# http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html """ Ask the user for a number and determine whether the number is prime or not. (For those who have forgotten, a prime number is a number that has no divisors.). You can (and should!) use your answer to [Exercise 4](/exercise/2014/02...
true
8f13963a5059a9cbb14790645f86ff0415398108
imjching/playground
/python/practice_python/14_list_remove_duplicates.py
764
4.1875
4
# http://www.practicepython.org/exercise/2014/05/15/14-list-remove-duplicates.html """ Write a program (function!) that takes a list and returns a new list that contains all the elements of the first list minus all the duplicates. Extras: Write two different functions to do this - one using a loop and constructing a...
true
35c0ab9c2e6bfb4eea6f3750b208495ce1407d03
imjching/playground
/python/practice_python/18_cows_and_bulls.py
1,813
4.21875
4
# http://www.practicepython.org/exercise/2014/07/05/18-cows-and-bulls.html """ Create a program that will play the 'cows and bulls' game with the user. The game works like this: Randomly generate a 4-digit number. Ask the user to guess a 4-digit number. For every digit that the user guessed correctly in the correct p...
true
53937a32b059e4e9613be47b492f586eff09a06d
bkhuong/LeetCode-Python
/make_itinerary.py
810
4.125
4
class Solution: ''' Given a list of tickets, find itinerary in order using the given list. ''' def find_route(tickets:list) -> str: routes = {} start = [] # create map for ticket in tickets: routes[ticket[0]] = {'to':ticket[1]} try: ...
true
70cc3581b224daa3beadfc0150d31b52c30f6284
Gachiman/Python-Course
/python-scripts/hackerrank/Medium/Find Angle MBC.py
603
4.21875
4
import math def input_length_side(val): while True: try: length = int(float(input("Enter the length of side {0} (0 < {0} <= 100): ".format(val)))) if 0 < length <= 100: return length else: raise ValueError except ValueError: ...
true
a1b6391a773b23a0f5fe8e0b0a4d36bc7e03b9b0
hobsond/Computer-Architecture
/white.py
1,788
4.625
5
# Given the following array of values, print out all the elements in reverse order, with each element on a new line. # For example, given the list # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] # Your output should be # 0 # 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # You may use whatever programming language you'd like. # Verbalize...
true
2718e25886a29226c5050afe0d83c6459bd6747b
Twest19/prg105
/Ch 10 HW/10-1_person_data.py
1,659
4.71875
5
""" Design a class that holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator methods (get and set). Write a program that creates three instances of the class. One instance should hold your information and the other two should hold your friends' o...
true
b33b65d4b831bcd41fac9f4cd424a65dc4589d39
Twest19/prg105
/3-3_ticket.py
2,964
4.3125
4
""" You are writing a program to sell tickets to the school play. If the person buying the tickets is a student, their price is $5.00 per ticket. If the person buying the tickets is a veteran, their price is $7.00 per ticket. If the person buying the ticket is a sponsor of the play, the price is $2.00 per ticket. ...
true
20a0d53d34ba73884e14d026030289475bb6275e
Twest19/prg105
/chapter_practice/ch_9_exercises.py
2,681
4.4375
4
""" Complete all of the TODO directions The number next to the TODO represents the chapter and section in your textbook that explain the required code Your file should compile error free Submit your completed file """ import pickle # TODO 9.1 Dictionaries print("=" * 10, "Section 9.1 dictionaries",...
true
666efab8a625d46543dab413aadd15936594a5dd
Twest19/prg105
/4-1_sales.py
862
4.5625
5
""" You need to create a program that will have the user enter in the total sales amount for the day at a coffee shop. The program should ask the user for the total amount of sales and include the day in the request. At the end of data entry, tell the user the total sales for the week, and the average sa...
true
a3ace412c840aac7ff86999020c0d765a5062a5d
Twest19/prg105
/5-3_assessment.py
2,467
4.21875
4
""" You are going to write a program that finds the area of a shape for the user. """ # set PI as a constant to be used as a global value PI = 3.14 # create a main function then from the main function call other functions to get the correct calculations def main(): while True: menu() ...
true
52dd577610c57f96e36b41ee06982c873f0d55af
dougiejim/Automate-the-boring-stuff
/commaCode.py
753
4.3125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- #Write a function that takes a list value as an argument and returns #a string with all the items separated by a comma and a space, with #and inserted before the last item. For example, passing the previous #spam list to the function would return 'apples, bananas, tofu, ...
true
732a68dc8a28c98ecc93001de996919759778a2c
sakamoto-michael/Sample-Python
/new/intro_loops.py
727
4.28125
4
# Python Loops and Iterations nums = [1, 2, 3, 4, 5] # Looping through each value in a list for num in nums: print(num) # Finding a value in a list, breaking upon condition for num in nums: if num == 3: print('Found!') break print(num) # Finding a value, the continuing execution for num in nums: if n...
true
701ea9976f04c66564962c3bc7f64d89e1314120
vivekyadav6838/Data-Structures-and-Algorithms-for-Interviews
/Python/BinaryTree/NumberOfNonLeafNodes.py
1,524
4.3125
4
# @author # Aakash Verma # Output: # Pre Order Traversal is: 1 2 4 5 3 6 7 # Number Of non-Leaf Nodes: 3 # Creating a structure for the node. # Initializing the node's data upon calling its constructor. class Node: def __init__(self, data): self.data = data self.right = self.left = None # Def...
true
8878c006639c546777ff2af254a979033560c15a
vivekyadav6838/Data-Structures-and-Algorithms-for-Interviews
/Python/LinkedList/StartingOfLoop.py
1,519
4.34375
4
# # # # @author # Aakash Verma # # Start of a loop in Linked List # # Output: # 5 # # Below is the structute of a node which is used to create a new node every time. class Node: def __init__(self, data): self.data = data self.next = None # None is nothing but null # Creating a class for implementing ...
true
96ca87b2c6191ffd17b5571581f5dec816529ef2
SgtHouston/python102
/sum the numbers.py
249
4.21875
4
# Make a list of numbers to sum numbers = [1, 2, 3, 4, 5, 6] # set up empty total so we can add to it total = 0 # add current number to total for each number iun the list for number in numbers: total += number # print the total print(total)
true
25ceca21258ebec39c3bb51f308a1e5f136aaca4
urmajesty/learning-python
/ex5.py
581
4.15625
4
name = 'Zed A Shaw' age = 35.0 # not a lie height = 74.0 # inches weight = 180.0 #lbs eyes = 'Blue' teeth = 'White' hair = 'Brown' print(f"Let's talk about {name}.") print(f"He's {height} pounds heavy.") print("Actually that's not too heavy.") print(f"He's got {eyes} eyes and {hair} hair.") print(f"His teeth are usua...
true
53c52d5fb29d5f8f28c56ead8f8c31dfd6f06d98
antoinemadec/test
/python/codewars/simplifying/simplifying.py
2,602
4.5
4
#!/usr/bin/env python3 ''' You are given a list/array of example formulas such as: [ "a + a = b", "b - d = c ", "a + b = d" ] Use this information to solve a formula in terms of the remaining symbol such as: "c + a + b" = ? in this example: "c + a + b" = "2a" Notes: Variables names are case sensitive There ...
true
1d5eba8fd2834bb2375016ec7ed9e8cc686f1991
antoinemadec/test
/python/programming_exercises/q5/q5.py
662
4.21875
4
#!/usr/bin/env python3 print("""https://raw.githubusercontent.com/zhiwehu/Python-programming-exercises/master/100%2B%20Python%20challenging%20programming%20exercises.txt Question: Define a class which has at least two methods: getString: to get a string from console input printString: to print the string ...
true
7f17dd1d0b9acc663a17846d838cbd79998bb79b
antoinemadec/test
/python/programming_exercises/q6/q6.py
840
4.21875
4
#!/usr/bin/env python3 print("""https://raw.githubusercontent.com/zhiwehu/Python-programming-exercises/master/100%2B%20Python%20challenging%20programming%20exercises.txt Question: Write a program that calculates and prints the value according to the given formula: Q = Square root of [(2 * C * D)/H] Follow...
true
d057707ccd873e895d2caf5eec45a19e0473da84
antoinemadec/test
/python/codewars/find_the_divisors/find_the_divisors.py
708
4.3125
4
#!/usr/bin/env python3 """ Create a function named divisors/Divisors that takes an integer and returns an array with all of the integer's divisors(except for 1 and the number itself). If the number is prime return the string '(integer) is prime' (null in C#) (use Either String a in Haskell and Result<Vec<u32>, String>...
true
81cc9b7d03933d990e1a90129929d1eb78ffb108
antoinemadec/test
/python/cs_dojo/find_mult_in_list/find_mult_in_list.py
526
4.1875
4
#!/bin/env python3 def find_multiple(int_list, multiple): sorted_list = sorted(int_list) n = len(sorted_list) for i in range(0,n): for j in range(i+1,n): x = sorted_list[i] y = sorted_list[j] if x*y == multiple: return (x,y) elif x>mu...
true