blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
ed7b1ca37da1bfbbbfdf09f56d3fc8bb860a439d | rahulshukla29081999/python-professional-programming-dsa | /bubble sort.py | 664 | 4.15625 | 4 | # Bubble Sort in Python...
#time complexity of bubble sort is O(n^2)
#it is a simple comparision based algorithm ...
#in this compare two adjacent element of list ..if 1st elemnt is bigger than 2nd then swap them ...
#largest element of the list will be in last position .
#second largest element of the list will come i... | true |
f08cf2d80f0af8a80254ac68c18a7b1977bfdd40 | clettieri/Algorithm_Implementations | /breadth_first_search.py | 2,685 | 4.375 | 4 | """
Breadth-First Search
This searching algorithm will search through a tree going through each
node at one level before continuing to the next level of nodes.
BFS will search through the tree assigning each vertex(node) a DISTANCE
value, which is the distance from the source vertex, and a PREDECESSOR value
which is ... | true |
0f24ce9b604ccda5bd7d222b9908dfbf57208982 | clettieri/Algorithm_Implementations | /MergeSort.py | 2,577 | 4.3125 | 4 | """
MergeSort
Given an array, merge_sort will recursively divide that array
until a subarray is length 0 or 1. In this base case (length 0 or 1),
the subarray is said to be sorted. Once the array is split up to the base case,
the merge function is called on each pairing of subarrays. The merge
function looks at the... | true |
49c2cbcf5686416914004eb4f071f84d669feb5b | zalthehuman/Python | /eulerPro.py | 2,352 | 4.25 | 4 | import sys
import math
from collections import OrderedDict
#1 Multiples of 3 and 5
"""
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 multThreeOrFive():
sum = 0
for i in ... | true |
a7387c1ecff82382aa75b75b113e62f318c73d32 | MiguelCF06/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/4-print_square.py | 556 | 4.25 | 4 | #!/usr/bin/python3
"""
Prints a square with "#"
"""
def print_square(size):
"""
An argument size type integer
representing the size of the square
"""
if isinstance(size, bool):
raise TypeError("size must be an integer")
elif not isinstance(size, int):
raise TypeError("size mus... | true |
e4e2598fbf394b7a2e1c2b660bb21732333a9005 | MiguelCF06/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/tests/6-max_integer_test.py | 1,226 | 4.375 | 4 | #!/usr/bin/python3
"""Unit test for the function max_integer
"""
import unittest
max_integer = __import__('6-max_integer').max_integer
class TestingMaxInteger(unittest.TestCase):
"""
Class Test for the max integer cases
"""
def no_arguments_test(self):
""" Test when no arguments is passed """
... | true |
cc926e711459e9bcb61c56041f6092a967b13cc8 | colinbazzano/learning-python | /src/classes/cats.py | 489 | 4.28125 | 4 | class Cat:
species = 'mammal'
def __init__(self, name, age):
self.name = name
self.age = age
# Instantiate the Cat object with 3 cats
cat1 = Cat("Tiff", 1)
cat2 = Cat("Gregory", 3)
cat3 = Cat("Harold", 12)
# Create a function that finds the oldest cat
def oldest_cat(*args):
return max... | true |
bc17e2a5436a35f6c2036c929bbe1ca4d1706839 | colinbazzano/learning-python | /src/regex/main.py | 604 | 4.28125 | 4 | import re
string = 'search inside of this text, please!'
print('search' in string)
# we are looking for the word 'this' in the variable string
a = re.search('this', string)
# will show you where it began counted via index
print(a.start())
# returns what you wanted if available
print(a.group())
"""NoneType
if you... | true |
01a1deaacd22b9a1bb7664748887a7abb2db59aa | colinbazzano/learning-python | /src/fileio/inputoutput.py | 499 | 4.15625 | 4 | # File I/O or, File Input/Output
# Below, we are assigning a variable to the path of the txt file we want to read.
my_file = open('src/fileio/write.txt')
# here we are just using the read method and printing it
print(my_file.read())
# .seek(0) is another way to move the cursor
# .readline() you can continue to call t... | true |
07cd1b50d39d25a2cb18c2b4f36110c80b192691 | rishabhgautam/LPTHW_mynotes | /ex13-studydrills3.py | 303 | 4.21875 | 4 | # ex13: Parameters, Unpacking, Variables
# Combine input with argv to make a script that gets more input from a user.
from sys import argv
script, first_name, last_name = argv
middle_name = input("What's your middle name?")
print("Your full name is %s %s %s." % (first_name, middle_name, last_name)) | true |
da50855b9c02c62100ae1870849b03c545afc8e1 | rishabhgautam/LPTHW_mynotes | /ex20-studydrills.py | 1,962 | 4.28125 | 4 | # ex20: Functions and Files
# Import argv variables from the sys module
from sys import argv
# Assign the first and the second arguments to the two variables
script, input_file = argv
# Define a function called print_call to print the whole contents of a
# file, with one file object as formal parameter
def print_all... | true |
d8e39d1e7c7561253203f68afcc1f4dfa7d7f5e7 | xiemingzhi/pythonproject | /lang/arrays.py | 1,365 | 4.375 | 4 | #List is a collection which is ordered and changeable. Allows duplicate members.
# in python they are called lists
a = [1, 2, 3, 4, 5]
def printArr(arr):
for x in arr:
print(x)
printArr(a)
#Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.
# in python t... | true |
477ed45fd0d6d278a87f33209ad99b30e7732c65 | AbhinavUtkarsh/Cracking-The-Coding-Interview | /Solutions to Arrays and Strings/rotate matrix.py | 1,787 | 4.34375 | 4 | def rotate(matrix):
N=len(matrix)
for layer in range(N//2):
first , last = layer, N - layer - 1
for i in range(first, last):
top = matrix[layer][i]
matrix[layer][i] = matrix[-i-1][layer]
matrix[-i-1][layer] = matrix[-layer-1][-i-1]
matrix[-l... | true |
a64c82bd01eac0b1114b23a9a3a88d0fe593e26e | Birdboy821/python | /natural.py | 399 | 4.1875 | 4 | #natural.py
#christopher amell 1/3/19
#find the sum and sum of the cubed of the natural
#numbers up to one that is imputed by the user
def sumN(n):
summ = 0
while(n>0):
summ=summ+n
n=n-1
print(summ)
def sumNCubes(n):
summ = 0
while(n>0):
summ=summ+n**3
n=n-1
print(summ)
def ... | true |
b7aaa56c625d4c68ce805e97b891a600313e56c3 | Shiv2157k/leet_code | /revisited__2021/arrays/container_with_most_water.py | 759 | 4.125 | 4 | from typing import List
class WaterContainer:
def with_most_water(self, height: List[int]) -> int:
"""
Approach: Two Pointers
Time Complexity: O(N)
Space Complexity: O(1)
:param height:
:return:
"""
left, right = 0, len(height) - 1
area = 0
... | true |
5882a8db15e46c6cfcb1e523e8f111e698b16789 | Shiv2157k/leet_code | /revisited__2021/linked_list/swap_nodes_in_pairs.py | 1,811 | 4.21875 | 4 | class ListNode:
def __init__(self, val: int, next: int = None):
self.val = val
self.next = next
class LinkedList:
def swap_nodes_in_pairs_(self, head: "ListNode"):
"""
Approach: Iterative
Time Complexity: O(N)
Space Complexity: O(1)
:param head:
... | true |
074c11ad90d77eb8641b6251f4065bc2c87c2855 | Shiv2157k/leet_code | /goldman_sachs/shortest_word_distance.py | 994 | 4.125 | 4 | from typing import List
class Words:
def shortest_word_distance(self, words: List[str], word1: str, word2: str) -> int:
"""
Approach: One Pass
Time Complexity: O(N * M)
Space Complexity: O(1)
:param words:
:param word1:
:param word2:
:return:
... | true |
1ed7487081e736f8b4732b114799d1b37bf59dee | obedansah/Smart_Game | /Smart_Game.py | 1,315 | 4.1875 | 4 |
#Welcoming the Users
name = input("Enter your name")
print("Hello " +name,"Let's Play SmartGame")
print("So what's your first guess")
#Guess word
word = "Entertainment"
#creates an variable with an empty value
guesses = " "
#determine the number of runs
runs = 15
while runs>0: # Create a while... | true |
cba91cabb82130749a4ca5026a76a949e0cd63b9 | mastansberry/LeftOvers | /lotteryAK.py | 1,573 | 4.125 | 4 | '''
matches(ticket, winners) reports how well a lottery ticket did
test_matches(matches) reports whether a matches() function works as assigned.
'''
def matches(ticket, winner):
''' returns the number of numbers that are in both ticket and winner
ticket and winner are each a list of five unique in... | true |
c239d4aedead6d00d326929403ba5ef36b5edbab | Varshitha019/Daily-Online-Coding | /25-06-2020/Program1.py | 207 | 4.125 | 4 | 1. Write a python program for cube sum of first n natural numbers.
def sumOfSeries(n):
sum = 0
for i in range(1, n+1):
sum +=i*i*i
return sum
n = int(input("Enter number:"))
print(sumOfSeries(n))
| true |
b4685f71740233957125bbcf285279612d6e7669 | Varshitha019/Daily-Online-Coding | /28-5-2020/Program2.py | 611 | 4.28125 | 4 | 2. .Write a python program to find digital root of a number.
Description:
A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to... | true |
e77acb53bf3bc9c86e18dc2b72ac6c86187b0ed0 | gislig/hr2018algorithmAssignment1 | /project2.py | 1,166 | 4.28125 | 4 | # 1. Checks if the first three numbers are entered
# 2. If the numbers are above 3 then start sequencing
# 3. Sums up the first, second and third number into a variable next_num
# 4. Each step sets the last number to the next bellow
# 5. Finally it prints out the next_num
n = int(input("Enter the length of the sequen... | true |
c99cf490702d49b88dfd18cdb8592546a46d17d0 | Nate-Rod/PythonLearning | /Problem_003.py | 1,319 | 4.4375 | 4 | ''' Problem text:
Time for some fake graphics!
Let’s say we want to draw game boards that look like this:
--- --- ---
| | | |
--- --- ---
| | | |
--- --- ---
| | | |
--- --- ---
This one is 3x3 (like in tic tac toe).
Obviously, they come in many other sizes (8x8 for chess, 19x19 for Go,... | true |
a18192ce83389931a90328b9b2b7fa21c282fe27 | BravoCiao/PY103_Bravo | /ex11.py | 1,921 | 4.375 | 4 | print "How old are you?",
age = raw_input("24")
# i've tried to delete the comma and run the programme,
# then the age shows,on the second line, the comma
# is a prompt for data to show on the same line.
# based on official handbook, raw_input() is written to standard output
# without a trailing newline. The func... | true |
db546942befa0cb9745931a986ff2f75ee008c53 | linusqzdeng/python-snippets | /exercises/string_lists.py | 867 | 4.34375 | 4 | '''Thsi program asks the user for a string and print out whether this string is a
palindrome or not (a palindrome is a string that reads the same forwards and backwards)
'''
# ask for a word
something = input('Give me a word: ')
# convert the given word into a list
original_list = list(something)
print(orig... | true |
8d085b8f331fad09583bc0e31e40e961ea03e833 | linusqzdeng/python-snippets | /exercises/guessing_game1.py | 1,102 | 4.3125 | 4 | '''
This program generates a random number between 1 to 9 (including 1 and 9) and asks the user to
guess the number, then tell them whether they guessed too low, too high, or exactly right.
'''
from random import randint
num = randint(1, 9)
attempt = 1
while True:
guess = int(input('Guess what number ... | true |
4501b4ba1f9e9b31875c063f1c21e36ac58475e2 | zerynth/core-zerynth-stdlib | /examples/Interrupts/main.py | 1,442 | 4.40625 | 4 | ################################################################################
# Interrupt Basics
#
# Created by Zerynth Team 2015 CC
# Authors: G. Baldi, D. Mazzei
################################################################################
import streams
# create a serial port stream with default parameters
s... | true |
981052ef2e22904af49c578dc06edab1df4834ea | SiddharthSampath/LeetCodeMayChallenge | /problem16.py | 1,707 | 4.25 | 4 | '''
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.
You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.
Example 1:
Input: 1->2->3->4->... | true |
20f31fa81f7e3ac014987d042e32ac4f0d9e2cc9 | tonycmooz/Pythonic | /nested_function.py | 277 | 4.15625 | 4 | # An example of a nested function
def outer():
x = 1
def inner():
print x # Python looks for a local variable in the inner
inner() # then looks in the enclosing, outer
outer() # Python looks in the scope of outer first
# and finds a local variable named inner
| true |
94086d952013023c802590a289e042bcdaedc44f | iffishells/Regular-Expression-python | /Split-with-regular-expressions.py | 908 | 4.71875 | 5 | #######################################
#### Split with regular expressions ###
######################################
import re
# Let's see how we can split with the re syntax. This should look similar to how
# you used the split() method with strings.
split_term="@"
phrase = "what is the domain name of someone d... | true |
743956f40ff4a5139d5fb2a6ce64688642238d39 | ai230/Python | /draw_shape.py | 504 | 4.125 | 4 | import turtle
def draw_square():
# Create window
window = turtle.Screen()
window.bgcolor("red")
#Create object
fig = turtle.Turtle()
fig.shape("circle")
fig.color("white")
fig.speed(5)
fig.forward(200)
fig.right(90)
fig.forward(200)
fig.right(90)
fig.forward(200)
... | true |
6263594794ac44dd19a4a81f202f5cc1fb63049b | 1devops/fun | /project 1.py | 318 | 4.40625 | 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 proj1(num):
j = 0
for i in range(0, num):
if i % 3 == 0 or i % 5 == 0:
j = i + j
print "final", j
proj1(1000) | true |
d7197fb18c63b4718cd3f24687925d0cf8e44029 | rishav-ish/MyCertificates | /reverseStack_recu.py | 398 | 4.125 | 4 | #Reverse Stack using recursion
def insert(stack,temp):
if not stack:
stack.append(temp)
return
temp2 = stack.pop()
insert(stack,temp)
stack.append(temp2)
def reverse(stack):
if not stack:
return
temp = stack.pop()
reverse(stack)
in... | true |
6676dffc286556c70577090f37d2a7f94d1eb652 | thirihsumyataung/Python_Tutorials | /function_CentigradeToFahrenheit_Converter_Python.py | 801 | 4.3125 | 4 | #Temperture converting from Centigrade to Fahrenheit is :
# F = 9/5 * C + 32
#Question : F = Fahrenheit temperature
# C = the centigrade temperature
#Write a function named fahrenheit that accepts a centigrade temperature as an argument
# function should return the temperature the temperature , converted to Fahrenheit
... | true |
c2778ff17feadc65e78715ec67b201d09d9adbfe | thirihsumyataung/Python_Tutorials | /function_kineticEnergyCalculation_Python.py | 779 | 4.375 | 4 | #Write a function named kineticEnergy that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments.
# The function should return the amount of kinetic energy that the object has.
# Demonstrate the function by calling it in a program that asks the user to enter values for mass and veloci... | true |
25761d97611f8acc56c87bbae58d07600d5054a5 | sppess/Homeworks | /homework-13/hw-13-task-1.py | 676 | 4.3125 | 4 | from functools import wraps
# Write a decorator that prints a function with arguments passed to it.
# NOTE! It should print the function, not the result of its execution!
# For example:
# "add called with 4, 5"
def logger(func):
def wripper(*args, **kwargs):
arguments = ''
for arg in args:
... | true |
abc589ba9207eac5da8ebad5db193fe0e7909b2f | hzhao22/ryanpython | /venv/hailstone.py | 533 | 4.375 | 4 | print ("Hail Stone")
#Starting with any positive whole number $n$ form a sequence in the following way:
#If $n$ is even, divide it by $2$ to give $n^\prime = n/2$.
#If $n$ is odd, multiply it by $3$ and add $1$ to give $n^\prime = 3n + 1.$
def hailStone(n):
numbers = []
while ( 1 not in numbers):
if n... | true |
97c9933472f1f2fab1c37d13c22fc91fa943dace | gstoel/adventofcode2016 | /day3_DK.py | 1,106 | 4.1875 | 4 | # http://adventofcode.com/2016/day/3
from itertools import combinations
from pandas import read_fwf
# all combinations of 2 sides of a triangle
tri = [list(n) for n in combinations(range(3), 2)]
for n in range(3):
tri[n].append(list(reversed(range(3)))[n])
def check_tri(sides):
"""checks whether the sum of a... | true |
4def4f4e7119ff665c9279a80916c60a64ce1af9 | awsk1994/DailyCodingProblems | /Problems/day23.py | 2,273 | 4.1875 | 4 | '''
This problem was asked by Google.
You are given an M by N matrix consisting of booleans that represents a board. Each True boolean represents a wall. Each False boolean represents a tile you can walk on.
Given this matrix, a start coordinate, and an end coordinate, return the minimum number of steps required to r... | true |
bbe885cb3e51c0c7b083a7a42d634dfc143e3d6a | Kapral26/solutions_from_checkio.org | /elem_list.py | 249 | 4.125 | 4 | '''
returns a tuple with 3 elements - first, third and second to the last
'''
def easy_unpack2(elements: tuple) -> tuple:
return(elements[0],elements[2], elements[-2])
print(easy_unpack2((1, 2, 3, 4, 5, 6, 7, 9)))
print(easy_unpack2((6, 3, 7)))
| true |
dc19208a3b7aa093a1588f3abb635f7c67c427b2 | bnitin92/coding_practice | /Interview1_1/9_30.py | 1,436 | 4.125 | 4 | # finding the depth of a binary tree
"""
input : root
Binary tree : not balanced
ouput: the height of the tree
5
/ \
4 7
/ \ \
12 15 15
\
19
use Breadth first searc... | true |
6432a0c3992552346b7bff30f72c4980422c513e | bnitin92/coding_practice | /Recursion_DP/8.1 Triple Step.py | 491 | 4.3125 | 4 | """
A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3
steps at a time. Implement a method to count how many possible ways the child can run up the stairs.
"""
def tripleStep(n):
if n < 0:
return 0
if n == 0:
return 1
else:
return tripleStep(n-3... | true |
8c6d32b839e851b019b2a8936e8809b97e28a361 | MarineKing5248/MLPython | /chapter4/gradient_descent.py | 1,000 | 4.21875 | 4 | # 1) An Empty Network
weight = 0.1
alpha = 0.01
def neural_network(input, weight):
prediction = input * weight
return prediction
# 2) PREDICT: Making A Prediction And Evaluating Error
number_of_toes = [8.5]
win_or_lose_binary = [1] # (won!!!)
input = number_of_toes[0]
goal_pred = win_or_lose_binary[0]
pred... | true |
b08fc4ba6f9053b9ffbae0c391bdaa10f7df906d | giacomocallegari/spatial-databases-project | /src/main.py | 1,394 | 4.125 | 4 | from src.geometry import Point, Segment
from src.structures import Subdivision
def main():
"""Main function.
After providing a sample subdivision, its trapezoidal map and search structure are built.
Then, points can be queried to find which faces contain them.
"""
example = 2 # Number of the ex... | true |
83e1cae23a573214248dadb3d9ed670330319555 | ruppdj/Curriculum | /Beginner_Level/Unit1/Practice_what_you_learned/variables.py | 308 | 4.15625 | 4 | """Variables"""
# To set the value 3 to the variable distance we code
distance = 3
# 1. Set the variable speed to the value 5.
speed =
# 2. Set the variable fast_speed to the value True.
# 3. Change the value in the variable below to 1.23
# What will be printed now?
a_variable = 3.4
print(a_variable)
| true |
cfd13f7dd2db899ebba36c992cefc0580c04a2dd | sdg000/git | /lowerANDupperlimit_code.py | 1,849 | 4.46875 | 4 | #Write a script to take in a lower limit and an upper limit.
#And based on the users selection, provide all the even or odd
#numbers within that range.
#enter a new range: then display odd or even values following that.
#if not , then exit.
'''
VARIABLES TO DECLARE
LowerL
UpperL
odd_range
even_range
'''
LowerL=in... | true |
18a85925742b90cc3618d42435ba3684caaf7614 | fr0z3n2/Python-Crash-Course-Examples | /ch2_variables_and_strings/print_message.py | 494 | 4.53125 | 5 | '''
This is how to print a message in python 3
'''
# Storing the message in a variable.
message = "This is a message ;)"
print(message)
message = 'Holy crap "Look at these quotes"'
print(message)
message = "holy cRaP 'look again'"
print(message)
# The title method puts the characters in upper case.
print(message.tit... | true |
62a5324ffbf462e7c2003314afe70526edead42c | MalithaDilshan/Data-Structures-and-Algorithms | /Sorting/Selection Sort/selectionsort.py | 1,301 | 4.34375 | 4 |
'''
This is the code for the selection sort algorithm
This code will handle the execution time using the time.time() method in python and
here use the random arrays (using the random()) as the input to the algorithm to sorting to
ascending order
'''
import time
import random
random.seed()
#test cas... | true |
0dc4cb22e911d581c47016f3214c5e1e0846d823 | Sam-Power/Trials | /Exercises/Statistics/Assignment-3.py | 1,547 | 4.28125 | 4 | """EXERCISE 1. The following data represent responses from 20 students who were asked “How many hours are you studying in a week?”
16 15 12 15 10 16 16 15 15 15 12 18 12 14 10 18 15 14 15 15
What is the value of the mode? The median? The mean?
EXERCISE 2. Use the data below to calculate the mean, variance, and standard... | true |
4044b4aa2dd63741b06f7632f462d1df05c26669 | nickvarner/automate-the-boring-stuff | /04-first-complete-program/numberGuessing.py | 610 | 4.125 | 4 | #This is a guess the number game.
import random
print('Hello! What is your name?')
userName = input()
print('Well ' + userName + ", I'm thinking of a number between 1-20.")
secretNum = random.randint(1,20)
for guessesTaken in range(1, 7):
print('Take a guess!')
guess = int(input())
if guess < secretNum:... | true |
0716cd827ea6026471f6e1d28483cab1a2c33b06 | Tanmay-Shinde/Python | /Arithmetic operators.py | 308 | 4.1875 | 4 | #Arithmetic Operators
print(3+5) # Addition
print(3-5) # Subtraction
print(3*5) # Multiplication
print(6**2) # Exponentiation
print(6/2) # Division (returns Quotient as floating value)
print(6//2) # Division (returns Quotient as integer value)
print(6%2) # Modulo Operator - returns the remainder
| true |
dd0eb1fd68a35a32d4a63c16df74367a4c6a4a21 | aryanmotgi/python-training | /training-day-9.py | 747 | 4.15625 | 4 | class MyClass:
# atrribute or methods go here
pass
myObj = MyClass()
class Person:
def __init__(self, name, age):
""" This methods is executed every time we created a new `person` instance
`self` is the object instanve being created."""
self.name = name
self.name = age
... | true |
132f53ace51e422b8506cae237fbb30ba673fb22 | dfrantzsmart/metis-datascience | /Pair-Programming/01-12-reverser.py | 661 | 4.28125 | 4 | """
## Pair Programming 1/12/2016
## Reverser of string
## Ozzie with Bryan
Pair Problem
You may be asked to write code that reads from standard input and/or writes to standard output. For example, you will be asked to do that now.
Write a program that reads from standard input and writes each line reversed to standa... | true |
ab837ad96b076533c9f146e58d7af43ad2358389 | sebadp/LeetCode---Python | /sortArrayByParity.py | 1,167 | 4.25 | 4 |
def sortArrayByParity(A):
"""
Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.
You may return any answer array that satisfies this condition.
Example 1:
Input: [3,1,2,4]
Output: [2,4,3,1]
The outputs... | true |
dbeab0c45b25f8651e4f53bf4079be1e9da143b9 | dssheldon/pands-programs-sds | /es.py | 1,691 | 4.1875 | 4 | # Sheldon D'Souza
# G00387857
# Weekly task 7
# The objective of the task is to write a program that reads a text file and outputs the number of 'e's it contains
# I amended the program slightly to take in a user input search character but the default remaining as e
# As instructed the program will take the filename on... | true |
a3d99c04c8e39bb909ff2d0088a1b85cb00e3de5 | Zhou-jinhui/Python-Crash-Course-Exercise | /Chepter4Slice.py | 2,422 | 4.5 | 4 | # Chepter 4 Working with part of a list
# Slice
players = ["charles", "martina", "michael", "florence", "eli"]
print(players[0:3]) # !!! It's a colon in the square bracket, not commas.
print(players[1:4])
print(players[:4])
print(players[2:])
print(players[-3:])
# Looping through a slice
playe... | true |
ca5af8027fc67847c56a641fb996d7a0f8c3e517 | AchWheesht/python_koans | /python3/koans/triangle.py | 1,064 | 4.1875 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Triangle Project Code.
# Triangle analyzes the lengths of the sides of a triangle
# (represented by a, b and c) and returns the type of triangle.
#
# It returns:
# 'equilateral' if all sides are equal
# 'isosceles' if exactly 2 sides are equal
# 'scalene' ... | true |
de61b7fcb0b2521097f41b1a8e140764dea0158e | meghavijendra/K_means_model | /elbow_method.py | 1,857 | 4.28125 | 4 | #!/usr/bin/env python
# coding: utf-8
# ## Finding optimum value for number of clusters for k-means clustering
# <p> Here we are trying to find the optimum value of k which needs to be used for the k-means algorithm in order to get the more accurate results</p>
# <p> We can either use this method to get the optimum k... | true |
5e6b40a9df523d901c02b7f9323e96b8cc05ea01 | chinmaybhoir/project-euler | /euler4.py | 707 | 4.25 | 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 time
start_t = time.time()
def is_palindrome(num):
num_string = str(num)
if num_str... | true |
662ecea8a000da7eacebedf9381f7c06ec627e90 | DipeshBuffon/python_assignment | /DT16.py | 269 | 4.125 | 4 | #Write a Python program to sum all the items in a list.
list=[]
n=int(input("Enter length of list:- "))
for i in range(n):
a=int(input("Enter numeric value for list:- "))
list.append(a)
sum=0
for i in range(len(list)):
sum+=list[i]
print(sum)
| true |
1ddd0ef3ae72a9de31920d1413b2795aee5b18b2 | DipeshBuffon/python_assignment | /DT18.py | 229 | 4.34375 | 4 | #Write a Python program to largest item in a list.
n=int(input("Enter length of list:- "))
list=[]
for i in range(n):
a=int(input("Enter numeric value for list:- "))
list.append(a)
list.sort()
print(list[-1])
| true |
eff9439139901b66bb066e932c4ff9326662c111 | DipeshBuffon/python_assignment | /f6.py | 280 | 4.15625 | 4 | #WAP in python function to check whether the given number is in range or not.
n=int(input("Enter a number:- "))
r=int(input("enter the end of range:- "))
def check(n,r):
if n in range(r+1):
print('found')
else:
print("not found")
check(n,r)
| true |
06e581477069f64f865aa01ddf93c433761b94c3 | deepakdas777/anandology | /functional_programming/tree_reverse.py | 255 | 4.125 | 4 | #Write a function tree_reverse to reverse elements of a nested-list recursively.
def tree_reverse(lis):
lis.reverse()
for i in lis:
if isinstance(i,list):
tree_reverse(i)
return lis
print tree_reverse([[1, 2], [3, [4, 5]], 6])
| true |
162c03918391f131d1f4c8741094da50238f0e9a | anudeepthota/Python | /checkingIn.py | 206 | 4.1875 | 4 | parrot = "Norwegian Blue"
letter = input("Enter a character:")
if(letter in parrot):
print("{} is present in {}".format(letter,parrot))
else:
print("{} is not present in {}".format(letter,parrot)) | true |
75c93b591147c4f1cf0e2788a46a0e4cf700d14d | anudeepthota/Python | /instance_start.py | 1,109 | 4.46875 | 4 | # Python Object Oriented Programming by Joe Marini course example
# Using instance methods and attributes
class Book:
# the "init" function is called when the instance is
# created and ready to be initialized
def __init__(self, title, author, pages, price):
self.title = title
self.author =... | true |
e1a7cde7429b806310907f77fd32b95af3b466a8 | anudeepthota/Python | /holidaychallenge.py | 235 | 4.21875 | 4 | name = input("Please enter your name: ")
age = int(input("Please enter your age: "))
if age > 18 and age < 31:
print("Hi {}, Welcome to the Holiday!!".format(name))
else:
print("Hi {}, Sorry you are not eligible".format(name)) | true |
ee1c1f40b7e3cf42cfc8a0851d834d8fd9cc1cdc | edubu2/OOP-Tutorials | /2_oop_class_variables.py | 1,566 | 4.4375 | 4 | # Object-Oriented Programming tutorials from Corey Schafer's OOP YouTube Series.
class Employee:
num_of_emps = 0 # will increment each time an employee is added
raise_amount = 1.04
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
... | true |
6f816aa39a46097c3bcbad42f6a262e12ab5aba7 | bana513/advent-of-code-2020 | /day2/part1.py | 1,145 | 4.125 | 4 |
"""
Task:
Each line gives the password policy and then the password. The password policy indicates the lowest and highest number
of times a given letter must appear for the password to be valid. For example, 1-3 a means that the password must
contain a at least 1 time and at most 3 times.
In the above example, 2 pas... | true |
c04bb30ce006e2b0f4fc816daaf6c664aa8fb147 | hasrakib/Python-Practice-Projects | /Basic/days-between.py | 293 | 4.375 | 4 | # Write a Python program to calculate number of days between two dates.
# Sample dates : (2014, 7, 2), (2014, 7, 11)
# Expected output : 9 days
from datetime import date
first_date = date(2014, 7, 2)
last_date = date(2014, 7, 11)
difference = last_date - first_date
print(difference.days)
| true |
220827b7f76f736120e24d9855bc3d1a1b66b0f5 | friver6/Programming-Projects | /Python Exercises/ex16-DriveAge.py | 314 | 4.3125 | 4 | #Program to determine if user can drive according to his or her age.
drivAge = 16
userAge = int(input("What is your age? "))
if userAge <= 0:
print("Please enter a valid age.")
elif userAge > 0 and userAge < drivAge:
print("You are not old enough to legally drive.")
else:
print("You are allowed to drive.")
| true |
c1918e556d13f357889d5f2196abfbd9811a758c | friver6/Programming-Projects | /Python Exercises/ex28-AddingNums.py | 263 | 4.125 | 4 | #Prompts for five numbers and computes the total.
total = 0
numInput = 0
usrInput = ""
for i in range(0,5):
usrInput = input("Enter a number: ")
if usrInput.isdecimal():
numInput = int(usrInput)
total += numInput
print("The total is {}.".format(total))
| true |
cdea4e4f0c0489edba630b95b4467efd84ae8a1f | friver6/Programming-Projects | /Python Exercises/ex18-TempConv.py | 678 | 4.34375 | 4 | #Converts between Fahrenheit and Celsius and vice-versa.
print("Press C to convert from Fahrenheit to Celsius.\nPress F to convert from Celsius to Fahrenheit.\n")
usrChoice = input("Your choice: ")
if usrChoice == "C" or usrChoice == "c":
usrTemp = float(input("Please enter the temperature in Fahrenheit: "))
convTe... | true |
206bf39105de0fa5388ec4635523c0e1378becf4 | rishavsharma47/ENC2020P1 | /Session10G.py | 2,477 | 4.21875 | 4 | """
OOPS : Object Oriented Programming Structure
How we design Software
Its a Methodology
1. Object
2. Class
Real World
Object : Anything which exists in Reality
Class : Represents how an object will look like
Drawing of an Object
Princ... | true |
98a87be0f2fe544c1db9d42800763be8a086562a | BurnsCommaLucas/Sorts | /python/bubble.py | 618 | 4.125 | 4 | #!/usr/bin/env python
"""bubble.py: Sorts an array of integers using bubble sort"""
__author__ = "Lucas Burns"
__version__ = "2017-9-28"
import process
def sort(items):
swapped = True
while (swapped):
swapped = False
for i in range(0, len(items) - 1):
process.comparisons += 1
if items[i] > items[i + 1]:... | true |
973dbd6c6cacda7b83e94d537eef50d729701423 | srivenkat13/OOP_Python | /Association _example.py | 892 | 4.25 | 4 | # two classes are said to associated if there is relation between classes without any rule
# be it aggregation , association and composition the object of one class is 'owned' by other class, this is the common point
# In composition they work together but, if one classes dissapears other will also sieze to exist
class... | true |
192e5f3604b9d11c1192fa42aabcc8b0d130d36e | RaghaviRShetty/pythonassignment | /ebill.py | 307 | 4.125 | 4 | # -*- coding: utf-8 -*-
units = int(input(" Please enter Number of Units you Consumed : "))
if(units <=100):
amount = units * 2
elif(units > 100 and units<=200):
amount = units*3
elif(units > 200 and units<=300):
amount = units*5
else:
amount =units*6
print("\nElectricity Bill = ",amount) | true |
80b10f042795a094b4b72b22a3fca9f153ffeb02 | Sinfjell/FOR14 | /Workshops/week_36 - Variables_and_strings/exercise_4.py | 810 | 4.625 | 5 | # -*- coding: utf-8 -*-
"""
@author: Isabel Hovdahl
"""
"""
Exercise 4
Modify this week’s class exercise so that the temperature conversion program
instead converts temperatures from celsius to fahrenheit.
The program should:
- prompt the user for a temperature in celsius
- display the conve... | true |
e51133c3d5c0a4389a342db4d71dd204146e8ac3 | Sinfjell/FOR14 | /Workshops/week_38 - loops/Exercise_1a.py | 1,294 | 4.53125 | 5 | # -*- coding: utf-8 -*-
"""
@author: Isabel Hovdahl
"""
"""
Exercise 1a
Modify the random number generator from last workshop so that the
program now draws multiple random numbers within the given bounds.
The program should now:
- prompt the user for a lower and upper bound, and for the numbe... | true |
0001040e8215e2f2e687d3d162a6c0812bc67d01 | Sinfjell/FOR14 | /Workshops/week_41 - Lists/Exercise_1b.py | 1,332 | 4.4375 | 4 | # -*- coding: utf-8 -*-
"""
@author: Isabel Hovdahl
"""
"""
Exercise 1b:
Write a program that creates a table with the tests scores of students.
The table should be in the form of a nested list where each sublist
contains the tests scores for a spesific student.
The program should:
- prompt... | true |
f482dd234cd32a129e1e19db26dac4bd0cbf9ed3 | Sinfjell/FOR14 | /Workshops/week_37 - Decisions/Exercise_3.py | 1,241 | 4.28125 | 4 | # -*- coding: utf-8 -*-
"""
@author: Isabel Hovdahl
"""
"""
Exercise 3
The prisoner’s dilemma is a common example used in game theory.
One example of the game is found in the table below (see slide).
Write a program that implements the game. The program should:
- prompt the user for two inputs... | true |
4d3cc4a33f6b0a0f13c703a7a5eeca8a52eb83cf | jlyu/chain-leetcode | /expired/algorithm/341. Flatten Nested List Iterator.py | 2,826 | 4.5625 | 5 | # -*- coding: utf-8 -*-
import time
"""
https://leetcode.com/problems/flatten-nested-list-iterator/
Given a nested list of integers, implement an iterator to flatten it.
Each element is either an integer, or a list -- whose elements may also be integers or other lists.
Example 1:
Given the list [[1,1],2,[1,1]],
By ... | true |
038b2a2e1d1515decbf7a42cab33f3573e94c071 | whitem1396/CTI110 | /P5HW1_RandomNumber_White.py | 994 | 4.28125 | 4 | ''' P5HW1 Random Number
Matthew White
03/18/2019
Random number generator '''
# Display a random number in the range of 1 to 100
import random
def get_number():
# Get the random number
number = random.randint(1, 100)
# Ask the user to guess the number
guess = int(input("Gues... | true |
d41ebd2cfa5967513e89ecc7080b64c7786ae9bf | fhansmann/coding-basics | /mini-programs/birthdays.py | 1,139 | 4.40625 | 4 | birthdays = {'Alice' : 'Apr 1', 'Bob' : 'Dec 12', 'Carol' : 'Mar 4'}
while True:
print('Enter a name: (blank to quit)')
name = input()
if name == '':
break
if name in birthdays:
print(birthdays[name] + ' is the birthday of ' + name)
else:
print('I do not have birthday inform... | true |
8d941369d1a3d3caa1b19dfb0a24e9fa6e740bc1 | blazehalderman/PythonAlgorithms | /ThreeNumberSum/threenumbersum.py | 765 | 4.34375 | 4 | """
Write a function that takes in a non-empty array of distinct integers and an
integer representing a target sum. The function should find all triplets in
the array that sum up to the target sum and return a two-dimensional array of
all these triplets. The numbers in each triplet should be ordered in ascendin... | true |
acb9969798a28f201ebba4e1262e75db79d86f69 | blazehalderman/PythonAlgorithms | /Two Number Sum/Two-Number-Sum.py | 597 | 4.1875 | 4 | """
Write a function that takes in a non-empty array of distinct integers and an
integer representing a target sum. If any two numbers in the input array sum
up to the target sum, the function should return them in an array, in any
order. If no two numbers sum up to the target sum, the function should return
... | true |
bacfee8695b0ea151fb60d82b4e308c17c798bb4 | apeterlein/A-Short-Introduction-To-Python | /AShortIntroductionToPython/9_Intro_To_Euler_Problems.py | 2,497 | 4.15625 | 4 | # A Short Introduction To Python
# FILE 9 - INTRO TO EULER PROBLEMS
# Adam Peterlein - Last updated 2019-01-29 with python 3.6.5 and Visual Studio 15.7.1.
# Any questions, suggestions, or comments welcome and appreciated.
# For the remainder of this tutorial series we will focus on something called "Euler proble... | true |
f9c881baee98ff82427dbe5b13a8d53e83386671 | rohira-dhruv/Python | /Blackjack/main.py | 2,657 | 4.125 | 4 |
from art import logo_blackjack
import os
import random
def clear():
"""This function is used to clear the terminal window for a better user experience"""
os.system('cls')
def deal_card():
"""This function returns a randomly drawn card from a deck of cards"""
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10,... | true |
61261f7f230376b91f30c878c441383af2f60d16 | evelandy/Remove-Headers-from-CSV-Files | /HeaderRemoveCSV.py | 1,171 | 4.15625 | 4 | #!/usr/bin/env python3
"""evelandy/W.G.
Nov. 3, 2018 7:31pm
Remove-Headers-from-CSV-Files
Python36-32
Removes Headers from .CSV files
"""
import csv
import os
# This makes a new folder in the directory that you input and leaves the one there if one exists
directory = input("Enter the directory for your .csv files: ")... | true |
083eb84db09598f89b5c2b12c4e919f72fd2cc3b | SwapnilBhosale/DSA-Python | /bit_manipulation/chek_pow_2.py | 937 | 4.625 | 5 | '''
Check whether given number is power of 2.
The logic is , if we AND the power of 2 number with the number one less that that,
the output will be zero
example: We are checking if 8 is power of 2
8 -> 1000
7 -> 0111
8 & 7 = 1 0 0 0
0 1 1 1
---------
0 ... | true |
36e466e0b67dabeb375aebce6023f9ef35bc39ba | aaaaatoz/leetcode | /algorithms/python/powerofN.py | 770 | 4.1875 | 4 | """
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
Credits:
Special thanks to @yukuairoy for adding this problem and creating all test cases.
Subscribe ... | true |
bd2a7b005121f31fe646f34ab4bdca6aca6a9662 | Amjad-hossain/algorithm | /basic/reverse_string.py | 1,246 | 4.625 | 5 | # /**
# * Reverse a string without affecting special characters
# * Given a string, that contains special character together with alphabets
# * (‘a’ to ‘z’ and ‘A’ 'Z’), reverse the string in a way that special characters are not affected.
# *
# * Examples:
# *
# * Input: str = "a,b$c"
# * Output: str = "c,b... | true |
63f4ed10ed7f58c2c2f0b8f2c531f270ad12894e | euphwes/Project-Euler-Python | /problems/problem_38.py | 1,833 | 4.15625 | 4 | """
Pandigital multiples
--------------------
Take the number 192 and multiply it by each of 1, 2, and 3:
192 × 1 = 192
192 × 2 = 384
192 × 3 = 576
By concatenating each product we get the 1 to 9 pandigital, 192384576.
We will call 192384576 the concatenated product of 192 and (1,2,3)
The same can be achieved by sta... | true |
4b419589c596829305b2cb76999ea64a59c207ac | translee/learn_python_answers | /even_or_odd.py | 219 | 4.1875 | 4 | number=input("Enter a number.and I'll tell you if it's even or odd: ")
number=int(number)
if number%2==0:
print("\nThe number "+str(number)+" is even.")
else:
print("\nThe number "+str(number)+" is odd.")
| true |
99b3bde0232a3f0fb8fd7188f738de98671bfb1a | mkvenkatesh/CrackTheCode | /Stack & Queue/three_in_one.py | 2,599 | 4.4375 | 4 | # Describe how you could use a single array to implement three stacks.
# push top of the array, pop top of the array, peek top of the array, is_empty() - O(1)
# solutions
# 1. use array of arrays
# 2. if you have a fixed size array, divide by 3 and use modulo to define the
# lower and upper limits of each stack. u... | true |
1fff0364d53459a4d557796e07f73e0741c68fef | mkvenkatesh/CrackTheCode | /Linked List/delete_middle_node.py | 1,316 | 4.15625 | 4 | # Implement an algorithm to delete a node in the middle (i.e., any node but the
# first and last node, not necessarily the exact middle) of a singly linked
# list, given only access to that node.
# EXAMPLE
# Input:the node c from the linked list a->b->c->d->e->f
# Result: nothing is returned, but the new linked list l... | true |
7a8165c6de5b7c049c8ff0ab2f34bb61fd47b5cb | mkvenkatesh/CrackTheCode | /Trees & Graphs/validate_bst_recrusion.py | 1,562 | 4.25 | 4 | # Implement a function to check if a binary tree is a binary search tree.
# example 1
# 10
# 4 17
# 3 5 11 18
# example 2
# 10
# 4 17
# 3 5 6 18
# solution
# 1. maintain two vars - MIN and MAX that you keep updating as you traverse down
# the tree. Moving to the left, update... | true |
ba6827952b6e40869c6df721fcb32333cd8f6daa | mkvenkatesh/CrackTheCode | /Trees & Graphs/check_balanced.py | 2,420 | 4.21875 | 4 | # check balanced - Implement a function to check if a binary tree is balanced.
# For the purposes of this question, a balanced tree is defined to be a tree
# such that the heights of the two subtrees of any node never differ by more
# than one.
# examples
# 9
# 8 7
# 6 5 1 8... | true |
a39775a0b1be47236a09fb74e26f06e45d79442b | jsdeveloper63/Python-Sqlite | /ConditionSearchGet.py | 1,062 | 4.375 | 4 | import sqlite3
#Create the database
conn = sqlite3.connect("Electricity.db")
#Cursor method is used to go through the database
c = conn.cursor()
#Select individual column from the table
#c.execute("SELECT period FROM electricity")
#Prints/Gives data from all columns
#c.execute("SELECT * FROM electricity")
#data = ... | true |
39441d61b7d370db5d9092b149b224ea9d02eacb | Alwayswithme/LeetCode | /Python/116-populating-next-right-pointers-in-each-node.py | 1,835 | 4.1875 | 4 | #!/bin/python
#
# Author : Ye Jinchang
# Date : 2015-10-08 13:23:10
# Title : 116 populating next right pointers in each node
# Given a binary tree
#
# struct TreeLinkNode {
# TreeLinkNode *left;
# TreeLinkNode *right;
# TreeLinkNode *next;
# }
#
# Populate each next poi... | true |
7c3b522f1f6a70dd4f718297f4077801f2664f6f | Alwayswithme/LeetCode | /Python/098-validate-binary-search-tree.py | 1,134 | 4.15625 | 4 | #!/bin/python
#
# Author : Ye Jinchang
# Date : 2015-09-17 20:10:24
# Title : 098 validate binary search tree
# Given a binary tree, determine if it is a valid binary search tree (BST).
#
# Assume a BST is defined as follows:
#
# The left subtree of a node contains only nodes with keys less tha... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.