blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
3ec6fd0dcd97904b08c95fe17cac67b03a75a61f | luthraG/ds-algo-war | /general-practice/11_09_2019/p11.py | 648 | 4.15625 | 4 | '''
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
'''
from timeit import default_timer as timer
power = int(input('Enter the power that needs to be raised to base 2 :: '))
start = timer()
sum_of_digits = 0
number = 2 << (power - 1)
numb... | true |
33f5c2d803562730098d3b4393d5843d9d2f9d4a | luthraG/ds-algo-war | /general-practice/14_09_2019/p18.py | 1,586 | 4.34375 | 4 | '''
https://leetcode.com/problems/unique-email-addresses/
Every email consists of a local name and a domain name, separated by the @ sign.
For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.
Besides lowercase letters, these emails may contain '.'s or '+'s.... | true |
2016817647c32c5e148437225c826b39f2ce8ee4 | luthraG/ds-algo-war | /general-practice/10_09_2019/p3.py | 2,228 | 4.125 | 4 | class Node:
def __init__(self, data = None):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.start_node = Node()
def add_to_start(self, data):
node = Node(data)
node.next = self.start_node.next
self.start_node.next = node
... | true |
b3aaf2652c1cfda99a9c3b3c8e1d7d47b358abb4 | luthraG/ds-algo-war | /general-practice/18_09_2019/p12.py | 1,035 | 4.15625 | 4 | '''
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
Example 1:
Input: ["flower","flow","flight"]
Output: "fl"
Example 2:
Input: ["dog","racecar","car"]
Output: ""
Explanation: There is... | true |
6d53601a7fc6a0c2fb2e35f5685770bd5e771798 | stollcode/GameDev | /game_dev_oop_ex1.py | 2,829 | 4.34375 | 4 | """
Game_dev_oop_ex1
Attributes: Each class below, has at least one attribute defined. They hold
data for each object created from the class.
The self keyword: The first parameter of each method created in a Python program
must be "self". Self... | true |
0f227ae102e644024608c93a33dac90b39f2dcb9 | greenblues1190/Python-Algorithm | /LeetCode/14. 비트 조작/393-utf-8-validation.py | 1,893 | 4.15625 | 4 | # https://leetcode.com/problems/utf-8-validation/
# Given an integer array data representing the data, return whether it is a valid UTF-8 encoding.
# A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:
# For a 1-byte character, the first bit is a 0, followed by its Unicode code.
# Fo... | true |
02bd64d1871d08a5ef5354e4962074dc01363b8e | darrenthiores/PythonTutor | /Learning Python/level_guessing.py | 2,170 | 4.125 | 4 | # membuat app number guessing dengan level berbeda
import random
def low_level() :
number = random.randint(1,10)
chances = 3
while (chances > 0) :
guess = int(input('Your guess : '))
if (guess == number) :
print ('Congratss you win the game!!')
break
elif (g... | true |
9b39f95066e6bf5919683302f61adc5f40300a60 | younism1/Checkio | /Password.py | 1,673 | 4.15625 | 4 | # Develop a password security check module.
# The password will be considered strong enough if its length is greater than or equal to 10 symbols, it has at least
# one digit, as well as containing one uppercase letter and one lowercase letter in it.
# The password contains only ASCII latin letters or digits.
# Input: ... | true |
522385d08ccd855e401d141f9f4e8ccf1535f926 | purwokang/learn-python-the-hard-way | /ex6.py | 971 | 4.15625 | 4 | # creating variable x that contains format character
x = "There are %d types of people." % 10
# creating variable binary
binary = "binary"
# creating variable do_not
do_not = "don't"
# creating variable y, contains format character
y = "Those who know %s and those who %s." % (binary, do_not)
# printing content of v... | true |
ea1e981b9a899e15fddce5b28d20ea97c05b5ccd | lovingstudy/Molecule-process | /point2Plane.py | 1,296 | 4.15625 | 4 | #---------------------------------------------------------------------------------------------------
# Name: point2Plane.py
# Author: Yolanda
# Instruction: To calculate the distance of a point to a plane, which is defined by 3 other points,
# user should input the coordinates of 3 points in the plane into (x1,y1,z1... | true |
3c1219e7c7c57db39fc61e7551c9e3e8808fadb7 | league-python-student/level1-module2-ezgi-b | /_01_writing_classes/_b_intro_to_writing_classes.py | 2,725 | 4.3125 | 4 | """
Introduction to writing classes
"""
import unittest
# TODO Create a class called student with the member variables and
# methods used in the test class below to make all the tests pass
class Student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
self.homework_d... | true |
e897af19e5fdf1f6ab3568b14ae124c5971a2a57 | Prabhjyot2/workshop-python | /L2/P2.py | 235 | 4.40625 | 4 | #wapp to read radius of circle & find the area & circumference
r = float(input("Enter the radius "))
pi = 3.14
area = pi * r** 2
print("area=%.2f" %area)
cir = 2 * pi * r
print("cir=%.4f" %cir)
print("area=", area, "cir=", cir )
| true |
532793eb6901f35e2184ab5b510aea233c5a484b | Sher-Chowdhury/CentOS7-Python | /files/python_by_examples/loops/iterations/p02_generator.py | 845 | 4.34375 | 4 | # functions can return multiple values by using the:
# return var1,var2....etc
# syntax.
# you can also do a similar thing using the 'yield' keyword.
fruits = ['apple', 'oranges', 'banana', 'plum']
fruits_iterator = iter(fruits)
# we now use the 'next' builtin function
# https://docs.python.org/3.3/l... | true |
f9886344b8c61878d322680525f4f4afe8220042 | abbi163/MachineLearning_Classification | /KNN Algorithms/CustomerCategory/teleCust_plots.py | 873 | 4.125 | 4 | import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('E:\Pythoncode\Coursera\Classification_Algorithms\KNN Algorithms\CustomerCategory/teleCust1000t.csv')
# print(df.head())
# value_counts() function is used to count different value separately in column custcat
# eg.
# 3 281
# 1 ... | true |
491ffe454bdd5161ea332eb5114561b1a56b8e36 | sacheenanand/pythondatastructures | /ReverseLinkedList.py | 557 | 4.1875 | 4 | __author__ = 'sanand'
# To implement reverse Linked we need 3 nodes(curr, prev and next) we are changing only the pointers here.
class node:
def __init__(self, value, nextNode=None):
self.value = value
self.nextNode = nextNode
class LinkedList:
def __init__(self, head):
self.head = he... | true |
04dce36f9f552216ea548da767dbf306fc2de8e9 | mrvbrn/HB_challenges | /medium/code.py | 1,162 | 4.1875 | 4 | """TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl
and it returns a short URL such as http://tinyurl.com/4e9iAk.
Design the encode and decode methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work.
You jus... | true |
289820dd78f4cf13538bde92149ae03d3e93784c | mrvbrn/HB_challenges | /hard/patternmatch.py | 2,712 | 4.59375 | 5 | """Check if pattern matches.
Given a "pattern string" starting with "a" and including only "a" and "b"
characters, check to see if a provided string matches that pattern.
For example, the pattern "aaba" matches the string "foofoogofoo" but not
"foofoofoodog".
Patterns can only contain a and b and must start with a:
... | true |
560459ddf49384a758c3bcfde15517ba99e44077 | shaikharshiya/python_demo | /fizzbuzzD3.py | 278 | 4.15625 | 4 | number=int(input("Enter number"))
for fizzbuzz in range(1,number+1):
if fizzbuzz % 3==0 and fizzbuzz%5==0:
print("Fizz-Buzz")
elif fizzbuzz % 3==0:
print("Fizz")
elif fizzbuzz % 5==0:
print("Buzz")
else:
print(fizzbuzz)
| true |
c21f73253780164661997fa29d873dec5a4803ce | A7xSV/Algorithms-and-DS | /Codes/Py Docs/Zip.py | 424 | 4.4375 | 4 | """ zip()
This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.
The returned list is truncated in length to the length of the shortest argument sequence. """
x = [1, 2, 3, 4]
y = [5, 6, 7, 8]
print x
print y
zipped = zip(x, y)
... | true |
a194787f8f7e817bf3b7166bcb3b9bce96e024ef | ataylor1184/cse231 | /Proj01/Project01.py | 1,221 | 4.46875 | 4 |
#######################################################
# Computer Project #1
#
# Unit Converter
# prompt for distance in rods
# converts rods to different units as floats
# Outputs the distance in multiple units
# calculates time spent walking that distance
#... | true |
7f3dc6666df5dbc8b2144dd22a4c175a299aa599 | Princess-Katen/hello-Python | /13:10:2020_Rock_Paper_Scissors + Loop _v.4.py | 1,696 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 13:18:18 2020
@author: tatyanamironova
"""
from random import randint
player_wins = 0
computer_wins = 0
winning_score = 3
while player_wins < winning_score and computer_wins < winning_score:
print (f'Player score: {player_wins} Computer sco... | true |
556c8b35139d8948b0c218579785dd640b57acde | prateek-chawla/DailyCodingProblem | /Solutions/Problem_120.py | 1,456 | 4.1875 | 4 | '''
Question -->
This problem was asked by Microsoft.
Implement the singleton pattern with a twist. First, instead of storing one instance,
store two instances. And in every even call of getInstance(), return the
first instance and in every odd call of getInstance(), return the second instance.
Approach -->
Create two... | true |
8e5c8f5ee8b8540d1c9d91dee38b44d67da57580 | franky-codes/Py4E | /Ex6.1.py | 433 | 4.375 | 4 | #Example - use while loop to itterate thru string & print each character
fruit = 'BANANA'
index = 0
while index < len(fruit):
letter = fruit[index]
print(letter)
index = index + 1
#Exercise - use while loop to itterate thru string backwards
fruit = 'BANANA'
index = -1 # because len(fruit) - 1 is the last i... | true |
43716fe322cd9e307b98cefa32a1e35a1d387b87 | omvikram/python-ds-algo | /dynamic-programming/longest_increasing_subsequence.py | 2,346 | 4.28125 | 4 | # Dynamic programming Python implementation of LIS problem
# lis returns length of the longest increasing subsequence in arr of size n
def maxLIS(arr):
n = len(arr)
# Declare the list (array) for LIS and
# initialize LIS values for all indexes
lis = [1]*n
# Compute optimized LIS values in bottom up manne... | true |
b4c01ca063d09ba24aff1bfe44c719043d24d1c3 | omvikram/python-ds-algo | /dynamic-programming/pattern_search_typo.py | 1,035 | 4.28125 | 4 | # Input is read from the standard input. On the first line will be the word W.
# On the second line will be the text to search.
# The result is written to the standard output. It must consist of one integer -
# the number of occurrences of W in the text including the typos as defined above.
# SAMPLE INPUT
# banana... | true |
a3ca34db407b81382afc3e61e6abbc74eed86c3a | omvikram/python-ds-algo | /dynamic-programming/bit_count.py | 568 | 4.3125 | 4 | # Function to get no of bits in binary representation of positive integer
def countBits(n):
count = 0
# using right shift operator
while (n):
count += 1
n >>= 1
return count
# Driver program
i = 65
print(countBits(i))
##########################################################################
# Pytho... | true |
5fff518a9ffe783632b8d28920772fbc7ab54467 | omvikram/python-ds-algo | /data-strucutres/linked_list.py | 1,483 | 4.4375 | 4 | # Python program to create linked list and its main functionality
# push, pop and print the linked list
# Node class
class Node:
# Constructor to initialize
# the node object
def __init__(self, data):
self.data = data
self.next = None
# LinkedList class
class LinkedList:
# Function ... | true |
8ac6c88830679c6fb29732e283ec1884d30fdaa8 | omvikram/python-ds-algo | /data-strucutres/heap.py | 742 | 4.125 | 4 | import heapq
## heapify - This function converts a regular list to a heap. In the resulting heap the smallest element
## gets pushed to the index position 0. But rest of the data elements are not necessarily sorted.
## heappush – This function adds an element to the heap without altering the current heap.
## heappop ... | true |
43486f405621613de5d973ecfa3dfed21356969f | Adil-Anzarul/VSC-codes-c-cpp-python | /python_language/W11p2.py | 1,257 | 4.75 | 5 | # Give a string, remove all the punctuations in it and print only the words
# in it.
# Input format :
# the input string with punctuations
# Output format :
# the output string without punctuations
# Example
# input
# “Wow!!! It’s a beautiful morning”
# output
# Wow Its a beautiful morning
# # Pytho... | true |
ddce169af5d2b344a2d3ce1e4e90a8c381f767af | Adil-Anzarul/VSC-codes-c-cpp-python | /python_language/W9p2.py | 949 | 4.1875 | 4 | # Panagrams
# Given an English sentence, check whether it is a panagram or not.
# A panagram is a sentence containing all 26 letters in the English alphabet.
# Input Format
# A single line of the input contains a stirng s.
# Output Format
# Print Yes or No
# Example:
# Input:
# The quick brown fox jumps over a lazy ... | true |
7e21b51ec88b79191088614971bbc325fff0fabf | AhhhHmmm/Programming-HTML-and-CSS-Generator | /exampleInput.py | 266 | 4.15625 | 4 | import turtle
# This is a comment.
turtle = Turtle()
inputs = ["thing1", "thing2", "thing3"]
for thing in inputs:
print(thing) # comment!!!
print(3 + 5) # little comment
print('Hello world') # commmmmmmm 3 + 5
print("ahhhh") # ahhhh
if x > 3:
print(x ** 2) | true |
df7282d45332baf2d25d9ca1794b55cd802aac6c | evab19/verklegt1 | /Source/models/Airplane.py | 1,156 | 4.25 | 4 | class Airplane:
'''Module Airplane class
Module classes are used by the logic layer classes to create new instances of Airplane
gets an instance of a Airplane information list
Returns parameters if successful
---------------------------------
'''
... | true |
905df9bcdb837b6e0692e1b2033aff9f72619a45 | DrakeDwornik/Data2-2Q1 | /quiz1/palindrome.py | 280 | 4.25 | 4 | def palindrome(value: str) -> bool:
"""
This function determines if a word or phrase is a palindrome
:param value: A string
:return: A boolean
"""
result = True
value_rev = value[::-1]
if value != value_rev:
result = False
return result | true |
15250c4e99d8133175c5956444b1473f70f194bb | Steven98788/Ch.03_Input_Output | /3.1_Temperature.py | 446 | 4.5 | 4 | '''
TEMPERATURE PROGRAM
-------------------
Create a program that asks the user for a temperature in Fahrenheit, and then prints the temperature in Celsius.
Test with the following:
In: 32 Out: 0
In: 212 Out: 100
In: 52 Out: 11.1
In: 25 Out: -3.9
In: -40 Out: -40
'''
print("Welcome to my Fahrenheit to Celsius ... | true |
30cb2152ba61fdc70e20fde9f9b71daa05ffafa1 | divyachandramouli/Data_structures_and_algorithms | /4_Searching_and_sorting/Bubble_sort/bubble_sort_v1.py | 555 | 4.21875 | 4 | # Implementation of bubble sort
def bubble_sorter(arr):
n=len(arr)
i=0
for j in range(0,n):
for i in range(0,n-j-1):
#In the jth iteration, last j elements have bubbled up so leave them
if (arr[i]>arr[i+1]):
arr[i],arr[i+1]=arr[i+1],arr[i]
return arr
array1=[21,4,1,3,9,20,25,6,21,14]
prin... | true |
3f3205aea8dd64a69b9ed91f6aab600d63da9475 | divyachandramouli/Data_structures_and_algorithms | /3_Queue/Queue_builtin.py | 384 | 4.21875 | 4 | # Queue using Python's built in functions
# Append adds an element to the tail (newest element) :Enqueue
# Popleft removes and returns the head (oldest element) : Dequeue
from collections import deque
queue=deque(["muffin","cake","pastry"])
print(queue.popleft())
# No operation called popright - you dequeue the head w... | true |
91a3b5ba76ba9b77775c981e048aec2cae7e8d9d | Fabulinux/Project-Cognizant | /Challenges/Brian-08302017.py | 1,007 | 4.25 | 4 | import sys
def main():
# While loop to check if input is valid
while(1):
# Try/Except statement for raw_input return
try:
# Prompt to tell user to input value then break out of while
val = int(raw_input("Please input a positive integer: ").strip())
break
... | true |
78f333af2427a13909aa28b67c4be1675d3e81f7 | AlexOKeeffe123/mastermind | /game/board.py | 2,682 | 4.15625 | 4 | import random
from typing import Text
#Chase
class Board:
def __init__(self, length):
"""The class constructor
Args:
self (Display): an instance of Display
"""
self._items = {} # this is an empty dictionary
self._solutionLength = length
def to_string(self):
"""Convert... | true |
b614122fb0117d4dd5afb5f148f5f803013a3397 | LeedsCodeDojo/Rosalind | /AndyB_Python/fibonacci.py | 1,355 | 4.25 | 4 |
def fibonacci(n, multiplier=1):
"""
Generate Fibonacci Sequence
fib(n) = fib(n-1) + fib(n-2)*multiplier
NB Uses recursion rather than Dynamic programming
"""
if n <= 2:
return 1
return fibonacci(n-1, multiplier) + fibonacci(n-2, multiplier) * multiplier
def fibonacciDynamic(n,... | true |
65a0a9921a54d50b0e262cccf64d980c2762f2f7 | edwinjosegeorge/pythonprogram | /longestPalindrome.py | 838 | 4.125 | 4 | def longestPalindrome(text):
'''Prints the longest Palendrome substring from text'''
palstring = set() #ensures that similar pattern is stored only once
longest = 0
for i in range(len(text)-1):
for j in range(i+2,len(text)+1):
pattern = text[i:j] #generates words of min lenght 2 (s... | true |
c3e4d19ad6b650bd400a75799c512bb8eecad4c9 | ldswaby/CMEECourseWork | /Week3/Code/get_TreeHeight.py | 2,274 | 4.5 | 4 | #!/usr/bin/env python3
"""Calculate tree heights using Python and writes to csv. Accepts Two optional
arguments: file name, and output directory path."""
## Variables ##
__author__ = 'Luke Swaby (lds20@ic.ac.uk), ' \
'Jinkai Sun (jingkai.sun20@imperial.ac.uk), ' \
'Acacia Tang (t.tang20@imp... | true |
954c952dba2e72d6b70c9d345b96090b0a43b732 | timmy61109/Introduction-to-Programming-Using-Python | /examples/TestSet.py | 549 | 4.3125 | 4 | from Set import Set
set = Set() # Create an empty set
set.add(45)
set.add(13)
set.add(43)
set.add(43)
set.add(1)
set.add(2)
print("Elements in set: " + str(set))
print("Number of elements in set: " + str(set.getSize()))
print("Is 1 in set? " + str(set.contains(1)))
print("Is 11 in set? " + str(set.contains(11)))... | true |
f20df9950890ea3b43729837524065283366aa60 | timmy61109/Introduction-to-Programming-Using-Python | /examples/ComputeFactorialTailRecursion.py | 322 | 4.15625 | 4 | # Return the factorial for a specified number
def factorial(n):
return factorialHelper(n, 1) # Call auxiliary function
# Auxiliary tail-recursive function for factorial
def factorialHelper(n, result):
if n == 0:
return result
else:
return factorialHelper(n - 1, n * result) # Recursive cal... | true |
0ad23dca684097914370ac9f35a385b80ed74cc4 | timmy61109/Introduction-to-Programming-Using-Python | /examples/ComputeLoan.py | 687 | 4.21875 | 4 | # Enter yearly interest rate
annualInterestRate = eval(input(
"Enter annual interest rate, e.g., 8.25: "))
monthlyInterestRate = annualInterestRate / 1200
# Enter number of years
numberOfYears = eval(input(
"Enter number of years as an integer, e.g., 5: "))
# Enter loan amount
loanAmount = eval(input("Enter l... | true |
97a050e009a2c1e53a1842a6c7de60a6d6148b90 | timmy61109/Introduction-to-Programming-Using-Python | /examples/QuickSort.py | 1,267 | 4.21875 | 4 | def quickSort(list):
quickSortHelper(list, 0, len(list) - 1)
def quickSortHelper(list, first, last):
if last > first:
pivotIndex = partition(list, first, last)
quickSortHelper(list, first, pivotIndex - 1)
quickSortHelper(list, pivotIndex + 1, last)
# Partition list[first..last]
def pa... | true |
324bb0fd6f126c77d953ba9dc1096f8bdb0d9a50 | timmy61109/Introduction-to-Programming-Using-Python | /examples/SierpinskiTriangle.py | 2,218 | 4.25 | 4 | from tkinter import * # Import tkinter
class SierpinskiTriangle:
def __init__(self):
window = Tk() # Create a window
window.title("Sierpinski Triangle") # Set a title
self.width = 200
self.height = 200
self.canvas = Canvas(window,
width = self.width... | true |
bf8d3d46a74e9da8fe560231ceb161cd57a3316d | timmy61109/Introduction-to-Programming-Using-Python | /examples/MergeSort.py | 1,246 | 4.21875 | 4 | def mergeSort(list):
if len(list) > 1:
# Merge sort the first half
firstHalf = list[ : len(list) // 2]
mergeSort(firstHalf)
# Merge sort the second half
secondHalf = list[len(list) // 2 : ]
mergeSort(secondHalf)
# Merge firstHalf with secondHalf into list
... | true |
674a0def98a2f37c3dae8cf1ce070c767431b66a | timmy61109/Introduction-to-Programming-Using-Python | /examples/EfficientPrimeNumbers.py | 1,451 | 4.15625 | 4 | def main():
n = eval(input("Find all prime numbers <= n, enter n: "))
# A list to hold prime numbers
list = []
NUMBER_PER_LINE = 10 # Display 10 per line
count = 0 # Count the number of prime numbers
number = 2 # A number to be tested for primeness
squareRoot = 1 # Check whether numbe... | true |
3eea73798a4ddc9043f2123d5ba6f919ca239929 | timmy61109/Introduction-to-Programming-Using-Python | /examples/DataAnalysis.py | 496 | 4.15625 | 4 | NUMBER_OF_ELEMENTS = 5 # For simplicity, use 5 instead of 100
numbers = [] # Create an empty list
sum = 0
for i in range(NUMBER_OF_ELEMENTS):
value = eval(input("Enter a new number: "))
numbers.append(value)
sum += value
average = sum / NUMBER_OF_ELEMENTS
count = 0 # The number of elements above ave... | true |
255e39ff64323b2afa0102ac92302511229317d6 | timmy61109/Introduction-to-Programming-Using-Python | /examples/TwoChessBoard.py | 1,263 | 4.15625 | 4 | import turtle
def main():
drawChessboard(-260, -20, -120, 120) # Draw first chess board
drawChessboard(20, 260, -120, 120) # Draw second chess board
turtle.hideturtle()
turtle.done()
# Draw one chess board
def drawChessboard(startx, endx, starty, endy):
# Draw chess board borders
turtle.pens... | true |
6bfb64ca94d7670bada63dfcd9229cba6baa3d25 | wjr0102/Leetcode | /Easy/MinCostClimb.py | 1,094 | 4.21875 | 4 | #!/usr/local/bin
# -*- coding: utf-8 -*-
# @Author: Jingrou Wu
# @Date: 2019-05-07 01:46:49
# @Last Modified by: Jingrou Wu
# @Last Modified time: 2019-05-07 01:53:03
'''
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).
Once you pay the cost, you can either climb one or two s... | true |
f7a5fe592f5c42ffa1b5d8f6d63d11d588403556 | ujjwalbaid0408/Python-Tutorial-with-Examples | /Ex22_StructuringElementForMorphological Transformations.py | 697 | 4.15625 | 4 | # Structuring element
"""
We manually created a structuring elements in the previous examples with help
of Numpy. It is rectangular shape. But in some cases, you may need elliptical/
circular shaped kernels. So for this purpose, OpenCV has a function,
cv2.getStructuringElement(). You just pass the shape and size... | true |
da60d5b35c0c7be1a238dd303ce6ce1f07d9ae80 | Max-Fu/MNISTPractice | /Digits_With_Neural_Network.py | 1,035 | 4.21875 | 4 | #!/usr/bin/python
#Import data and functions from scikit-learn packets, import plotting function from matplotlib
from sklearn.neural_network import MLPClassifier
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import svm
#load the digits and asign it to digits
digits = datasets.load_digits... | true |
521f7092961eafb8ec49952366a9457e6549341f | HackerajOfficial/PythonExamples | /exercise1.py | 348 | 4.3125 | 4 | '''Given the following list of strings:
names = ['alice', 'bertrand', 'charlene']
produce the following lists: (1) a list of all upper case names; (2) a list of
capitalized (first letter upper case);'''
names = ['alice', 'bertrand', 'charlene']
upNames =[x.upper() for x in names]
print(upNames)
cNames = [x.title() f... | true |
fd9c99441cba0d403b6b880db4444f95874eeb0c | micriver/leetcode-solutions | /1684.py | 2,376 | 4.3125 | 4 | """
You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.
Return the number of consistent strings in the array words.
Example 1:
Input: allowed = "ab", words = ["ad","bd","aaab","baa","ba... | true |
aab785831638f7e29f6ca68343eff9c5cdc29c0e | micriver/leetcode-solutions | /1470_Shuffle_Array.py | 983 | 4.375 | 4 | """
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].
Return the array in the form [x1,y1,x2,y2,...,xn,yn].
Example 1:
Input: nums = [2,5,1,3,4,7], n = 3
Output: [2,3,5,4,1,7]
Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].
Example 2:... | true |
26b569a159c98d69b9bdadbb2c8e498bacc41edf | sumibhatta/iwbootcamp-2 | /Data-Types/26.py | 348 | 4.3125 | 4 | #Write a Python program to insert a given string at the beginning
#of all items in a list.
#Sample list : [1,2,3,4], string : emp
#Expected output : ['emp1', 'emp2', 'emp3', 'emp4']
def addString(lis, str):
newList = []
for item in lis:
newList.append(str+"{}".format(item))
return newList
print(a... | true |
3151f1dd3c21b3603d8c616b643cdfb3f25d79a3 | sumibhatta/iwbootcamp-2 | /Data-Types/12.py | 218 | 4.21875 | 4 | #Write a Python script that takes input from the user and
# displays that input back in upper and lower cases.
string = "Hello Friends"
upper = string.upper()
lower = string.lower()
print(string)
print(upper)
print(lower) | true |
aa5cdbd2c62421ab8a68d3112e4703ff70504bff | KenFin/sarcasm | /sarcasm.py | 1,715 | 4.25 | 4 | while True:
mainSentence = input("Enter your sentence here: ").lower() # making everything lowercase
letters = ""
isCapital = 0 # Re-initializing variables to reset the sarcastic creator
for letter in mainSentence:
if letter == " ": # If there's a space in the sentence, add it back into the final sentence... | true |
f44e6b5789ee7c3d75a1891cb4df186016ff8d1a | tgm1314-sschwarz/csv | /csv_uebung.py | 2,240 | 4.34375 | 4 | import csv
class CSVTest:
"""
Class that can be used to read, append and write csv files.
"""
@staticmethod
def open_file(name, like):
"""
Method for opening a csv file
"""
return open(name, like)
@staticmethod
def get_dialect(file):
"""
Me... | true |
c1249eca315f652960a09c2b903c93121c8a19c4 | saiso12/ds_algo | /study/OOP/Employee.py | 452 | 4.21875 | 4 | '''
There are two ways to assign values to properties of a class.
Assign values when defining the class.
Assign values in the main code.
'''
class Employee:
#defining initializer
def __init__(self, ID=None, salary=None, department=None):
self.ID = ID
self.salary = salary
self.departme... | true |
60f24bde8f1acd6637010627b439584eb8d08f32 | mosesobeng/Lab_Python_04 | /Lab04_2_3.py | 1,048 | 4.3125 | 4 | print 'Question 2'
##2a. They will use the dictionary Data Structure cause they will need a key and value
## where stock is the key and price is the value
shopStock ={'Apples ' : '7.3' , 'Bananas ' : '5.5' , 'Bread ' : '1.0' , 'Carrots ':'10.0','Champagne ':'20.90','Strawberries':'32.6'}... | true |
863c76edceb3d1e98acd52d7b45b114153532a1f | PreetiChandrakar/Letsupgrade_Assignment | /Day1.py | 634 | 4.125 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[4]:
num=int(input("Enter Number to check prime or not:"))
m=0
i=0
flag=0
m=int(num/2)
for i in range(2,m+1):
if(num%i==0) :
print("Number is not prime")
flag=1
break
if(flag==0) :
print("Number is prime")
# In[3]:
... | true |
ba934740e3a009ec713f7c3630b71ec56d9bb699 | killo21/poker-starting-hand | /cards.py | 2,285 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Wed Nov 25 17:30:27 2020
@author: dshlyapnikov
"""
import random
class Card:
def __init__(self, suit, val):
"""Create card of suit suit [str] and value val [int] 1-13
1 - Ace, 2 - 2, 3 - 3,..., 11 - Jack, 12 - Queen, 13 - King
suit can be "clu... | true |
141b6d72a3890b96f51838d1b4806763f0c60684 | sivaneshl/python_ps | /tuple.py | 801 | 4.25 | 4 | t = ('Norway', 4.953, 4) # similar to list, but use ( )
print(t[1]) # access the elements of a tuple using []
print(len(t)) # length of a tuple
for item in t: # items in a tuple can be accessed using a for
print(item)
print(t + (747, 'Bench')) # can be concatenated using + operator
print(t) # imm... | true |
a29a778e801e3ca3e9a5904fafca8310de0b0b43 | sivaneshl/python_ps | /range.py | 541 | 4.28125 | 4 | # range is a collection
# arithmetic progression of integers
print(range(5)) # supply the stop value
for i in range(5):
print(i)
range(5, 10) # starting value 5; stop value 10
print(list(range(5, 10))) # wrapping this call to the list
print(list(range(0, 10, 2))) # 2 is the step argument
# enumerate -... | true |
003112e87a05bb6da91942b2c5b3db98d082193a | joshua-hampton/my-isc-work | /python_work/functions.py | 370 | 4.1875 | 4 | #!/usr/bin/python
def double_it(number):
return 2*number
def calc_hypo(a,b):
if (type(a)==float or type(a)==int) and (type(b)==float or type(b)==int):
hypo=((a**2)+(b**2))**0.5
else:
print 'Error, wrong value type'
hypo=False
return hypo
if __name__ == '__main__':
print double_it(3)
print double_it(3.... | true |
d2822cfa674d1c3701c46e6fd305bf665f26ace4 | nkpydev/Algorithms | /Sorting Algorithms/Selection Sort/selection_sort.py | 1,030 | 4.34375 | 4 | #-------------------------------------------------------------------------#
#! Python3
# Author : NK
# Desc : Insertion Sort Implementation
# Info : Find largest value and move it to the last position.
#-------------------------------------------------------------------------... | true |
4cb75a34e0f6806c8990bc06079272effbc2451c | patrickdeyoreo/holbertonschool-interview | /0x19-making_change/0-making_change.py | 1,161 | 4.15625 | 4 | #!/usr/bin/python3
"""
Given a list of coin denominations, determine the fewest number of coins needed
to make a given amount.
"""
def makeChange(coins, total):
"""
Determine the fewest number of coins needed to make a given amount.
Arguments:
coins: list of coin denominations
total: total... | true |
31d07fd3332e0b6ca050f4ee3df184451287d710 | gauborg/code_snippets_python | /14_power_of_two.py | 1,220 | 4.625 | 5 | '''
Description: The aim of this code is to identify if a given numer is a power of 2.
The program requires user input.
The method keeps bisecting the number by 2 until no further division by 2 is possible.
'''
def check_power_of_two(a, val):
# first check if a is odd or equal to zero or an integer
... | true |
f65d53c042bebae591090aebbf16b3b155e0eee2 | gauborg/code_snippets_python | /7_random_num_generation.py | 1,416 | 4.5 | 4 | '''
This is an example for showing different types of random number generation for quick reference.
'''
# code snippet for different random options
import os
import random
# generates a floating point number between 0 and 1
random1 = random.random()
print(f"\nRandom floating value value between using random.random(... | true |
2c17e2b6ed89bebf30bbf9a2f25bb8f0793c0019 | jkamby/portfolio | /docs/trivia/modulesAndClients/realcalc.py | 1,358 | 4.15625 | 4 | import sys
import stdio
def add(x, y):
"""
Returns the addition of two floats
"""
return float(x) + float(y)
def sub(x, y):
"""
Returns the subtraction of two floats
"""
return float(x) - float(y)
def mul(x, y):
"""
Returns the multiplication of two floa... | true |
a743debf018b5322b6a681783aa0a009fbfd3b61 | karingram0s/karanproject-solutions | /fibonacci.py | 722 | 4.34375 | 4 |
#####---- checks if input is numerical. loop will break when an integer is entered
def checkInput(myinput) :
while (myinput.isnumeric() == False) :
print('Invalid input, must be a number greater than 0')
myinput = input('Enter number: ')
return int(myinput)
#####---- main
print('This will print the Fib... | true |
b97a94399afac9b9f793d680ffb01892f041ff25 | arononeill/Python | /Variable_Practice/Dictionary_Methods.py | 1,290 | 4.3125 | 4 | import operator
# Decalring a Dictionary Variable
dictExample = {
"student0" : "Bob",
"student1" : "Lewis",
"student2" : "Paddy",
"student3" : "Steve",
"student4" : "Pete"
}
print "\n\nDictionary method get() Returns the value of the searched key\n"
find = dictExample.get("student0")
print find
print "\n\nDict... | true |
e54903690eceffc1bd7b49faa2db0f79d111f974 | TheManyHatsClub/EveBot | /src/helpers/fileHelpers.py | 711 | 4.125 | 4 | # Take a file and read it into an array splitting on a given delimiter
def parse_file_as_array(file, delimiter=None):
# Open the file and get all lines that are not comments or blank
with open(file, 'r') as fileHandler:
read_data = [(line) for line in fileHandler.readlines() if is_blank_or_comment(line... | true |
97c80a0bc24deb72d908c283df28b314454bcfc5 | KHilse/Python-Stacks-Queues | /Queue.py | 2,139 | 4.15625 | 4 | class Node:
def __init__(self, data):
self.data = data
self.next = None
class Queue:
def __init__(self):
self.head = None
def isEmpty(self):
"""Returns True if Queue is empty, False otherwise"""
if self.head:
return False
return True
def enq... | true |
485458ce7505e832f81aab7520d9fa16db630e89 | kalstoykov/Python-Coding | /isPalindrome.py | 1,094 | 4.375 | 4 | import string
def isPalindrome(aString):
'''
aString: a string
Returns True if aString is a Palindrome
String strips punctuation
Returns False otherwise.
'''
alphabetStr = "abcdefghijklmnopqrstuvwxyz"
newStr = ""
# converting string to lower case and stripped of extra non alphabet c... | true |
db1eedd2b2ea011786f6b26d58a1f72e5349fceb | mirarifhasan/PythonLearn | /function.py | 440 | 4.15625 | 4 | #Function
# Printing the round value
print(round(3.024))
print(round(-3.024))
print(min(1, 2, 3))
#If we call the function without parameter, it uses the default value
def my_function(country = "Norway"):
print("I am from " + country)
my_function("Sweden")
my_function("India")
my_function()
#Array passing in fu... | true |
4235ddfb49c4281b0ecbb62fa93c9098ca025273 | davisrao/ds-structures-practice | /06_single_letter_count.py | 638 | 4.28125 | 4 | def single_letter_count(word, letter):
"""How many times does letter appear in word (case-insensitively)?
>>> single_letter_count('Hello World', 'h')
1
>>> single_letter_count('Hello World', 'z')
0
>>> single_letter_count("Hello World", 'l')
3
... | true |
99db5d93dd6673b1afa97701b1fb8d09294223c0 | timseymore/py-scripts | /Scripts/set.py | 485 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Sets
numerical sets and operations on them
Created on Tue May 19 20:08:17 2020
@author: Tim
"""
test_set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
# returns a set of numbers in given range (inclusive)
# that are divisible by either 2 or 3
def set_mod_2_3(size):
temp = {}
index = 0
f... | true |
4bdf487e4600dfd927e4419f0c25391cfbfb721c | timseymore/py-scripts | /Scripts/counting.py | 2,285 | 4.5 | 4 | # -*- coding: utf-8 -*-
"""
Counting
examples of counting and recursive counting used in cominatorics
We will be implementing a graph consisting of nodes
and then use recursive counting to find the number of
possible paths from the start node to any given node
in the graph.
The number of possible paths to any give... | true |
6832a42539daa56e2f4c04a1238236a2cfc31e98 | mmuratardag/DS_SpA_all_weeks | /DS_SpA_W10_Recommender_System/03_19/TeachMat/flask-recommender/recommender.py | 1,270 | 4.1875 | 4 | #!/usr/bin/env python
import random
MOVIES = ["The Green Book", "Django", "Hors de prix"]
# def get_recommendation():
# return random.choice(MOVIES)
def get_recommendation(user_input: dict):
m1 = user_input["movie1"]
r1 = user_input["rating1"]
m2 = user_input["movie2"]
r2 = user_input["rating... | true |
26fded563d3655f5f06e2cdf582d0cdc564ab9dc | yveslox/Genesisras | /practice-code-blue/programme-python/lists.py | 672 | 4.34375 | 4 | #!/usr/bin/python
list=[1,2,3,4,5,6,7,8];
print("list[0] :",list[0])
print("list[1] :",list[1])
print("list[2:5] :",list[2:5])
#updating list
list[3] = 44
print("list(after update):",list)
#delete element
del list[3]
print("list(after delete) :",list)
#length of list
print("length of list : ",len(list))
#appendi... | true |
9bac38cd3bc1014cc19216e4cbcda36f138dfef1 | Ri8thik/Python-Practice- | /creat wedge using loop/loop.py | 2,269 | 4.40625 | 4 | import tkinter as tk
from tkinter import ttk
root=tk.Tk()
# A) labels
#here we create a labels using loop method
# first we amke a list in which all the labels are present
labels=["user name :-","user email :-","age:-","gender:-",'state:-',"city:-"]
#start a for loop so that it print all the labels which are given in a... | true |
fca8a93a245b027c0cfee51200e9e603c737f5df | rchu6120/python_workshops | /comparison_operators.py | 234 | 4.21875 | 4 | x = [1, 2, 3]
y = list(x) # create a NEW list based on the value of x
print(x, y)
if x is y:
print("equal value and identity")
elif x == y:
print("equal value but unqual identity")
else:
print("unequal")
| true |
1ef7c763b40ab15b9bb07313edc9be70f9efd5d6 | rchu6120/python_workshops | /logic_hw.py | 852 | 4.375 | 4 | ############# Ask the user for an integer
### If it is an even number, print "even"
### If it is an odd number, print "odd"
### If it is not an integer (e.g. character or decimal #), continue asking the user for an input
### THIS PROGRAM SHOULND'T CRASH UNDER THESE CIRCUMSTANCES:
# The user enters an alphabet
#... | true |
5f5f657ef5fad9d08ad0a1657a97cbe83535cb09 | HeyChriss/BYUI-Projects-Spring-2021 | /Maclib.py | 1,453 | 4.25 | 4 | print ("Please enter the following: ")
adjective = input("adjective: ")
animal = input("animal: ")
verb1 = input("verb: ")
exclamation = input("exclamation: ")
verb2 = input("verb : ")
verb3 = input("verb: ")
print ()
print ("Your story is: ")
print ()
print (f"The other day, I was really in trouble. It all s... | true |
7e46e20703c0a192343772c52686b4846904537d | UnimaidElectrical/PythonForBeginners | /Algorithms/Sorting_Algorithms/Quick_Sort.py | 2,603 | 4.375 | 4 | #Quick Sort Implementation
**************************
def quicksort(arr):
"""
Input: Unsorted list of intergers
Returns sorted list of integers using Quicksort
Note: This is not an in-place implementation. The In-place implementation with follow shortly after.
"""
if len(arr) < 2:
ret... | true |
1ab91009e990c5f8858a019968d8a1616a9e4c09 | UnimaidElectrical/PythonForBeginners | /Algorithms/Sorting_Algorithms/selection_sort.py | 2,740 | 4.46875 | 4 | # Selection Sort
# Selection sort is also quite simple but frequently outperforms bubble sort.
# With Selection sort, we divide our input list / array into two parts: the sublist
# of items already sorted and the sublist of items remaining to be sorted that make up
# the rest of the list.
# We first find the smalles... | true |
38baa3eb890530cac3a056140908e23015070428 | UnimaidElectrical/PythonForBeginners | /Random_code_store/If_Else_Statement/If_Else_statement.py | 2,375 | 4.375 | 4 | """This mimicks the children games where we are asked to choose our own adventure
"""
print("""You enter a dark room with two doors.
Do you go through door #1 or door #2?""")
door = input ("> ")
if door == "1":
print("There's a giant bear here eating a cheese cake.")
print("What do you want to do?")
prin... | true |
0f509b10fd23df81cd306ea05a6ae07e6b9c13b3 | UnimaidElectrical/PythonForBeginners | /Random_code_store/Lists/In_Operators.py | 453 | 4.34375 | 4 | #The In operator in python can be used to determine weather or not a string is a substring of another string.
#what is the optcome of these code:
nums=[10,9,8,7,6,5]
nums[0]=nums[1]-5
if 4 in nums:
print(nums[3])
else:
print(nums[4])
#To check if an item is not in the list you can use the NOT operator
#In th... | true |
ff97e60837bf32c1dc1f65ef8afda4f658a7116b | lchristopher99/CSE-Python | /CSElab6/turtle lab.py | 2,207 | 4.5625 | 5 | #Name: Jason Hwang, Travis Taliancich, Logan Christopher, Rees Hogue Date Assigned: 10/19/2018
#
#Course: CSE 1284 Section 14 Date Due: 10/20/2018
#
#File name: Geometry
#
#Program Description: Make a geometric shape
#This is the function for making the circle us... | true |
5e447702f51cd3318fd5595a131da34c2bc498d5 | endreujhelyi/endreujhelyi | /week-04/day-3/04.py | 528 | 4.3125 | 4 | # create a 300x300 canvas.
# create a line drawing function that takes 2 parameters:
# the x and y coordinates of the line's starting point
# and draws a line from that point to the center of the canvas.
# draw 3 lines with that function.
from tkinter import *
top = Tk()
size = 300
canvas = Canvas(top, bg="#222", he... | true |
0c2563d42a29e81071c4a2667ace0495477ac241 | endreujhelyi/endreujhelyi | /week-04/day-3/08.py | 534 | 4.1875 | 4 | # create a 300x300 canvas.
# create a square drawing function that takes 2 parameters:
# the x and y coordinates of the square's top left corner
# and draws a 50x50 square from that point.
# draw 3 squares with that function.
from tkinter import *
top = Tk()
size = 300
lines = 3
canvas = Canvas(top, bg="#222", heigh... | true |
dc27b4d07c81d4faed52867851a4b623ac3a7ca3 | jonathan-potter/MathStuff | /primes/SieveOfAtkin.py | 1,824 | 4.21875 | 4 | ##########################################################################
#
# Programmer: Jonathan Potter
#
##########################################################################
import numpy as np
##########################################################################
# Determine the sum of all prime numbers l... | true |
6733b7b848e1e271f7f3d313284348f9e9fab0a8 | gyhou/DS-Unit-3-Sprint-2-SQL-and-Databases | /SC/northwind.py | 2,546 | 4.5625 | 5 | import sqlite3
# Connect to sqlite3 file
conn = sqlite3.connect('northwind_small.sqlite3')
curs = conn.cursor()
# Get names of table in database
print(curs.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;").fetchall())
# What are the ten most expensive items (per unit price) in the database... | true |
c653a1e85345ac2bd9dabf58da510c86a43afdac | jrabin/GenCyber-2016 | /Base_Day.py | 309 | 4.21875 | 4 | # -*- coding: utf-8 -*
"""
Created on Wed Jul 6 10:24:01 2016
@author: student
"""
#Create your own command for binary conversion
#// gives quotient and % gives remainder
'''
hex_digit=input("Hex input:")
print(chr(int("0x"+hex_digit,16)))
'''
letter=input("Enter letter:")
print(hex(int(ord(letter)))) | true |
f7c954329701b44dd381aa844cf6f7a11ba1461e | KritiBhardwaj/PythonExercises | /loops.py | 1,940 | 4.28125 | 4 | # # Q1) Continuously ask the user to enter a number until they provide a blank input. Output the sum of all the
# # numbers
# # number = 0
# # sum = 0
# # while number != '':
# # number = input("Enter a number: ")
# # if number:
# # sum = sum + int(number)
# # print(sum)
# # sum = 0
# # number... | true |
dbe0e4b02b87fc67dd2e4de9cbaa7c0226f9e58e | geekidharsh/elements-of-programming | /primitive-types/bits.py | 1,870 | 4.5 | 4 | # The Operators:
# x << y
# Returns x with the bits shifted to the left by y places (and new bits on the right-hand-side are zeros).
# This is the same as multiplying x by 2**y.
# ex: 2 or 0010, so 2<<2 = 8 or 1000.
# x >> y
# Returns x with the bits shifted to the right by y places. This is the same as //'ing x by ... | true |
3a60bae93f01f1e9205430277f924390825c598f | geekidharsh/elements-of-programming | /binary-trees/binary-search-tree.py | 1,229 | 4.15625 | 4 | """a binary search tree, in which for every node x
and it's left and right nodes y and z, respectively.
y <= x >= z"""
class BinaryTreeNode:
"""docstring for BT Node"""
def __init__(self, data=None, left=None, right=None):
self.data = data
self.left = left
self.right = right
# TRAVERSING OPERATION
def preor... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.