blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
835f358f71f3a8e6361c2c5fa0a8ed765e58386b
jakupierblina/learning-python
/tutorial/set.py
1,059
4.1875
4
x = set('abcde') y = set('bdxyz') print('e' in x) # membership print(x-y) #difference print(x | y) #union print(x & y) #intersection print(x ^ y) #symmetric difference print(x > y, x < y) #superset, subset z = x.intersection(y) #find the same elements z.add('SPAM') print(z) z.update(set(['X', 'Y'])) #update the se...
true
0a4cf1075711c3b98b5d6dfd88b0065aec99c044
stephenchenxj/myLeetCode
/findDiagonalOrder.py
1,512
4.15625
4
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. 498. Diagonal Traverse Medium Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Example: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1...
true
f8ff8c47fe3b6f6532182ec3474a1405f8293638
stephenchenxj/myLeetCode
/reverseInteger.py
1,146
4.15625
4
# -*- coding: utf-8 -*- """ Created on Sat Oct 5 00:44:11 2019 @author: stephen.chen """ ''' 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 r...
true
da0019078824aa244442fbf23e20fb33814c05af
stephenchenxj/myLeetCode
/shuffle.py
1,386
4.15625
4
# -*- coding: utf-8 -*- """ Created on Fri Oct 11 20:26:42 2019 @author: stephen.chen Shuffle an Array Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums); // Shuffle the array [1,2,3] and return its result. Any...
true
b0ba8f4f5411931d0d106a1e4ff75c15deb4a32c
christian-alexis/edd_1310_2021
/colas.py
2,818
4.15625
4
#PRUEBAS DE LAS COLAS class Queue: def __init__(self): self.__data = list() def is_empty (self): return len(self.__data)==0 def length(self): return len(self.__data) def enqueue(self,elem): self.__data.append(elem) def dequeue (self): i...
true
0ffe4afc95e64efe667b76c42dbae97687b2160d
mendozatori/python_beginner_proj
/rainfall_report/rainfall_report.py
1,305
4.3125
4
# Average Rainfall Application # CONSTANTS NUM_MONTHS = 12 # initialize total_inches = 0.0 # input years = int(input("How many years are we calculating for? ")) while years < 0: print("Please enter a valid number of years!") years = int(input("How many years are we calculating for? ")) ...
true
3b811ee60b5aee105510e413af107661e2127836
tenzin1308/PythonBasic
/Class/TypesOfMethods.py
711
4.125
4
""" We have 3 types of Methods: a) Instances/Object Methods b) Class Methods c) Static Methods """ class Student: # Class/Static Variable school = "ABC School" def __init__(self, m1, m2, m3): self.m1 = m1 self.m2 = m2 self.m3 = m3 # Instances/Object M...
true
23f386c4f97055645a6724a76dc49f3b7a93c93b
pc2459/learnpy
/csv_parse.py
2,455
4.15625
4
""" Write a script that will take three required command line arguments - input_file, output_file, and the row_limit. From those arguments, split the input CSV into multiple files based on the row_limit argument. Arguments: 1. -i: input file name 2. -o: output file name 3. -r: row limit to split Default settings: 1. ...
true
2791583af83b9ff15ac5fe9d30acd2313e6cfd2a
kirteekishorpatil/dictionary
/studant_data_8.py
375
4.34375
4
# i=0 # dict1={} # if i<3: # num=input("enter the student name") # num2=int(input("enter the students marks")) # i=i+1 # new_type={num:num2} # dict1.update(new_type) # print(dict1) num=input("enter the student name") num2=int(input("enter the students marks")) # i=0 dict1={} # while i<8: new_type={...
true
2bbf90d8645ba21f97c0e4fc635cd50be9bffe2c
milnorms/pearson_revel
/ch7/ch7p5.py
841
4.15625
4
''' (Sorted?) Write the following function that returns True if the list is already sorted in increasing order: def isSorted(lst): Write a test program that prompts the user to enter a list of numbers separated by a space in one line and displays whether the list is sorted or not. Here is a sample run: Sample Run 1...
true
97d6ffbe6671998c18f37757459a61aea61de6f0
milnorms/pearson_revel
/ch8/ch8p4.py
1,626
4.46875
4
''' (Markov matrix) An n by n matrix is called a positive Markov matrix if each element is positive and the sum of the elements in each column is 1. Write the following function to check whether a matrix is a Markov matrix: def isMarkovMatrix(m): Write a test program that prompts the user to enter a 3 by 3 matrix of...
true
d5ae42360d6c5b28032c26f94bf5570608378ae7
milnorms/pearson_revel
/ch4/ch4p2.py
888
4.3125
4
''' (Convert letter grade to number) Write a program that prompts the user to enter a letter grade A/a, B/b, C/c, D/d, or F/f and displays its corresponding numeric value 4, 3, 2, 1, or 0. Sample Run 1 Enter a letter grade: B The numeric value for grade B is 3 Sample Run 2 Enter a letter grade: b The numeric val...
true
c54e78731fa62bc05f222e87bb91d0961b89766a
milnorms/pearson_revel
/ch2/ch2p5.py
1,009
4.21875
4
''' (Financial application: calculate future investment value) Write a program that reads in an investment amount, the annual interest rate, and the number of years, and then displays the future investment value using the following formula: futureInvestmentAmount = investmentAmount * (1 + monthlyInterestRate) ^ numbe...
true
94e1e2f107723e9ea3d4ea648cbd16487b69af16
pectoraux/python_programs
/question5.py
2,323
4.125
4
''' Efficiency: ---------------------------------------------- member function get_length() of class Linked_List runs in O(1) member function get_at_position() of class Linked_List runs in O(n) make_ll() runs in O(n) So question5() runs in O(n) ''' class Node(object): def __init__(self, da...
true
41ad1238055f8657136aebbfdddd50e81ac0e66b
ebrahim-j/FindMissingLab
/MissingNumber.py
662
4.125
4
def find_missing(list1, list2): inputList = [] #list with extra number checkList = [] #template list if len(list1) > len(list2): #determines the variable (input and check)lists will be assigned to inputList = list1 checkList = list2 else: inputList = list2 checkList = li...
true
4cd52636027021227a8195e5a0a8ed31cb7753b3
7Aishwarya/HakerRank-Solutions
/30_Days_of_Code/day5_loops.py
343
4.125
4
'''Given an integer, n, print its first 10 multiples. Each multiple n x i (where 1<=i<=10) should be printed on a new line in the form: n x i = result.''' #!/bin/python3 import math import os import random import re import sys if __name__ == '__main__': n = int(input()) for i in range(10): print(...
true
8bb2e6edbb2d703ad41e899b57cb32b228676557
7Aishwarya/HakerRank-Solutions
/Algorithms/beautiful_days_at_the_movies.py
1,685
4.46875
4
'''Lily likes to play games with integers. She has created a new game where she determines the difference between a number and its reverse. For instance, given the number 12, its reverse is 21. Their difference is 9. The number 120 reversed is 21, and their difference is 99. She decides to apply her game to decision ...
true
6ce7779a588924aab0caea37a70bbe7be5d93ff2
7Aishwarya/HakerRank-Solutions
/30_Days_of_Code/day25_running_time_and_complexity.py
745
4.15625
4
'''Given a number, n find if it is prime or not. Input Format The first line contains an integer, T, the number of test cases. Each of the T subsequent lines contains an integer, n, to be tested for primality. Constraints 1<=T<=30 1<=n<=2*10^9 Output Format For each test case, print whether n is Prime or Not Prime on a...
true
abb691603f4655d3c1a116d94b76f83655d182c3
Jinx-Heniux/Python-2
/maths/odd_check.py
980
4.4375
4
def is_odd(number: int) -> bool: """ Test if a number is a odd number. :param number: the number to be checked. :return: True if the number is odd, otherwise False. >>> is_odd(-1) True >>> is_odd(-2) False >>> is_odd(0) False >>> is_odd(3) True >>> is_odd(4) Fals...
true
8bd8af36d1693829ebbf3e958a11b8a15fe44e0c
Jinx-Heniux/Python-2
/sorts/quick_sort.py
1,336
4.125
4
""" https://en.wikipedia.org/wiki/Quicksort """ def quick_sort(array, left: int = 0, right: int = None): """ Quick sort algorithm. :param array: the array to be sorted. :param left: the left index of sub array. :param right: the right index of sub array. :return: sorted array >>> import r...
true
82c56958204986ce03caf2d8e913b06ccf433ac5
Jinx-Heniux/Python-2
/searches/binary_search_recursion.py
871
4.15625
4
""" https://en.wikipedia.org/wiki/Binary_search_algorithm """ def binary_search(array, key) -> int: """ Binary search algorithm. :param array: the sorted array to be searched. :param key: the key value to be searched. :return: index of key value if found, otherwise -1. >>> array = list(range(...
true
93f1ec4e576c4d805a26e8e0a8b9adef0e021aca
rockchar/CODE_PYTHON
/Sets.py
598
4.28125
4
# sets are unordered collections of unique objects. They contain only one # unique object # Lets create a set my_set = set() my_set.add(1) my_set.add(2) my_set.add(3) print(my_set) # lets try to add a duplicate element to the set my_set.add(3) print(my_set) #lets declare a list with duplicate objects my_list =...
true
6bcdb23587171691e25cd375ea30f5356487dcc9
vensder/codeacademy_python
/shout.py
289
4.15625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- def shout(phrase): if phrase == phrase.upper(): return "YOU'RE SHOUTING!" print phrase else: return "Can you speak up?" print "Hello!" phrase = raw_input("Enter yours phrase:\n") print shout(phrase)
true
2bb4c43c58c24f07a6b0a2e30ae5e3a1593e1ef6
sipakhti/code-with-mosh-python
/Data Structure/Dictionaries.py
1,002
4.25
4
point = {"x": 1, "y": 2} point = dict(x=1, y=2) point["x"] = 10 # index are names of key point["z"] = 20 print(point) # to make sure the program doesnt crash due to invalid dict key if "a" in point: print(point["a"]) # Alternative approach using .get function and it makes the code cleaner print(point.get("a", 0...
true
b5fc18297b318ff88610adf0cb3d3448de671d31
sipakhti/code-with-mosh-python
/Data Structure/Unpacking Operator.py
440
4.21875
4
numbers = [1, 2, 3] print(*numbers) print(1, 2, 3) values = list(range(5)) print(values) print(*range(5), *"Hello") values = [*range(5), * "Hello"] first = [1, 2] second = [3] values = [*first, *second] print(*values) first = dict(x=1) second = dict(x=10, y=2) # incase of multiple values with similar keys, the last...
true
307eccd04d95e8e169f1b1cf743b10fb42686268
sipakhti/code-with-mosh-python
/Control Flow/Ternary_Operator.py
240
4.15625
4
age = 22 if (age >= 18): message = "Eligible" else: message = "Not Eligible" print(message) # more clearner way to do the same thing age = 17 message = "Eligible" if age >= 18 else "Not Eligible" # ternary Operator print(message)
true
64fef01dcc207fc7e1d965d319f03433672f2429
EarthCodeOrg/earthcode-curriculum
/modules/recursive_to_iterative.py
544
4.15625
4
# Recursive to Iterative # Approach 1: Simulate the stack def factorial(n): if n < 2: return 1 return n * factorial(n - 1) def factorial_iter(n): original_n = n results = {} inputs_to_resolve = [n] while inputs_to_resolve: n = inputs_to_resolve.pop() if n < 2: results[n] = 1 else: ...
true
f2a9b7ec51fa931682743a4957d34a9a80441679
ModellingWebLab/chaste-codegen
/chaste_codegen/_script_utils.py
676
4.15625
4
import os def write_file(file_name, file_contents): """ Write a file into the given file name :param file_name: file name including path :param file_contents: a str with the contents of the file to be written """ assert isinstance(file_name, str) and len(file_name) > 0, "Expecting a fi...
true
d0bf5cbec6cc10cecfd3a5e556851908df86110e
pliz/PDF-guard
/pdf-encryptor.py
651
4.15625
4
from PyPDF2 import PdfFileWriter, PdfFileReader pdfWriter = PdfFileWriter() # Read the pdf file which will be encrypted pdf = PdfFileReader("example.pdf") for page_num in range(pdf.numPages): pdfWriter.addPage(pdf.getPage(page_num)) # Encryption process goes here passw = input('Enter your password: ') pdfWriter...
true
2a185cc736922ae8baff835e5d0b9b3727dc7fc3
MLgeek96/Interview-Preparation-Kit
/Python_Interview_Questions/leetcode/problem_sets/Q139_word_break.py
1,980
4.28125
4
import re from typing import List def wordBreak(s: str, wordDict: List[str]) -> bool: """ Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multip...
true
0c822fefe2815bf1f401a6ae0e5ca175fd252ee8
MLgeek96/Interview-Preparation-Kit
/Python_Interview_Questions/leetcode/problem_sets/Q46_permutations.py
1,137
4.125
4
from typing import List def permute(nums: List[int]) -> List[List[int]]: """ Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Examp...
true
6b91e70df04c6feb54be4da4c340b151951f0a4e
MLgeek96/Interview-Preparation-Kit
/Python_Interview_Questions/leetcode/problem_sets/Q169_majority_element.py
1,126
4.28125
4
from typing import List def majorityElement(nums: List[int]) -> int: """ Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1: Input: num...
true
cd2d86cd6a9e91412e5e4eaac9d33716291177e2
MLgeek96/Interview-Preparation-Kit
/Python_Interview_Questions/CSES_Problem_Set/Q2_missing_number.py
1,248
4.125
4
""" You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. Input The first input line contains an integer n. The second line contains n−1 numbers. Each number is distinct and between 1 and n (inclusive). Output Print the missing number. Constraints 2 ≤ n ≤ 2*10^5 Example ...
true
856d259f74a1016e5cc43bfe2bc9bb714108ed2c
MLgeek96/Interview-Preparation-Kit
/Python_Interview_Questions/leetcode/problem_sets/Q20_valid_parenthesis.py
1,243
4.28125
4
def isValid(s: str) -> bool: """ Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order....
true
6ad68ea092a6435db680bd485a1279b2de19292d
MLgeek96/Interview-Preparation-Kit
/Python_Interview_Questions/leetcode/problem_sets/Q11_container_with_most_water.py
1,501
4.25
4
from typing import List def container_with_most_water(height: List[int]) -> int : """" Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines...
true
2be28d3c7f1d27878116b489ddf78409f4fe1a2c
bheinks/2018-sp-a-puzzle_4-bhbn8
/priorityqueue.py
1,194
4.21875
4
class PriorityQueue: """Represents a custom priority queue instance. While Python has a PriorityQueue library available, this is more efficient because it sorts on dequeue, rather than enqueue.""" def __init__(self, key, items=[]): """Initializes a PriorityQueue instance. Args: ...
true
ec9ab3c13b26dfbfbf5edf2225ae6870f59a7e80
lucguittard/DS-Unit-3-Sprint-2-SQL-and-Databases
/module2-sql-for-analysis/practice.py
946
4.21875
4
# Working with sqlite # insert a table # import the needed modules import sqlite3 import pandas as pd # connect to a database connection = sqlite3.connect("myTable.db") # make a cursor curs = connection.cursor() # SQL command to create a table in the database sql_command = """CREATE TABLE emp (staff_number INT...
true
23b32a35acc060b021706f17754c0e1479259025
saranaweera/dsp
/python/q8_parsing.py
701
4.3125
4
# The football.csv file contains the results from the English Premier League. # The columns labeled ‘Goals’ and ‘Goals Allowed’ contain the total number of # goals scored for and against each team in that season (so Arsenal scored 79 goals # against opponents, and had 36 goals scored against them). Write a program to r...
true
656a32a3781605c1f68539cfcdc3e8de98bf4181
sivaneshl/real_python
/implementin_linked_list/implementing_a_own_linked_list.py
1,765
4.46875
4
from linked_list import LinkedList, Node # using the above class create a linked list llist = LinkedList() print(llist) # add the first node first_node = Node('a') llist.head = first_node print(llist) # add subsequent nodes second_node = Node('b') third_node = Node('c') first_node.next = second_node secon...
true
37898e1d98f7a08c52d2dc6fc80779c54ba60685
nnamon/ctf101-systems-2016
/lessonfiles/offensivepython/11-stringencodings.py
864
4.125
4
#!/usr/bin/python def main(): sample_number = 65 # We can get binary representations for a number print bin(sample_number) # Results in 0b1000001 # We can also get hex representations for a number: print hex(sample_number) # Results in 0x41 # Also, octal: print oct(sample_number) # Re...
true
d57e662d520f5ff40408d2d410584cb32942d4aa
elrapha/Lab_Python_01
/zellers.py
1,672
4.75
5
""" Zeller’s algorithm computes the day of the week on which a given date will fall (or fell). In this exercise, you will write a program to run Zeller’s algorithm on a specific date. You will need to create a new file for this program, zellers.py. The program should use the algorithm outlined below to compute the day ...
true
1faf7950718cd67c1bd3dc182059763b1c784c5c
JosephLiu04/Wave3
/PythagTheorem.py
317
4.53125
5
from math import sqrt Side1 = float(input("Input the length of the shorter first side:")) Side2 = float(input("Input the length of the shorter second side: ")) def Pythag_theorem(): Side3 = sqrt((Side1 * Side1) + (Side2 * Side2)) return Side3 print("The length of the hypotenuse is", str(Pythag_theorem()))
true
9902409c31c852fd0878827aaa3b025099f997af
mrfabroa/ICS3U
/Archives/2_ControlFlow/conditional_loops.py
1,611
4.34375
4
__author__ = 'eric' def example1(): # initialize the total and number total = 0 number = input("Enter a number: ") # the loop condition while number != -1: # the loop statements total = total + number number = input("Enter a number: ") print "The sum is", total def...
true
c2e42318e56cf09abd5c1a456a4e3222a80e5226
mrfabroa/ICS3U
/Archives/3_Lists/3_1_practice.py
1,341
4.1875
4
__author__ = 'eric' def middleway(list_a, list_b): """ Given 2 int lists, list_a and list_b, each length 3, write a function middle_way(list_a,list_b) that returns a new list length 2 containing their middle elements. :param list_a: int[] :param list_b: int[] :return: int[] """ li...
true
8b505676a08ba224903433f7546e35ae8f441edb
manhtruong594/vumanhtruong-fundamental-c4e24
/Fundamental/Session04/homework/SeriousEx1.py
1,313
4.125
4
items = ["T-Shirt", "Sweater"] print("Here is my items: ", sep=" ") print(*items, sep=", ") loop = True while loop: cmd = input("Welcome to our shop, what do u want (C, R, U, D or exit)? ").upper() if cmd == "R": print("Our items: ", *items, sep=", ") elif cmd == "C": new = input("Enter new...
true
99ec192ac77df5906950a92b131e73665a76a06a
Cole-Hayson/L1-Python-Tasks
/Names List.py
1,136
4.25
4
names = ["Evi", "Madeleine", "Dan", "Kelsey", "Cayden", "Hayley", "Darian"] user_name = input("Enter a name") if user_name in names: print("That name is already on the list!") else: print("The name you chose is not on the list.") if user_name != names: replace = input("Would you like to replace one of the n...
true
bd64fadca3071891ce36d42ddfdd8b1ddc96901b
PuneetPowar5/Small-Python-Projects
/fibonacciSequence.py
323
4.21875
4
print("Welcome to the Fibonacci Sequence Generator\n") maxNum = int(input("How many numbers of the sequence do you want to see? \n")) maxNum = int(maxNum) a = 0 b = 1 c = 0 print("\n") for num in range(0, maxNum): if(num <= 1): c = num else: c = a + b a = b b = c print...
true
aa960deeb474ab57d4ef72d675a8fd4742104014
egonnelli/algorithms
/sorting_algorithms/01_bubblesort.py
544
4.34375
4
#Bubblesort algorithm in python #Time complexity - O(N^2) def bubble_sort(array): """ This functions implements the bubble sort algorithm """ is_sorted = False counter = 0 while not is_sorted: is_sorted = True for i in range(len(array) - 1 - counter) if array[i] > array[i+1]: swap(i, i+1, array) i...
true
2af5b432ac298bebe3343f9ee18ae79e5f368b3e
Dushyanttara/Competitive-Programing
/aliens.py
2,312
4.15625
4
"""#Dushyant Tara(19-06-2020): This program will help you understand dictionary as a data strucutre alien_0 = {'color': 'green', 'points': 5} #print(alien_0['color']) #print(alien_0['points']) #new_points = alien_0['points'] #print("You just earned " + str(new_points) + " points.") #Adding new...
true
6b6c88029116d4f5de407c8c8640345bdadb10bb
PajamaProgrammer/Python_MIT-6.00_Problem-Set-Solutions
/Problem Set 2/ps2b.py
2,303
4.15625
4
# Problem Set 2 (Part 4) # Name: Pajama Programmer # Date: 28-Oct-2015 # """ Problem4. Assume that the variable packages is bound to a tuple of length 3, the values of which specify the sizes of the packages, ordered from smallest to largest. Write a program that uses exhaustive search to find the largest number (less ...
true
2352cc95d3464d4a7f6a7f01781d9de1278b0113
UddeshJain/Master-Computer-Science
/Data_Structure/Python/Stack.py
1,262
4.34375
4
class Stack(object): ''' class to represent a stack Implemented with an array ''' def __init__(self): ''' Constructor ''' self.datas = [] def __str__(self): return " ".join(str(e) for e in reversed(self.datas)) def size(self): ...
true
e8faa90b2c9b3ee9a1d694bb6a236e80cbd27733
missystem/math-crypto
/mathfxn.py
790
4.53125
5
""" Authors: Missy Shi Date: 05/22/2020 Python Version: 3.8.1 Functions: - largest_prime_factor Find the largest prime factor of a number - prime_factors Given a integer, return a set of factors of the number """ import math def largest_prime_factor(n: int) -> int: """ Return largest prime factor of num...
true
682d25a675d2b58c48c7359774378ae921405b24
missystem/math-crypto
/prime.py
1,155
4.21875
4
""" Author: Missy Shi Course: math 458 Date: 04/23/2020 Project: A3 - 1 Description: Write a Python function which, given n, returns a list of all the primes less than n. There should be 25 primes less than 100, for instance. Task: How many prime numbers are there which are less than 367400? """ i...
true
cea5559f924ca0ec895074ca5898c96fc003bc74
sahilkumar4all/HMRTraining
/Day-5/calc_final.py
380
4.125
4
def calc(operator): z = eval(x+operator+y) print(z) print(''' Press 1 for addition press 2 for substraction press 3 for multiplication press 4 for division''') x = input("enter first no") y = input("enter second no") choice = input("enter operation you wanna perform") dict = {"1":"+", "2":"-", ...
true
cc669352fa7f30b87d40343ab529635289a35884
Miguelmargar/file-io
/writefile.py
698
4.125
4
f = open("newfile.txt", "a") # opens and creates file called newfile.txt to write on it with "w" - if using "a" it means append not create new or re-write f.write("\nHello World\n") # writes Hello on the file opened above - depending on where you use the \n the lines will brake accor...
true
a153c0f74861ec3c8c786b7b5d9b379331904612
cheeseaddict/think-python
/chapter-6/exercise-6.2.py
667
4.25
4
import math def distance(x1, y1, x2, y2): dx = x2 - x1 dy = y2 - y1 dsquared = dx**2 + dy**2 result = math.sqrt(dsquared) return result print(distance(1,2,4,6)) """ As an exercise, use incremental development to write a function called hypotenuse that returns the length of the hypotenuse of a r...
true
3d045213ec7cc8711783ec2e6be8eeedf4ebf6c2
FrankchingKang/phrasehunter
/phrasehunter/character.py
1,774
4.125
4
# Create your Character class logic in here. class Character(object): """The class should include an initializer or def __init__ that receives a char parameter, which should be a single character string.""" def __init__(self,char): """An instance attribute to store the single char string character so...
true
898ed9b37e512dca37848a040ff175ce57b65e08
mverleg/bardeen
/bardeen/inout.py
2,011
4.15625
4
""" Routines related to text input/output """ import sys, os def clear_stdout(lines = 1, stream = sys.stdout, flush = True): """ Uses escape characters to move back number of lines and empty them To write something on the empty lines, use :func:sys.stdout.write() and :func:sys.stdout.flush() :param lines: the...
true
c824029a5d1ef7317bb98bd39f623292fd392d71
ms-shakil/Some_problems_with_solve
/Extra_Long_Factorial.py.py
401
4.125
4
""" The factorial of the integer n , written n! , is defined as: n! = n * (n-1)*(n-2)*... *2*1 Calculate and print the factorial of a given integer. For example Inp =25 we calculate 25* 24* 23*....*2*1 and we get 15511210043330985984000000 . """ def Factorial(inp): val = 1 for i in range(1,inp): val +...
true
12b784aecca1d4276228b7b7ad13d3cc1d679208
lenncb/safe_password
/main.py
1,319
4.125
4
# This programm will show you how strong your password is # If your password is weak, program will generate new and strong password. # Just write your password import re, password_generator password = input(str('Enter your password: ')) #good password is if it has minimum 8 signs, inculde small and big letters and h...
true
37693a5b038c83a5eae1f13d6bd0540c4852b9ad
navinduJay/interview
/python/sort/insertionSort.py
635
4.34375
4
#INSERTION SORT array = [] #array declaration for everyValue in range(10): array.append(input("Enter number ")) #adding values to the array print('Unsorted array') print(array) def insertionSort(array): #function declaration for j in range(1 , len(array)): # starting index is 1(2nd position) to array lengt...
true
c574d55303bce0e3e99b39777be42153f3c47a7d
minkyaw17/CECS-328
/Lab 5/lab5.py
2,656
4.15625
4
import random import time def swap(arr, a, b): # swap function to be used in the heap sort and selection sort temp = arr[a] arr[a] = arr[b] arr[b] = temp def max_heapify(arr, i, n): # parameter n for length of array max_element = i left = (2 * i) + 1 right = (2 * i) + 2 max_element = ...
true
589aada2ad71b067e9602780edd62c7e540169db
carlosmertens/Python-Masterclass
/challenge_control_flow.py
1,456
4.34375
4
# Complete Python MasterClass Course # # This challenge is intended to practise for loops and if/else statements, # so although you could use other techniques (such as splitting the string up), # that's not the approach we're looking for here. # # Create a program that takes an IP address entered at the keyboard and pr...
true
ee6e9248a17fc4ec2426cebf57ec9404dea28955
ardaunal4/My_Python_Lessons
/ClassPython/example_of_properties_of_classes.py
1,459
4.21875
4
# -*- coding: utf-8 -*- """ Created on Wed May 27 02:35:30 2020 @author: ardau """ from abc import ABC, abstractmethod from cmath import pi class shape(ABC): """ Parent class / abstract class example """ # abstract methods @abstractmethod def area(self): pass @...
true
33c1feb36398f075fc0b1d205803ad901e7366d6
ardaunal4/My_Python_Lessons
/ALGORITHMS/Fundemantals of_Python_Questions/questions3.py
723
4.25
4
# How you can convert a sorted list to random from random import shuffle my_list = [0, 1, 2, 3, 4, 5, 6, 7] print("Sorted list : ", my_list) shuffle(my_list) print("Shuffled list : ", my_list) # How you can make sorted list from random list my_list.sort() print("Sorted list : ", my_list) # What are funct...
true
5e2eba80e377a1eb7d2fadfe8c52999605fe8e06
ardaunal4/My_Python_Lessons
/ClassPython/abstract_class.py
488
4.28125
4
from abc import ABC, abstractmethod # abc -> abstract base class class Animal(ABC): #super class @abstractmethod # this makes the class abstract def walk(self): pass def run(self): pass # this abstract class is a kind of template for other sub classes class Bird(A...
true
6421bd469e371aa256b634c344f81c71072ff336
dailycodemode/dailyprogrammer
/Python/034_squareTwoLargest.py
984
4.15625
4
# https://www.reddit.com/r/dailyprogrammer/comments/rmmn8/3312012_challenge_34_easy/ # DAILY CODE MODE def square_two_largest(list): list.sort(reverse=True) return list[0] ** 2 + list[1] ** 2 print(square_two_largest([3,1,2])) # ANSWER BY Should_I_say_this def sumsq(a,b,c): l=[a,b,c] del l[l.index(mi...
true
4a977849536b8afc9d7cce8f715d1359009d14da
rnekadi/CSEE5590_PYTHON_DEEPLEARNING_FALL2018
/ICP3/Source/codon.py
522
4.21875
4
# Program to read DNA Codon Sequence and Split into individual Codon # Fixed Codon Sequence codonseq = 'AAAGGGTTTAAA' # Define List to hold individual Codon codon = [] # Defining function to to fill Codon list def codonlist(seq): if len(seq) % 3 == 0: for i in range(0, len(seq), 3): codo...
true
2d7a2d740143a19d38e290c3dc81e00cafcdeaff
smailmedjadi/jenkins_blueocean
/src/new_functions.py
570
4.1875
4
def bubbleSort(list): for passnum in range(len(list)-1,0,-1): for i in range(passnum): if list[i]>list[i+1]: temp = list[i] list[i] = list[i+1] list[i+1] = temp def insertionSort(list): for index in range(1,len(list)): currentv...
true
0ec2e9f2fcb36f32ae4220b6f35fa96529a2af30
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/sum_2_binary_numbers_without_converting_to_integer.py
1,784
4.21875
4
# Task: # # Given two binary numbers represented as strings, return the sum of the two binary numbers as a new binary represented # as a string. Do this without converting the whole binary string into an integer. # # Here's an example and some starter code. # # def sum_binary(bin1, bin2): # # Fill this in. # # print(...
true
480dd41bb1dfde38741970333c6442df17dd944a
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/sort_array_with_three_values_in_place.py
2,376
4.25
4
# Task: # # Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are # adjacent, with the colors in the order red, white and blue. # # Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. # # Note: You are not supp...
true
96002e94186bdfef6a04951c5b99d55e21bb9d00
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/find_first_recurring_character.py
1,231
4.125
4
# Task: # # Given a string, return the first recurring letter that appears. If there are no recurring letters, return None. # # Example: # # Input: qwertty # Output: t # # Input: qwerty # Output: None # # Here's some starter code: # # def first_recurring_char(s): # # Fill this in. # # print(first_recurring_char('qwer...
true
04269da9800ce546e8c89a5d9cba8b74b102e05d
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/swap_every_two_nodes_in_linked_list.py
1,632
4.15625
4
# Task: # # Given a linked list, swap the position of the 1st and 2nd node, then swap the position of the 3rd and 4th node etc. # # Here's some starter code: # # class Node: # def __init__(self, value, next=None): # self.value = value # self.next = next # # def __repr__(self): # return f"{self.value}, (...
true
cc2d33ae78495714b158947820c819a25734ed64
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/find_shortest_distance_of_characters_to_given_character.py
1,560
4.15625
4
# Task: # # Given a string s and a character c, find the distance for all characters in the string to the character c in # the string s. You can assume that the character c will appear at least once in the string. # # Here's an example and some starter code: # # def shortest_dist(s, c): # # Fill this in. # # print(sh...
true
1dc29418a4324e658afdddbabd372c2dbe9ae97c
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/find_characters_appearing_in_all_strings.py
862
4.15625
4
# Task: # # Given a list of strings, find the list of characters that appear in all strings. # # Here's an example and some starter code: # # def common_characters(strs): # # Fill this in. # # print(common_characters(['google', 'facebook', 'youtube'])) # # ['e', 'o'] from typing import List, Set def find_characters...
true
9e6ca28b0657297cd3223daef3a3fb6eee2e0ec9
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/reverse_integer_without_converting_it_to_string.py
677
4.3125
4
# Task: # # Given an integer, reverse the digits. Do not convert the integer into a string and reverse it. # # Here's some examples and some starter code. # # def reverse_integer(num): # # Fill this in. # # print(reverse_integer(135)) # # 531 # # print(reverse_integer(-321)) # # -123 from math import floor def reve...
true
d720bec8f8a39a08d7eba61fb7006042e54394e8
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/reverse_binary_representation_of_integer.py
980
4.15625
4
# Task: # # Given a 32 bit integer, reverse the bits and return that number. # # Example: # # Input: 1234 # # In bits this would be 0000 0000 0000 0000 0000 0100 1101 0010 # Output: 1260388352 # # Reversed bits is 0100 1011 0010 0000 0000 0000 0000 0000 # # Here's some starter code: # # def to_bits(n): # return '{0:0...
true
9e1f8ae86d4092c5105f8ab43ff0356c00777fea
Sandeep8447/interview_puzzles
/src/main/python/com/skalicky/python/interviewpuzzles/search_in_matrix_with_sorted_elements.py
2,075
4.25
4
# Task: # # Given a matrix that is organized such that the numbers will always be sorted left to right, and the first number of # each row will always be greater than the last element of the last row (mat[i][0] > mat[i - 1][-1]), search for # a specific value in the matrix and return whether it exists. # # Here's an ex...
true
8a5fcc17e24a57d5783b8f91a7a41f480171d9c3
ksu-is/Hotel-Python
/hotelpython2.py
1,949
4.125
4
print("Welcome to Hotel Python!") print("\t\t 1 Booking") print("\t\t 2 Payment") print("\t\t 3 Guest Requests") print("\t\t 4 Exit") reservation=" " payment=" " payment_method=" " requests=" " def guest_info(reservation="A"): print("Please collect guest information such as name, phone number, and dates of stay")...
true
ce09f1c9ebded1b1b2716f017583dea3d4cf5a23
rfaroul/Activities
/Week03/3/lists.py
1,601
4.28125
4
prices = ["24","13","16000","1400"] price_nums = [int(price) for price in prices] print(prices) print(price_nums) dog = "poodle" letters = [letter for letter in dog] print(letters) print(f"We iterate over a string into a list: {letters}") capital_letters = [letter.upper() for letter in letters] print(capital_letters)...
true
131f1147267852294f9674c7b6883c1f5f580d7d
minhazalam/py
/data_collectn_and_processing/week_1/nested_iteration.py
443
4.5
4
# In this program we'll implement the nested iteration concepts using # * two for loops # * one loop and a square bracket(indexing) # * indexing(square bracket) and a for loop # nested list nested1 = [1, 2, ['a', 'b', 'c'],['d', 'e'],['f', 'g', 'h']] # iterate for x in nested1: # outer loop print("level1: ")...
true
4448b46aeb6c9ba1ea874f52aa7a0a8a10c761d7
minhazalam/py
/class_inheritance/inheritance/inheritance.py
827
4.28125
4
# Intro : Inheritance in python 3 # current year CURRENT_YEAR = 2020 # base class class Person: # constructor def __init__(self, name, year_born): self.name= name self.year_born = year_born # def methods def get_age(self): return CURRENT_YEAR - self.year_born # def _...
true
b2677a1cee82e3f2a851f604804f276131f63d75
minhazalam/py
/class_inheritance/exceptions/try_exception.py
554
4.15625
4
# we'll see how this try and exception works in the python 3 programming language # syntax : # try: # <try clause code block> # except <ErrorType>: # <exception handler code block> # def square(num): # return num * num # # assertion testingg # assert square(3) == 9 # try and except block of statement a_...
true
8c44c1692f9091b3290f50c23ee3529888b606db
adam-worley/com404
/1-basics/5-functions/4-loop/bot.py
271
4.125
4
def cross_bridge (steps): x = 0 while (steps>0): print("Crossed step") steps = (steps-1) x = x+1 if (x>=5): print("The bridge is collapsing!") else: print("we must keep going") cross_bridge(3) cross_bridge(6)
true
0a7343306387e4f6c326a8bec187da13dc2c45ed
adam-worley/com404
/1-basics/6-mocktca/1-minimumtca/Q2.py
255
4.125
4
print("Where is Forky?") forky_location=str(input()) if (forky_location=="With Bonnie"): print("Phew! Bonnie will be happy.") elif(forky_location=="Running away"): print ("Oh no! Bonnie will be upset!") else: print("Ah! I better look for him")
true
637abb15832ba8ebafa8e90d958df4ea05d3b236
keshavkummari/KT_PYTHON_6AM_June19
/Functions/Overview_Of_Functions.py
1,347
4.25
4
# Functions in Python # 1. def # 2. Function Name # 3. Open & Close Paranthesis and Parameters # 4. Colon : Suit # 5. Indented # 6. return statement - Exits a Function """ def function_name(parameters): function_suite return [expression] def sum(var1,var2): total = var1 + var2 print(total) retu...
true
cfbba32a8f869a1f9afaba9381382611f70c789a
MompuPupu/ProjectEuler
/Problems 1 - 10/Problem 1.py
516
4.5
4
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. # Find the sum of all the multiples of 3 or 5 below 1000. def determine_if_multiple_of_3_or_5(number): """Return whether the number is a multiple of 3 or 5. """ if number % 3 == 0 or n...
true
ffd4583fc2f7498e36d5f9bd8fa7162c08295439
MompuPupu/ProjectEuler
/Problems 1 - 10/Problem 4.py
1,154
4.34375
4
# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers # is 9009 = 91 × 99. # Find the largest palindrome made from the product of two 3-digit numbers. import math def check_for_palindrome(num): # loads the number into an array of characters digit_list...
true
ee164fea12b17eb34cf532481c77e93bd91a2313
nda11/CS0008-f2016
/ch5/ch5,ex3.py
1,064
4.375
4
# name : Nabil Alhassani # email : nda11@pitt.edu # date :septemper/11th # class : CS0008-f2016 # instructor : Max Novelli (man8@pitt.edu) # Description:Starting with Python, Chapter 2, # Notes: # any notes to the instructor and/or TA goes here # ...and now let's program with Python # exercise 3 # Many financial exper...
true
81d1b25c60fd7043a49fb43f2cb4c808c4d21a86
nda11/CS0008-f2016
/ch2.py/ch2-ex3 bis.py
442
4.25
4
# Exercise : ch2-ex3 #This program asks the user to enter the total square meters of land and calculates the number of #acres in the tract. #set one_acre value and one_acre= 4,046.8564224**2 one_square_meter= 0.000247105 #input square_meter square_meter=float(input('enter the total square meters:',)) # calculation th...
true
2f3cf52da18ad63dcd6a9cec6710b3b1b15f1e9f
Victor-Bonnin/git-tutorial-rattrapages
/guessing_game.py
1,300
4.375
4
#! /usr/bin/python3 # The random package is needed to choose a random number import random # Define the game in a function def guess_loop(): # This is the number the user will have to guess, chosen randomly in between 1 and 100 number_to_guess = random.randint(1, 100) name = input("Write your name:...
true
3759e1450a801809bb2b00bcbf17d8ab474054a4
nagalr/algo_practice
/src/main/Python/Sort/insertion_sort.py
565
4.15625
4
def insertion_sort(l): """ Insertion Sort Implementation. Time O(n^2) run. O(1) space complexity. :param l: List :return: None, orders in place. """ # finds the next item to insert for i in range(1, len(l)): if l[i] < l[i - 1]: item = l[i] # moves the...
true
15e3ed05dc5919e6a86fe26cd62e6fff05e65209
wulfebw/algorithms
/scripts/probability_statistics/biased_random.py
2,057
4.25
4
""" :keywords: probability, biased, random """ import random def biased_random(p=.1): """ :description: returns 1 with p probability and 0 o/w """ if random.random() < p: return 1 return 0 def unbiased_random(): """ :description: uses a biased random sampling with unknown bias to ...
true
914c9007a4dbf898d7d84bcdf477dc00b5a43d89
JingYiTeo/Python-Practical-2
/Q08_top2_scores.py
567
4.15625
4
NStudents = int(input("Please Enter Number of Students: ")) Names = [] Scores = [] for i in range(NStudents): Name = str(input("Please enter Name: ")) Score = int(input("Please enter Score: ")) Names.append(Name) Scores.append(Score) Scores, Names = (list(t) for t in zip(*sorted(zip(Scor...
true
ab7a5601210b13fd049b859d96aa0e25c1f6df0e
Soreasan/Python
/MoreList.py
1,135
4.4375
4
#!/usr/bin/env python3 #We can create a list from a string using the split() method w = "the quick brown fox jumps over the lazy dog".split() print(w) #We can search for a value like this which returns the index it's at i = w.index('fox') print(i) print(w[i]) #w.index('unicorn') #Error #You can check for membership wi...
true
e6b4587b69e39a7e1bdbeb7befc1cd064ef1cb35
Ankitpahuja/LearnPython3.6
/Lab Assignments/Lab06 - Comprehensions,Zip/Q1.py
886
4.75
5
# Create a text file containing lot of numbers in float form. The numbers may be on separate lines and there may be several numbers on same line as well. We have to read this file, and generate a list by comprehension that contains all the float values as elements. After the data has been loaded, display the total numb...
true
6486f929c5adccc0980dc26db652e9358c001754
Ankitpahuja/LearnPython3.6
/Lab Assignments/Lab05 - RegEX/ppt_assignment.py
673
4.3125
4
''' Write a function that would validate an enrolment number. valid=validateEnrolment(eno ) Example enrolment number U101113FCS498 U-1011-13-F-CS-498 13 – is the year of registration, can be between 00 to 99 CS, EC or BT Last 3 are digits ''' import re pattern = re.compile("U1011[0-9][0-9]F(CS|BT)\d\d\d")...
true
76e97fc42db60802575bb4b9be80a7499298d26e
Ankitpahuja/LearnPython3.6
/Tutorials - Examples/GUI - Tkinter/boilerplate.py
1,170
4.4375
4
import tkinter as tk window = tk.Tk() window.title("Tkinter's Tutorial") window.geometry("550x400") # Label title = tk.Label(text="Hello World. Welcome to tkinter's tutorial!", font=("Times New Roman",20)) title.grid(column=0,row=0) #Button1 button1 = tk.Button(text="Click Me!", bg="red") button1.gri...
true
dfe339423b83149a43710cbf6eef8ad51cb9c1e9
pavanvittanala/Coding_programs
/uniformity.py
1,475
4.15625
4
''' ----->>>>> PROBLEM STATEMENT <<<<<----- ''' ''' You are given a string that is formed from only three characters ‘a’, ‘b’, ‘c’. You are allowed to change atmost ‘k’ characters in the given string while attempting to optimize the uniformity index. Note : The uniform...
true
eccaf13f1f46e435b9547ecffe26c55e63108852
atseng202/ic_problems
/queues_and_stacks/queue_with_two_stacks/queue_two_stacks.py
1,371
4.125
4
class Stack(object): def __init__(self): # """Initialize an empty stack""" self.items = [] def push(self, item): # """Push a new item onto the stack""" self.items.append(item) def pop(self): # """Remove and return the last item""" # If the stack is empty, return None # (it would also be reasonable to thr...
true