blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
af771a30f93a4382dacfb04e423ad01dd96b3160 | zaincbs/PYTECH | /filter_long_words_using_filter.py | 561 | 4.25 | 4 | #!/usr/bin/env python
"""
Using the higher order function filter(), define a function
filter_long_words() that takes a list of words and an
integer n and returns the list of words that are longer
than n.
"""
def filter_long_words(l,n):
return filter(lambda word: len(word) > n, l)
def main():
list_with_len_of... | true |
528bb5e90b48a7b741e96c7df0ffe0905534df39 | zaincbs/PYTECH | /readlines.py | 1,420 | 4.125 | 4 | #!/usr/bin/env python
"""
I am making a function that prints file in reverse order and then reverses
the order of the words
"""
import sys
def readFile(filename):
rorder = ''
opposed = ''
finale= ''
inline = ''
#reading file line by line
#with open(filename) as f:
# lines = f.readline... | true |
597368b52b65f2cf0b6a61a78ec076f6ff925432 | AlanFermat/leetcode | /linkedList/707 designList.py | 2,691 | 4.53125 | 5 | """
Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node. If you want to use the doubly linked... | true |
8f967f1220a5b1dbf211c5360d99c479fb522383 | tskillian/Programming-Challenges | /N-divisible digits.py | 939 | 4.21875 | 4 | #Write a program that takes two integers, N and M,
#and find the largest integer composed of N-digits
#that is evenly divisible by M. N will always be 1
#or greater, with M being 2 or greater. Note that
#some combinations of N and M will not have a solution.
#Example: if you are given an N of 3 and M of 2, t... | true |
ea96f8e8e0c7a7e1bde8a01c47098036d10799f2 | usmanmalik6364/PythonTextAnalysisFundamentals | /ReadWriteTextFiles.py | 1,111 | 4.5 | 4 | # python has a built in function called open which can be used to open files.
myfile = open('test.txt')
content = myfile.read() # this function will read the file.
# resets the cursor back to beginning of text file so we can read it again.
myfile.seek(0)
print(content)
content = myfile.readlines()
myfile.seek(0)
fo... | true |
ce51c27893b378bd6abb314ad4926e17637c6228 | SmischenkoB/campus_2018_python | /Dmytro_Shalimov/1/9.py | 2,110 | 4.3125 | 4 | <<<<<<< HEAD
print("Convert a 24-hour time to a 12-hour time.")
print("Time must be validated.")
user_input = input("Enter time: ")
formatted_time = str()
if len(user_input) != 5:
print("not valid time")
hours = user_input[:2]
minutes = user_input[3:]
if hours.isnumeric() and minutes.isnumeric():
hou... | true |
425c4137611ae13aee9d24a486040bc9e565edd8 | SmischenkoB/campus_2018_python | /Dmytro_Skorobohatskyi/batch_3/verify_brackets.py | 1,004 | 4.3125 | 4 | def verify_brackets(string):
""" Function verify closing of brackets, parentheses, braces.
Args:
string(str): a string containing brackets [], braces {},
parentheses (), or any combination thereof
Returns:
bool: Return True if all brackets are closed, otherwise... | true |
92cbac43042872e865e36942ce164e1d5fdb0d40 | SmischenkoB/campus_2018_python | /Kyrylo_Yeremenko/2/task7.py | 2,517 | 4.21875 | 4 | """
This script solves task 2.7 from Coding Campus 2018 Python course
(Run length encoding)
"""
def write_char_to_list(last_character, character_count):
"""
Convenience function to form character and count pairs for RLE encode
:param last_character: Character occurred on previous iteration
:... | true |
c955386992b1cf118dd6b8c1ffb792c98a12012e | SmischenkoB/campus_2018_python | /Dmytro_Shalimov/1/8.py | 1,062 | 4.125 | 4 | <<<<<<< HEAD
print("Validate a 24 hours time string.")
user_input = input("Enter time: ")
if len(user_input) != 5:
print(False)
hours = user_input[:2]
minutes = user_input[3:]
if hours.isnumeric() and minutes.isnumeric():
hours_in_int = int(hours)
minutes_in_int = int(minutes)
if hours_in_... | true |
92295f2ad2b0ed8ff4d35474780dba9dc88e16e5 | SmischenkoB/campus_2018_python | /Kateryna_Liukina/3/3.5 Verify brackets.py | 766 | 4.25 | 4 | def verify_brackets(string):
"""
Function verify brackets
Args:
string(str): string to verify brackets
Returns:
bool: return true if all brackets are closed and are in right order
"""
brackets_opening = ('(', '[', '{')
brackets_closing = (')', ']', '}')
brackets_dict = di... | true |
2d9d5ecb3a53c62da62052da5f849c71384a0300 | SmischenkoB/campus_2018_python | /Mykola_Horetskyi/3/Crypto Square.py | 1,074 | 4.125 | 4 | import math
def encode(string):
"""
Encodes string with crypto square method
Args:
string (str) string to be encoded
Returns:
(str) encoded string
"""
encoded_string = "".join([character.lower() for character in string
if character.isalpha()])
... | true |
e63105840c53f6e3ea05835cb8a67afe38e741cc | SmischenkoB/campus_2018_python | /Lilia_Panchenko/1/Task7.py | 643 | 4.25 | 4 | import string
input_str = input('Your message: ')
for_question = 'Sure.'
for_yelling = 'Whoa, chill out!'
for_yelling_question = "Calm down, I know what I'm doing!"
for_saying_anything = 'Fine. Be that way!'
whatever = 'Whatever.'
is_question = False
if ('?' in input_str):
is_question = True
is_yelling = True
ha... | true |
3f2039d4698f8b153ef13deaee6ec80e266dae3c | SmischenkoB/campus_2018_python | /Yurii_Smazhnyi/2/FindTheOddInt.py | 402 | 4.21875 | 4 | def find_odd_int(sequence):
"""
Finds and returns first number that entries odd count of times
@param sequence: sequnce to search in
@returns: first number that entries odd count of times
"""
for i in sequence:
int_count = sequence.count(i)
if int_count % 2:
retu... | true |
5fbf80dd6b1bc1268272eb9e79c6c6e792dcc680 | SmischenkoB/campus_2018_python | /Tihran_Katolikian/2/CustomMap.py | 606 | 4.3125 | 4 | def custom_map(func, *iterables):
"""
Invokes func passing as arguments tuples made from *iterables argument.
:param func: a function which expects len(*iterables) number of arguments
:param *iterables: any number of iterables
:return: list filled with results returned by func argument. length of l... | true |
03cd271429808ad9cf1ca520f8463a99e91c9321 | SmischenkoB/campus_2018_python | /Tihran_Katolikian/2/FindTheOddInt.py | 1,183 | 4.375 | 4 | def find_odd_in_one_way(list_of_numbers):
"""
Finds an integer that present in the list_of_number odd number of times
This function works as efficient as possible for this task
:param list_of_numbers: a list of integers in which must be at least one integer
which has odd number of copies there
... | true |
a19c8d2bf61250e9789f95a202f86dafbe371166 | SmischenkoB/campus_2018_python | /Ruslan_Neshta/3/VerifyBrackets.py | 897 | 4.3125 | 4 | def verify(string):
"""
Verifies brackets, braces and parentheses
:param string: text
:return: is brackets/braces/parentheses matched
:rtype: bool
"""
stack = []
is_valid = True
for ch in string:
if ch == '(' or ch == '[' or ch == '{':
stack.append(ch)
... | true |
6855d88767abbe577f76e8263f5b1ec6aa9a6dee | SmischenkoB/campus_2018_python | /Dmytro_Skorobohatskyi/2/armstrong_numbers.py | 917 | 4.125 | 4 | def amount_digits(number):
""" Function recognize amount of digit in number.
Args:
number(int): specified number
Returns:
int: amount of digits in number
"""
counter = 0
while number != 0:
counter += 1
number //= 10
return counter
def chec... | true |
9879e700bccb8329e9a1b5e5ddca71abfb0aa7ba | SmischenkoB/campus_2018_python | /Dmytro_Shalimov/2/1.py | 1,338 | 4.4375 | 4 | from collections import Counter
print("Given an array, find the int that appears an odd number of times.")
print("There will always be only one integer that appears an odd number of times.")
print("Do it in 3 different ways (create a separate function for each solution).")
def find_odd_number_1(sequence):
... | true |
3c2510888352bd0867e04bf557b473af4b4ecfa9 | SmischenkoB/campus_2018_python | /Kyrylo_Yeremenko/3/task5.py | 858 | 4.46875 | 4 | """
This script solves task 3.5 from Coding Campus 2018 Python course
(Verify brackets)
"""
brackets = \
{
'{': '}',
'[': ']',
'(': ')'
}
def verify_brackets(string):
"""
Verify that all brackets in string are paired and matched correctly
:param string: Inp... | true |
c45867f3199dbb730ae4764ece11d7a4742af826 | walton0193/cti110 | /P3HW2_BasicMath_WaltonKenneth.py | 1,198 | 4.1875 | 4 | #This program is a calculator
#It performs basic math operations
#CTI - 110
#P3HW2 - BasicMath
#Kenneth Walton
#17 March 2020
def add(number1, number2):
return number1 + number2
def subtract(number1, number2):
return number1 - number2
def multiply(number1, number2):
return number1 * number2
pr... | true |
b0c99ad473d14d8488a904db839ca328c1cceb1d | Patricia-Henry/tip-calculator-in-python- | /tip_calculator_final.py | 440 | 4.28125 | 4 | print("Welcome to the Tip Calculator")
bill_total = float(input("What was the bill total? $"))
print(bill_total)
tip = int(input("How much of a tip do you wish to leave? 10, 12, 15 \n"))
people_eating = int(input("How many people are splitting the bill?"))
percentage_tip = tip / 100
tip_amount = bill_total * ... | true |
28fcd79f93af5e8516506dcb1402152ff26b9cfb | samdoty/smor-gas-bord | /morty.py | 995 | 4.28125 | 4 | # If you run this there is a bunch of intro stuff that will print
a = 10
print(a + a)
my_income = 100
tax_rate = 0.1
my_taxes = my_income * tax_rate
print(my_taxes)
print('hello \nworld')
print('hello \tworld')
print(len('hello'))
print(len('I am'))
mystring = "Hello World"
print(mystring[2])
print(mystrin... | true |
d928744c32bde2b1aa046090a2fac343b2faf10d | SallyM/implemented_algorithms | /merge_sort.py | 1,458 | 4.1875 | 4 | def merge_sort(input_list):
# splitting original list in half, then each part in half thru recursion
# until left and right are each one-element lists
if len(input_list) > 1:
# print 'len(input_list)= {}'.format(len(input_list))
split = len(input_list)//2
left = input_list[: split]
... | true |
6f74a09eb4b76315055d796874feeb993514e8f7 | USFMumaAnalyticsTeam/Kattis | /Autori.py | 590 | 4.1875 | 4 | # This python code is meant to take a single string that is in a
# long naming variation (ex. Apple-Boy-Cat) and change it
# to a short variation (ex. ABC)
import sys
# Receive user input as string
long_var = input()
# Verify user input is no more than 100 characters
if (long_var.count('') > 100):
sys.e... | true |
e9c7187e3f56e6bd0dd46ac18c0ff70b879eb0b0 | sahilshah1/algorithm-impls | /course_schedule_ii.py | 2,497 | 4.15625 | 4 | # There are a total of n courses you have to take, labeled from 0 to n - 1.
#
# Some courses may have prerequisites, for example to take course 0 you have
# to first take course 1, which is expressed as a pair: [0,1]
#
# Given the total number of courses and a list of prerequisite pairs,
# return the ordering of course... | true |
52d0586ed3cdbe18346e70d45883b74ec929e6c7 | pavankalyannv/Python3-Problems | /HackerRank.py | 1,718 | 4.34375 | 4 | Problme: @HackerRank
==========
Given the names and grades for each student in a Physics class of students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.
Note: If there are multiple students with the same grade, order their names alphabetically and print each name... | true |
944f2a67f38f40370b64c9e97914e355009b9c6b | lixuanhong/LeetCode | /LongestSubstring.py | 979 | 4.15625 | 4 | """
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substri... | true |
df7978f0c6a2f0959ecf5ead00a2d05f18325b10 | gauravdhmj/Project | /if programfile.py | 2,761 | 4.1875 | 4 | name = input("please enter your name:")
age = input("How old are you, {0}".format(name))
age = int(input("how old are you, {0}".format(name)))
print(age)
# USE OF IF SYNTAX
if age >= 18:
print("you are old enough to vote")
print("please put an x in the ballot box")
else:
print("please come back aft... | true |
bdf2b0fe68c75b4e9c5fe1c1173ebd19fa8cf5ff | CHS-computer-science-2/python2ChatBot | /chatBot1.py | 808 | 4.40625 | 4 | #This is the starter code for the Chatbot
# <Your Name Here>
#This is a chatbot and this is a comment, not executed by the program
#Extend it to make the computer ask for your favorite movie and respond accordingly!
def main():
print('Hello this is your computer...what is your favorite number?')
#Declaring our... | true |
a66ee557c0557d6dfe61852771995e3143b74022 | thatdruth/Drew-Lewis-FinalCode | /ExponentFunction.py | 247 | 4.40625 | 4 |
print(3**3) #Easy exponent
def raise_to_power(base_num, pow_num):
result = 1
for index in range(pow_num):
result = result * base_num
return result
print(raise_to_power(4,3)) #A coded loop exponent function
| true |
f97a33df94c0b8bf5424a74bef1d7cc584b7bfb7 | GabrielDaKing/Amateur_ML | /amateur_ml/regression/linear.py | 1,448 | 4.34375 | 4 | class Linear:
"""
A class to handle the basic training and pridiction capability
of a Linear Regression model while storing the slope and intercept.
"""
def __init__(self):
self.slope = 0
self.intercept = 0
def fit(self, x, y):
"""
A function to set the slope a... | true |
ef7fc6de72d7f28fe6dacb3ad4c2edfcebce3d3d | kiranrraj/100Days_Of_Coding | /Day_59/delete_elemt_linked_list_frnt_back.py | 1,971 | 4.375 | 4 | # Title : Linked list :- delete element at front and back of a list
# Author : Kiran raj R.
# Date : 30:10:2020
class Node:
"""Create a node with value provided, the pointer to next is set to None"""
def __init__(self, value):
self.value = value
self.next = None
class Simply_linked_list:
... | true |
854616d109a06681b8765657cb5ba0e47689484f | kiranrraj/100Days_Of_Coding | /Day_12/dict_into_list.py | 537 | 4.15625 | 4 | # Title : Convert dictionary key and values into a new list
# Author : Kiran raj R.
# Date : 26:10:2020
# method 1 using dict.keys() and dict.values()
main_dict = {'a': 'apple', 'b': 'ball',
'c': 'cat', 'd': 'dog', 'e': 'elephant'}
list_keys = list(main_dict.keys())
list_values = list(main_dict.values... | true |
19ea68c556c52b616ab33e76b24e779a21a8bc08 | kiranrraj/100Days_Of_Coding | /Day_7/count_items_string.py | 998 | 4.1875 | 4 | # Title : Find the number of upper, lower, numbers in a string
# Author : Kiran raj R.
# Date : 21:10:2020
import string
def count_items(words):
word_list = words.split()
upper_count = lower_count = num_count = special_count = 0
length_wo_space = 0
for word in words:
word = word.rstrip()... | true |
ec074f7136a4a786840144495d61960430c61c1c | kiranrraj/100Days_Of_Coding | /Day_26/linked_list_insert.py | 1,340 | 4.125 | 4 | # Title : Linked list insert element
# Author : Kiran Raj R.
# Date : 09:11:2020
class Node:
def __init__(self,data):
self.next = None
self.data = data
class LinkedList:
def __init__(self):
self.head = None
def print_list(self):
start = self.head
while start:
... | true |
25ee94661cc1cce075df1356cbd9e9c76c9eb2be | kiranrraj/100Days_Of_Coding | /Day_47/check_tri_angle.py | 402 | 4.21875 | 4 | # Title : Triangle or not
# Author : Kiran Raj R.
# Date : 30/11/2020
angles = []
total = 0
for i in range(3):
val = float(input(f"Enter the angle of side {i}: "))
angles.append(val)
total = sum(angles);
# print(total)
if total == 180 and angles[0] != 0 and angles[1] != 0 and angles[2] != 0:
print("Va... | true |
13917f87c5fd24ee4f0f90bc0d5152aa2dccce83 | priyankaVi/Python | /challenge 3 #strings.py | 1,983 | 4.4375 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
###challenge3 STRINGSabs
# In[ ]:
020
## Ask the user to enter their first name
##and then display the length of their name
# In[2]:
user=input("nter the first name")
len(user)
# In[ ]:
021
#Ask the user to enter their first name
#and then ask t... | true |
dfa353728f27230e57cde4ea7d3ed84d0746527a | ramlaxman/Interview_Practice | /Strings/reverse_string.py | 548 | 4.21875 | 4 | # Reverse a String iteratively and recursively
def reverse_iteratively(string):
new_string = str()
for char in reversed(string):
new_string += char
return new_string
def test_reverse_iteratively():
assert reverse_iteratively('whats up') == 'pu stahw'
def reverse_recursively(string):
prin... | true |
d516b1c2b45bf8145759ba5ae676f24c1c7384ce | ahmad-elkhawaldeh/ICS3U-Unit-4-03-python | /loop3.py | 779 | 4.5 | 4 | #!/usr/bin/env python3
# Created by: Ahmad El-khawaldeh
# Created on: Dec 2020
# a program that accepts a positive integer;
# then calculates the square (power of 2) of each integer from 0 to this number
def main():
# input
positive_integer = print(" Enter how many times to repeat ")
positive_string = ... | true |
c0c7507d3d351d1cdd4dff4624acef7f54b4b52f | bikash-das/pythonprograms | /practice/check_list.py | 1,293 | 4.21875 | 4 | def is_part_of_series(lst):
'''
:param: lst - input is the set of integers (list)
:output: returns true if the list is a part of the series defined by the following.
f(0) = 0 f(1) = 1 f(n) = 2*f(n-1) - 2*f(n-2) for all n > 1.
'''
assert(len(lst) > 0)
if(lst[0] != 0):... | true |
3ad3950e0d0b1cef1791b7563714f3ffec93d4ac | bikash-das/pythonprograms | /tkinter/ch-1/clickEvent2.py | 761 | 4.3125 | 4 | import tkinter as tk
from tkinter import ttk
# create an instance of window (tk)
win = tk.Tk() # creates an empty window
# action for button click
def click():
btn.configure(text = "Hello " + name.get()) # get() to retrive the name from the text field
# create a Label
ttk.Label(win, text = "Enter a name: ").... | true |
5e9c092473f6f2e780979df5f11b74d30db9d346 | bikash-das/pythonprograms | /ds/linkedlist.py | 1,233 | 4.15625 | 4 | class node:
def __init__(self,data):
self.value = data
self.next=None;
class LinkedList:
def __init__(self):
self.start = None;
def insert_last(self,value):
newNode = node(value)
if(self.start == None):
self.start = newNode;
else:
... | true |
ff983f0996b4abffdfa420f9449f95aa47097011 | xXPinguLordXx/py4e | /exer11.py | 234 | 4.125 | 4 | def count (word, char):
char_count = 0
for c in word:
if c == char:
char_count += 1
return char_count # occurences
inp_word = input ("Enter word: ")
inp_char = input ("Enter char: ")
print (count)
| true |
2b2260baa8a63839a1d3feeabfc645cf52ef7761 | xXPinguLordXx/py4e | /exer8.py | 768 | 4.28125 | 4 | #declare this shit outside the loop because if you put it inside it will just get looped forever
#declare this outside so that it is accessible by the entire program outside and not just within the loop
sum = 0
count = 0
while True:
number = input ("Enter a number: ")
if number == 'done':
break
tr... | true |
e3d5c813c35e2ba8683d5404fa936e862a7e35f3 | mileuc/breakout | /paddle.py | 725 | 4.1875 | 4 | # step 2: create paddle class
from turtle import Turtle
class Paddle(Turtle): # paddle class is now effectively the same as a Turtle class
def __init__(self, paddle_position):
super().__init__() # enable Turtle methods to be used in Ball class
self.shape("square")
self.color("white")
... | true |
6ff3d2c4c52c4ed4c0543b81eb97a4e59e6babeb | vishalkmr/Algorithm-And-Data-Structure | /Searching/Binary Search(Ascending Order).py | 1,134 | 4.15625 | 4 | '''
Binary Search on Ascending order Lists
Assume that list is in Ascending order
Note : Binary search is aplicable only when list is sorted
'''
def binary_search(list,item):
'''
funtion for binary search of element in list
synatx: binary_search( list,item)
retrun index of element where the item is... | true |
edd37b42b381dfc85b5f443b79e151f7225b9201 | vishalkmr/Algorithm-And-Data-Structure | /Arrays & Strings/Array Pair Sum.py | 2,761 | 4.40625 | 4 | '''
Given an integer array, output all the unique pairs that sum up to a specific value k.
Example
pair_sum([1,2,3,4,5,6,7],7)
Returns: (3, 4), (2, 5), (1, 6)
'''
#using Sorting
def pair_sum(list,k):
'''
Funtion return all the unique pairs of list elements that sum up to k
Syntax: insert(list,k)
Time Complexity... | true |
aba4633ded621a38d9a0dd4a6373a4b70ee335d9 | vishalkmr/Algorithm-And-Data-Structure | /Linked Lists/Rotate Right.py | 1,755 | 4.40625 | 4 | '''
Rotates the linked-list by k in right side
Example:
link-list : 1,2,3,4,5,6
after 2 rotation to right it becomes 5,6,1,2,3,4
'''
from LinkedList import LinkedList
def rotate_right(linked_list,k):
"""
Rotates the linked-list by k in right side
Syntax: rotate_right(linked_list,k)
Time Complex... | true |
bac0d9c2b34bf891722e468c11ff0f615faef1fc | vishalkmr/Algorithm-And-Data-Structure | /Arrays & Strings/Missing element.py | 1,576 | 4.28125 | 4 | '''
Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array
and deleting a random element. Given these two arrays, find which element is missing in the second array.
Example :
The first array is shuffled and the number 5 is removed to construct the second ... | true |
23ad168cebd9f937871f8ef52f0822387308dbc5 | vishalkmr/Algorithm-And-Data-Structure | /Trees/Mirror Image.py | 1,639 | 4.34375 | 4 | '''
Find the Mirror Image of a given Binary tree
Exapmle :
1
/ \
2 3
/ \ / \
4 5 6 7
Mirror Image :
1
/ \
3 2
/ \ / \
7 6 5 4
'''
from TreeNod... | true |
8f8ba9c1a6e13d1527f0c3ac5c2a72dc330a0321 | vishalkmr/Algorithm-And-Data-Structure | /Sorting/Bubble Sort.py | 2,203 | 4.5625 | 5 | '''
SORT the given array using Bubble Sort
Example: Let us take the array of numbers "5 1 4 2 8", and sort the array in ascending order using bubble sort.
First Pass
( 5 1 4 2 8 ) -> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1.
( 1 5 4 2 8 ) -> ( 1 4 5 2 8 ), Swap sin... | true |
30a98b2f034a60422a2faafbd044628cd1011e43 | vishalkmr/Algorithm-And-Data-Structure | /Arrays & Strings/Max and Min(Recursion).py | 1,108 | 4.40625 | 4 | '''
Find the maximum and minimum element in the given list using Recursion
Example
max_min([11,-2,3,6,14,8,16,10])
Returns: (-2, 16)
'''
def max_min(list,index,minimum,maximum):
'''
Funtion to return maximum and minimum element in the given list
Syntax: max_min(list,index,minimum,maximum)
Time Complexity: O... | true |
4106cc2dccfacb7322a9e00a440321b30d224e30 | vishalkmr/Algorithm-And-Data-Structure | /Searching/Ternary Search.py | 1,860 | 4.46875 | 4 | '''
Ternary Search on lists
Assume that list is already in Ascending order.
The number of Recursive Calls and Recisrion Stack Depth is lesser for Ternary Search as compared to Binary Search
'''
def ternary_search(list,lower,upper,item):
'''
Funtion for binary search of element in list
Synatx: ternary_search... | true |
29c60efe0b91a9c74c2eebe4d9ce599a8c52ba7f | vishalkmr/Algorithm-And-Data-Structure | /Linked Lists/Cyclic.py | 1,733 | 4.21875 | 4 | '''
Check the given limked-list is cyclic or not
'''
from LinkedList import LinkedList
#using Set
def is_cyclic(linked_list):
"""
Returns True if linked-list is cyclic
Syntax: is_cyclic(linked_list)
Time Complexity: O(n)
"""
# if linked-list is empty
if not linked_list.hea... | true |
967ac148b13a59295b9c16523e6e046ffd000950 | PdxCodeGuild/Full-Stack-Day-Class | /practice/solutions/ttt-interface/list_board.py | 1,184 | 4.1875 | 4 | """Module containing a list of lists tic-tac-toe board implementation."""
class ListListTTTBoard:
"""Tic-Tac-Toe board that implements storage as a list
of rows, each with three slots.
The following board results in the following data structure.
X| |
|X|O
| |
[
['X', ' ', ' '],... | true |
dcc6eac9a830867df9b8bf1dbc28c592c4458990 | priyankamadhwal/MCA-101-OOP | /14- bubbleSort.py | 1,139 | 4.28125 | 4 | def swap(lst, lowerIndex=0, pos=0):
'''
OBJECTIVE : To swap the elements of list so that the largest element goes at the lower index.
INPUT :
lst : A list of numbers.
lowerIndex : The lower index upto which swapping is to be performed.
OUTPUT : List, with the correct el... | true |
16bc2814112b7bd4fad04457af0ba79ccf21e68a | soumilk91/Algorithms-in-Python | /Mathematical_algorithms/calculate_fibo_number.py | 1,414 | 4.21875 | 4 | """
@ Author : Soumil Kulkarni
This file contains various methods related to problems on FIBO Series
"""
import sys
# Method to calculate the fibo number recursively
def calculate_fibo_number_recursive(num):
if num < 0:
print "Input incorrect"
elif num == 0 :
return 0
elif num == 1 :
return 1
else :
re... | true |
8358b7abc87c5062eeb4b676eb1091b5d6d897ba | abhijit-nimbalkar/Python-Assignment-2 | /ftoc.py | 530 | 4.125 | 4 | #Author-Abhijit Nimbalkar & Sriman Kolachalam
import Functions #importing Functions.py file having multiple functions
temp_in_F=Functions.check_temp_input_for_F("Enter the Temperature in Fahrenheit: ") #Calling function check_temp_input_for_F() for accepting the valid input from User
... | true |
685d18829d1197fa5471cfed83446b14af65789e | hsuvas/FDP_py_assignments | /Day2/Q6_FibonacciRecursion.py | 263 | 4.25 | 4 | #6. fibonacci series till the Nth term by using a recursive function.
def fibo(n):
if n<=1:
return n
else:
return (fibo(n-1)+fibo(n-2))
n=int(input("How many numbers: "))
print("Fibonacci series: ")
for i in range(n):
print(fibo(i))
| true |
99bb6059454cf462afbe9bfc528b8ea6d9d84ecb | hsuvas/FDP_py_assignments | /Day2/Q3_areaCircumference.py | 279 | 4.5 | 4 | #3.compute and return the area and circumference of a circle.
def area(r):
area=3.14*r*r
return area
def circumference(r):
c=2*3.14*r
return c
r=float(input("enter the radius"))
a=area(r)
print("area is: ",a)
cf=circumference(r)
print("Circumference is: ",cf)
| true |
edb63793a549bf6bf0e4de33f86a7cefb1718b57 | onionmccabbage/python_april2021 | /using_logic.py | 355 | 4.28125 | 4 | # determine if a number is larger or smaller than another number
a = int(float(input('first number? ')))
b = int(float(input('secomd number? ')))
# using 'if' logic
if a<b: # the colon begins a code block
print('first is less than second')
elif a>b:
print('second is less than first')
else:
pr... | true |
ee715cb90cf4724f65c0f8d256be926b66dc1ddb | onionmccabbage/python_april2021 | /fifo.py | 1,739 | 4.1875 | 4 | # reading adnd writing files file-input-file-output
# a simple idea is to direct printout to a file
# fout is a common name for file output object
# 'w' will (over)write the file 'a' will append to the file. 't' is for text (the default)
fout = open('log.txt', 'at')
print('warning - lots of interesting loggy st... | true |
4417ee4d4251854d55dd22522dfef83a0f55d396 | VadymGor/michael_dawson | /chapter04/hero's_inventory.py | 592 | 4.40625 | 4 | # Hero's Inventory
# Demonstrates tuple creation
# create an empty tuple
inventory = ()
# treat the tuple as a condition
if not inventory:
print("You are empty-handed.")
input("\nPress the enter key to continue.")
# create a tuple with some items
inventory = ("sword",
"armor",
... | true |
6d19be295873c9c65fcbb19b9adbca57d700cb64 | vedk21/data_structure_playground | /Arrays/Rearrangement/Pattern/alternate_positive_negative_numbers_solution.py | 1,882 | 4.125 | 4 | # Rearrange array such that positive and negative elements are alternate to each other,
# if positive or negative numbers are more then arrange them all at end
# Time Complexity: O(n)
# Auxiliary Space Complexity: O(1)
# helper functions
def swap(arr, a, b):
arr[a], arr[b] = arr[b], arr[a]
return arr
def righ... | true |
e149ad4cc8b69c2addbcc4c5070c00885d26726d | KyrillMetalnikov/HelloWorld | /Temperature.py | 329 | 4.21875 | 4 | celsius = 10
fahrenheit = celsius * 9/5 + 32
print("{} degrees celsius is equal to {} degrees fahrenheit!".format(celsius, fahrenheit))
print("Roses are red")
print("Violets are blue")
print("Sugar is sweet")
print("But I have commitment issues")
print("So I'd rather just be friends")
print("At this point in our relati... | true |
c018cea22879247b24084c56731289a2a0f789f5 | abhay-jindal/Coding-Problems | /Minimum Path Sum in Matrix.py | 1,409 | 4.25 | 4 | """
MINIMUM PATH SUM IN MATRIX
https://leetcode.com/problems/minimum-path-sum/
https://www.geeksforgeeks.org/min-cost-path-dp-6/
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right,
which minimizes the sum of all numbers along its path.
Note: You can only move either do... | true |
a711681f3168d9f733694126d0487f60f39cdf56 | abhay-jindal/Coding-Problems | /Linked List Merge Sort.py | 1,275 | 4.21875 | 4 | """
LINKEDLIST MERGE SORT
"""
# Class to create an Linked list with an Null head pointer
class LinkedList:
def __init__(self):
self.head = None
# sorting of linked list using merge sort in O(nlogn) time complexity
def mergeSort(self, head):
if head is None or head.next is None:
... | true |
c2c19d072b086c899b227646826b7ef168e24a78 | abhay-jindal/Coding-Problems | /Array/Zeroes to Left & Right.py | 1,239 | 4.125 | 4 | """
MOVE ZEROES TO LEFT AND RIGHT IN ARRAY
https://leetcode.com/problems/move-zeroes/
Given an integer array nums, move all 0's to the end of it while maintaining the relative order
of the non-zero elements. Note that you must do this in-place without making a copy of the array.
Time complexity: O(n)
"""
def zeros... | true |
952943db49fe23060e99c65a295d35c1aff7c7d5 | abhay-jindal/Coding-Problems | /LinkedList/check_palindrome.py | 2,523 | 4.21875 | 4 | """
Palindrome Linked List
https://leetcode.com/problems/palindrome-linked-list/
https://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/
Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false.
"""
from... | true |
9be41506dd4300748e2b37c19e73cd4e62d107f7 | abhay-jindal/Coding-Problems | /LinkedList/last_nth_node.py | 1,537 | 4.28125 | 4 | """
Clockwise rotation of Linked List
https://leetcode.com/problems/rotate-list/
https://www.geeksforgeeks.org/clockwise-rotation-of-linked-list/
Given a singly linked list and an integer K, the task is to rotate the linked list clockwise to the right by K places.
"""
from main import LinkedList
#... | true |
45eb0065c98e74c6502b973fc234b6a19ffed92a | bakossandor/DataStructures | /Stacks and Queues/single_array_to_implement_3_stacks.py | 910 | 4.28125 | 4 | # describe how would you implement 3 stack in a single array
# I would divide the array into 3 spaces and use pointer to mark the end of each stack
# [stack1, stack1, stack2, stack2, stack3, stack3]
# [None, None, "1", None, "one", "two"]
class threeStack:
def __init__(self):
self.one = 0
self.two... | true |
b86d42a1ed8bd87ddae179fda23d234096459e0c | bakossandor/DataStructures | /LinkedLists/linked_list.py | 2,278 | 4.28125 | 4 | # Implementing a Linked List data structure
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def add(self, val):
new_node = Node(val)
if self.head is not None:
new_node.next... | true |
97d430a520e681cd8a0db52c1610436583bf9889 | raj-rox/Coding-Challenges | /hurdle.py | 946 | 4.125 | 4 | #1st attempt. DONE. bakwaas
#https://www.hackerrank.com/challenges/the-hurdle-race/problem
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'hurdleRace' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:... | true |
6f134495fa15c220c501a82206a33839d0083079 | tanbir6666/test-01 | /starting codes/python after 1 hour.py | 808 | 4.21875 | 4 | newString="hello Tanbir";
print(type(newString));
newstring_value= newString[5:]
print(newstring_value);
print(newstring_value.upper());
print(newstring_value.lower());
print(newstring_value.replace("Tanbir", "Taohid"))
print(newstring_value);
#replace string
whatTosay=newString.replace("hello","how are you");
pri... | true |
9c6627692d958ddf64b87aaa495ce7e315dc8e8f | simon-fj-russell/ds_python | /linear_regression.py | 2,509 | 4.1875 | 4 | # Linear Regression model using stats models
# First import the modules
import pandas as pd
import statsmodels.api as sm
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()
# User made functions
# Use Stats models to train a linear model
# Using OLS -> ordinary least squares
def train_lr_model(x, y):
#... | true |
2e8a17d29fd352af98d0cc4b2b53d9d543601f6a | trenton1199/Python-mon-K | /Reminder.py | 2,157 | 4.34375 | 4 | from datetime import date
import os
def pdf():
pdf = input(f"would you like to turn {file_name} into a pdf file? [y/n] ").lower()
if pdf == 'y':
pdf_name = input("what would you like the pdf file to be named ") + ".pdf"
font_size = int(input("what would you like your font size to be?"))
... | true |
2dfad5d7fcf6789c93002064f621691677899758 | kraftpunk97-zz/Fundamentals-ML-Algos | /k_means.py | 2,338 | 4.1875 | 4 | #! /usr/local/bin/python3
'''Implementing the k-Means Clustering Algorithm from scratch'''
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
def kmeans(dataset, num_clusters=3, max_iter=10):
'''
The k-means implemention
'''
m, n = dataset.shape
cluster_arr = np.zeros(dtype=in... | true |
ab87e9277d7605bb7353c381f192949b40abcc49 | rprustagi/EL-Programming-with-Python | /MT-Python-Programming/MT-Programs/hanoi.py | 2,368 | 4.5 | 4 | #!/usr/bin/env python3
""" turtle-example-suite:
tdemo_minimal_hanoi.py
A minimal 'Towers of Hanoi' animation:
A tower of N discs is transferred from the
left to the right peg.
The value of N is specified by command line argument
An imho quite elegant and concise
implementation using a tower class, wh... | true |
94fd0458b2282379e6e720d07581fd15467d0581 | Anirban2404/HackerRank_Stat | /CLT.py | 2,013 | 4.125 | 4 | #!/bin/python
import sys
'''
A large elevator can transport a maximum of 9800 pounds. Suppose a load of cargo containing 49 boxes
must be transported via the elevator. The box weight of this type of cargo follows a distribution
with a mean of 205 pounds and a standard deviation of 15 pounds. Based on this in... | true |
4aa692633576198ea6580dfd97e2b068d5dbe920 | AbhijeetDixit/MyAdventuresWithPython | /OOPython/ClassesExample2.py | 1,927 | 4.34375 | 4 | ''' This example shows the use of multiple classes in a single program'''
class City:
def __init__(self, name):
self.name = name
self.instituteCount = 0
self.instituteList = []
pass
def addInstitute(self, instObj):
self.instituteList.append(instObj)
self.instituteCount += 1
def displayInstitute(self)... | true |
8720d528fb634c4a61eeb5b33a3405ee87883ada | Siddhant-Sr/Turtle_race | /main.py | 1,006 | 4.21875 | 4 | from turtle import Turtle, Screen
import random
race = False
screen = Screen()
screen.setup(width= 500, height= 400)
color = ["red", "yellow", "purple", "pink", "brown", "blue"]
y = [-70, -40, -10, 20, 50, 80]
bet = screen.textinput(title="make your bet", prompt="Which turtle will win the race? Enter a color")
all_tur... | true |
3c7665bbadb5ae2903b9b5edfda93d3a78ada475 | dgupta3102/python_L1 | /PythonL1_Q6.py | 916 | 4.25 | 4 | # Write a program to read string and print each character separately.
# a) Slice the string using slice operator [:] slice the portion the strings to create a sub strings.
# b) Repeat the string 100 times using repeat operator *
# c) Read string 2 and concatenate with other string using + operator.
Wo... | true |
347ac39407381d1d852124102d38e8e9f746277f | dgupta3102/python_L1 | /PythonL1_Q19.py | 969 | 4.21875 | 4 | # Using loop structures print even numbers between 1 to 100.
# a) By using For loop, use continue/ break/ pass statement to skip odd numbers.
# i) Break the loop if the value is 50
print("part 1a --------------")
for j in range(1, 101):
if j % 2 != 0: # checks the number is Odd and Pass
pass
... | true |
ec2ae4d1db1811fcca703d6a35ddf1732e481e2a | riteshrai11786/python-learning | /InsertionSort.py | 1,600 | 4.40625 | 4 | # My python practice programs
# function for sorting the list of integers
def insertion_sort(L):
# Loop over the list and sort it through insertion algo
for index in range(1, len(L)):
# define key, which is the current element we are using for sorting
key = L[index]
# Move elements of a... | true |
93481419afcb5937eca359b323e038e7e29c6ad9 | rzfeeser/20200831python | /monty_python3.py | 1,075 | 4.125 | 4 | #!/usr/bin/python3
round = 0
answer = " "
while round < 3:
round += 1 # increase the round counter by 1
answer = input('Finish the movie title, "Monty Python\'s The Life of ______": ')
# transform answer into something "common" to test
answer = answer.lower()
# Correct Answer
if answe... | true |
4c5a2f9b26e6d4fa7c3250b3043d1df5865b76c8 | g-boy-repo/shoppinglist | /shopping_list_2.py | 2,162 | 4.5 | 4 | # Have a HELP command
# Have a SHOW command
# clean code up in general
#make a list to hold onto our items
shopping_list = []
def show_help():
#print out instructions on how to use the app
print("What should we pick up at the store?")
print("""
Enter 'DONE' to stop addig items.
Enter 'HELP' for this help... | true |
3edf29f645ecb4af1167359eab4c910d47c40805 | sankar-vs/Python-and-MySQL | /Data Structures/Basic Program/41_Convert_to_binary.py | 519 | 4.3125 | 4 | '''
@Author: Sankar
@Date: 2021-04-08 15:20:25
@Last Modified by: Sankar
@Last Modified time: 2021-04-08 15:27:09
@Title : Basic_Python-41
'''
'''
Write a Python program to convert an integer to binary keep leading zeros.
Sample data : 50
Expected output : 00001100, 0000001100
'''
decimal = 50
print("Convertion to bin... | true |
67bdb85c94a8874623c89d0ac74a9b1464e5c391 | sankar-vs/Python-and-MySQL | /Data Structures/List/8_Find_list_of_words.py | 739 | 4.5 | 4 | '''
@Author: Sankar
@Date: 2021-04-09 12:36:25
@Last Modified by: Sankar
@Last Modified time: 2021-04-09 12:42:09
@Title : List_Python-8
'''
'''
Write a Python program to find the list of words that are longer than n from a
given list of words.
'''
n = 3
list = ['Hi','Sankar','How','are','you',"brotha"]
def countWord... | true |
1e16341185e46f060a7a50393d5ec47275f6b009 | sankar-vs/Python-and-MySQL | /Data Structures/List/3_Smallest_number.py | 440 | 4.15625 | 4 | '''
@Author: Sankar
@Date: 2021-04-09 12:07:25
@Last Modified by: Sankar
@Last Modified time: 2021-04-09 12:13:09
@Title : List_Python-3
'''
'''
Write a Python program to get the smallest number from a list.
'''
list = [1,2,3,4,6,10,0]
minimum = list[0]
for i in list:
if (minimum>i):
minimum = i
print("Min... | true |
08a53c3d25d935e95443f1dfa3d2cefdd10237fb | sankar-vs/Python-and-MySQL | /Data Structures/Array/4_Remove_first_element.py | 482 | 4.1875 | 4 | '''
@Author: Sankar
@Date: 2021-04-09 07:46:25
@Last Modified by: Sankar
@Last Modified time: 2021-04-09 07:51:09
@Title : Array_Python-4
'''
'''
Write a Python program to remove the first occurrence of a specified element from an
array.
'''
array = []
for i in range(5):
element = int(input("Enter Element {} in arr... | true |
2b3f22bb3fcad13848f40e0c938c603acb2f3959 | sankar-vs/Python-and-MySQL | /Functional Programs/Distance.py | 1,357 | 4.28125 | 4 | '''
@Author: Sankar
@Date: 2021-04-01 09:06:25
@Last Modified by: Sankar
@Last Modified time: 2021-04-02 12:25:37
@Title : Euclidean Distance
'''
import re
def num_regex_int(x):
'''
Description:
Get input from user, check whether the input is matching with the pattern
expression, if True then re... | true |
55f9b7cd0aa5a2b10cd819e5e3e6020728e2c670 | Dilshodbek23/Python-lessons | /38_4.py | 366 | 4.4375 | 4 | # Python Standard Libraries
# The user was asked to enter a phone number. The entered value was checked against the template.
import re
regex = "^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$"
phone = input("Please enter phone number: ")
if re.match(regex, phone):
print(f"phone: {phone}")
el... | true |
38c79868e60d20c9a6d5e384b406c3656f565ffb | Haldgerd/Simple_coffee_machine_project | /main.py | 2,305 | 4.5 | 4 | """
An attempt to simulate a simple coffee machine and it's functionality. This version is used as in depth exercise, before
writing same program using OOP later within the programming course.
The main requirements where:
1. Output a report on resources.
2. Receive user input, referring to type of coffee they want.
3.... | true |
2370915fa2514143fc56ea1e055b70805d22d170 | samaracanjura/Coding-Portfolio | /Python/Shapes.py | 996 | 4.375 | 4 | #Samara Canjura
#shapes.py
#Finding the area and perimeter of a square, and finding the circumference and area of a circle.
import math # Python Library needed for access to math.pi and math.pow
def main():
inNum = getInput("Input some number: ")
while inNum != 0: #Loop ends when zer... | true |
74c00f287ec85a3a8ac0b3b9fd8f3d0bd6babe70 | psmzakaria/Practical-1-2 | /Practical2Q1.py | 478 | 4.125 | 4 | # Question 1
# Write codes for the incomplete program below so that it sums up all the digits in the integer variable num (9+3+2) and displays the output as a sum.
num = int(input("Enter your Number Here"))
print(num)
# Getting the first digit number
digit1 = int(num/100)
print(digit1)
# Getting the second digit n... | true |
5de721579c27704e39cf12b1183a1eebea4d22d4 | lion137/Python-Algorithms | /shuffling.py | 441 | 4.1875 | 4 | # algorithm for shuffling given subscriptable data structure (Knuth)
import random
def swap(alist, i, j):
"""swaps input lists i, j elements"""
alist[i], alist[j] = alist[j], alist[i]
def shuffle(data):
"""randomly shuffles element in the input data"""
n = len(data)
for token in range(n - 1):
... | true |
f882f9dcf344950cc893bf1e2fb49ffb103d168e | chenjyr/AlgorithmProblems | /HackerRank/Search/FindTheMedian.py | 1,652 | 4.3125 | 4 | """
In the Quicksort challenges, you sorted an entire array.
Sometimes, you just need specific information about a list of numbers,
and doing a full sort would be unnecessary.
Can you figure out a way to use your partition code to find the median in an array?
Challenge
Given a list of number... | true |
0adf7ed3f2301c043ef269a366a90c3970673b1f | chenjyr/AlgorithmProblems | /HackerRank/Sorting/Quicksort1.py | 2,143 | 4.21875 | 4 | """
The previous challenges covered Insertion Sort, which is a simple and intuitive sorting algorithm.
Insertion Sort has a running time of O(N2) which isn’t fast enough for most purposes.
Instead, sorting in the real-world is done with faster algorithms like Quicksort,
which will be covered in these... | true |
248f5308062ddc2b896413a99dc9d5c3f3c29ac6 | chenjyr/AlgorithmProblems | /HackerRank/Sorting/InsertionSort2.py | 1,852 | 4.625 | 5 | """
In Insertion Sort Part 1, you sorted one element into an array.
Using the same approach repeatedly, can you sort an entire unsorted array?
Guideline: You already can place an element into a sorted array.
How can you use that code to build up a sorted array, one element at a time?
Note that in the first step, wh... | true |
c2098e9dd0710577a8bcac533b34b3bbee7b3a19 | NishuOberoi1996/IF_ELSE | /num_alph_chatr.py | 206 | 4.15625 | 4 | num=input("enter anything:-")
if num>="a" and num<="z" or num>="A" and num<="Z":
print("it is a alphabet")
elif num>="0" and num<="9":
print("it is number")
else:
print("Special Character") | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.