blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
7092a12e3c6a798e8819718e135686d1863c55bf | jessicakimbril/Intro-Python-I | /src/03_modules.py | 1,229 | 4.21875 | 4 | """
In this exercise, you'll be playing around with the sys module,
which allows you to access many system specific variables and
methods, and the os module, which gives you access to lower-
level operating system functionality.
"""
import sys
# See docs for the sys module: https://docs.python.org/3.7/library/sys.html... | true |
cac29dbe57414e796c71817c442459be46ead4b7 | erjan/coding_exercises | /watering_plants.py | 1,664 | 4.1875 | 4 | '''
You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.
Each plant needs a specific amount of water. You will wate... | true |
d2310b4e5dee42d19eb7f30338dd4a9f16c74220 | erjan/coding_exercises | /palindrome_number.py | 860 | 4.125 | 4 | '''
Given an integer x, return true if x is palindrome integer.
An integer is a palindrome when it reads the same backward as forward.
For example, 121 is a palindrome while 123 is not.
'''
class Solution:
def isPalindrome(self, x: int) -> bool:
s = str(x)
k = len(s)
if len(s) % ... | true |
451d9d63ee5672d9d4098995987b6ee4b8459df1 | erjan/coding_exercises | /Smallest Missing Non-negative Integer After Operations.py | 805 | 4.125 | 4 | '''
You are given a 0-indexed integer array nums and an integer value.
In one operation, you can add or subtract value from any element of nums.
For example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].
The MEX (minimum excluded) of an array is the smallest m... | true |
6435c456c95b8094817d8f7757e86b7c49e87e8d | erjan/coding_exercises | /number_of_valid_words_in_sentence.py | 2,128 | 4.25 | 4 | '''
A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separated by one or more spaces ' '.
A token is a valid word if all three of the following are true:
It ... | true |
844fb50e96147f9a3427c1c8b54845a09cf506a2 | erjan/coding_exercises | /reformat_date.py | 1,731 | 4.1875 | 4 | '''
Given a date string in the form Day Month Year, where:
Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}.
Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
Year is in the range [1900, 2100].
Convert the date string to the format YYYY-MM-DD, ... | true |
7ae388edc8ff6878b165a7abbd25f0c182a9fde8 | erjan/coding_exercises | /merge_triplets_to_form_target_triplet.py | 2,149 | 4.25 | 4 | '''
A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.
To obtain target, you may apply the following operation on triplets a... | true |
96da01c2afae044cddf85659ca804df4743c441a | erjan/coding_exercises | /find_anagram_mappings.py | 705 | 4.125 | 4 | '''
You are given two integer arrays nums1 and nums2 where nums2 is an anagram of nums1. Both arrays may contain duplicates.
Return an index mapping array mapping from nums1 to nums2 where mapping[i] = j means the ith element in nums1 appears in nums2 at index j. If there are multiple answers, return any of them.
An ... | true |
3b4ef2b8d56f461b00a0ba28ec2838f6b2947257 | erjan/coding_exercises | /implement_magic_dictionary.py | 1,220 | 4.125 | 4 | '''
Design a data structure that is initialized with a list of different words. Provided a string, you should determine if you can change exactly one character in this string to match any word in the data structure.
Implement the MagicDictionary class:
MagicDictionary() Initializes the object.
void buildDict(String[]... | true |
72f41b726a1c97492422d69d47ba4cb86b1d999f | erjan/coding_exercises | /design_atm_machine.py | 2,595 | 4.125 | 4 | '''
There is an ATM machine that stores banknotes of 5 denominations: 20, 50, 100, 200, and 500 dollars. Initially the ATM is empty. The user can use the machine to deposit or withdraw any amount of money.
When withdrawing, the machine prioritizes using banknotes of larger values.
For example, if you want to withdraw... | true |
5cc5d2095bc77a2a6eff79cbcae519e06afe2a83 | erjan/coding_exercises | /check_if_a_number_is_majority_element_in_array.py | 1,871 | 4.15625 | 4 | '''
Given an integer array nums sorted in non-decreasing order and an integer target, return true if target is a majority element, or false otherwise.
A majority element in an array nums is an element that appears more than nums.length / 2 times in the array.
'''
class Solution:
def isMajorityElement(self, nums: ... | true |
c0a9628f2b0ad49c53a0a563cd9205d9b1ccc0c1 | erjan/coding_exercises | /flatten_binary_tree_to_linked_list.py | 2,539 | 4.28125 | 4 | '''
Given the root of a binary tree, flatten the tree into a "linked list":
The "linked list" should use the same TreeNode class where the right child pointer points
to the next node in the list and the left child pointer is always null.
The "linked list" should be in the same order as a pre-order traversal of the bin... | true |
7855304e35b2731467989c9b9db478d3afa2d8e4 | erjan/coding_exercises | /decode_the_slanted_ciphertext.py | 1,127 | 4.1875 | 4 | '''
A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows.
originalText is placed first in a top-left to bottom-right manner.
The blue cells are filled first, followed by the red cells, then the yellow cells, and so ... | true |
2cd5d950cf5afefd5e51606ecd6cc371b382e8a7 | erjan/coding_exercises | /find_duplicate_file_in_system.py | 2,609 | 4.15625 | 4 | '''
Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.
A group of duplicate files consists of at least two files that have the same cont... | true |
84f67d4e99e7f0634f4f8053fe7048914915b78c | erjan/coding_exercises | /unique_length_3_palindromic_subsequences.py | 2,068 | 4.1875 | 4 | '''
Given a string s, return the number of unique palindromes of length three that are a subsequence of s.
Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once.
A palindrome is a string that reads the same forwards and backwards.
A subsequence of a string is a new s... | true |
389ed5aafe065149af013158ca76915c38064266 | erjan/coding_exercises | /integer_replacement.py | 1,287 | 4.375 | 4 | '''
Given a positive integer n, you can apply one of the following operations:
If n is even, replace n with n / 2.
If n is odd, replace n with either n + 1 or n - 1.
Return the minimum number of operations needed for n to become 1.
'''
def integerReplacement(self, n):
# Basically, There are four cases in the trai... | true |
2ba335098ca1665f0e4a712b82a3bbee0796c3db | erjan/coding_exercises | /minimum_number_of_frogs_croaking.py | 1,222 | 4.3125 | 4 | '''
You are given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple "croak" are mixed.
Return the minimum number of different frogs to finish all the croaks in the given string.
A valid "croak" means a fr... | true |
446c83d92aa9635523efa8ba0ea6cb2316583fd7 | erjan/coding_exercises | /maximum_total_importance_of_roads.py | 1,872 | 4.46875 | 4 | '''
You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.
You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.
You need to assign each city with an integer value from ... | true |
72d635f5eb13b9644ff68a48a5a74f7ca971d7f4 | erjan/coding_exercises | /path_in_zigzag_labelled_binary_tree.py | 730 | 4.125 | 4 | '''
In an infinite binary tree where every node has two children, the nodes are labelled in row order.
In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even
numbered rows (second, fourth, sixth,...), the labelling is right to left.
Given the label of a node in... | true |
ab5766d47c449d9b4922018966e5bb3c6c417734 | erjan/coding_exercises | /exam_room.py | 1,451 | 4.15625 | 4 | '''
There is an exam room with n seats in a single row labeled from 0 to n - 1.
When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits at ... | true |
86923d2a6533022a6fb11cd521d66ccdd3ddbc25 | erjan/coding_exercises | /delete_characters_to_make_fancy_string.py | 652 | 4.21875 | 4 | '''
A fancy string is a string where no three consecutive characters are equal.
Given a string s, delete the minimum possible number of characters from s to make it fancy.
Return the final string after the deletion. It can be shown that the answer will always be unique.
'''
class Solution:
def makeFancyString(sel... | true |
b2bfb5699c483a83a876447638c51af24ad05660 | erjan/coding_exercises | /minimum_cost_to_set_cooking_time.py | 2,987 | 4.125 | 4 | '''
A generic microwave supports cooking times for:
at least 1 second.
at most 99 minutes and 99 seconds.
To set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the s... | true |
2cc8dfc639f49b8b153963ee3a08cf9d056cf244 | notmycall/algorithms | /Sort Algorithms/quick_sort.py | 1,496 | 4.46875 | 4 | import verify # Used for verifying that the algorithm is working as intended
'''
Quick Sort:
Quick sort accepts a sequence. If the sequence has the length of 1 or 0, then it is returned.
if it doesn't, then a pivot is taken from the very end, and the remaining values are split into left and right sequences.
The seq... | true |
8919afe0aed3aa3fb22d69f2d0ff68dc48f5e74a | armennmuradyan/python_classes | /repeat1.py | 1,573 | 4.40625 | 4 | ##5. Write a python script to find the highest of given three numbers
# a = [15, 56, 1, -3, 465, 77, 29]
# a.sort()
# print(a[-1])
##write a python program to check leap year without using datetime library (google for conditions)
# year = int(input('Enter the year: '))
# if year % 400 == 0:
# print("leap year... | true |
95892f531f63eba6852b27dab7544494c37a623b | erickim713/DataStructure-Algorithm-Python | /dataStructure_python/LinkedList.py | 2,272 | 4.125 | 4 |
class LinkedList:
def __init__(self):
self.head = None
self.tail = None
def add(self, element):
elementToBeAdded = Node(element)
if(self.isEmpty()):
self.head = elementToBeAdded
self.last = elementToBeAdded
else:
self.last.setNext(el... | true |
dd0a47034879566b0b9c47a71f6605b166dfbdc7 | CrtomirJuren/pygame-projects | /pong-turtle/2_pong.py | 1,055 | 4.15625 | 4 | """
Simple pong in python 3 for begginers
tutorial series: https://www.youtube.com/playlist?list=PLlEgNdBJEO-kXk2PyBxhSmo84hsO3HAz2
"""
import turtle
wn = turtle.Screen()
wn.title("Pong by @TokyoEdTech")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)
# Paddle A
paddle_a = turtle.Turtle()
paddle_a.... | true |
18f15b945c03c6ccc333a72adc037b2c4345bfee | Samrat0009/Python_REPO1 | /#14 OOPS-2/Object_class.py | 768 | 4.34375 | 4 | # 3 types of obj-class methods functions : __new__ : used to create new objects
# : __init__ : used to initialise the object
# : __str__ : below ! basically customises what the function returns ! (useful info)
#this does not usually ... | true |
172569fa2288fadaf00bece146c14a2be475e9ce | klaudis1/curr-convert-tkinter | /curr_convert.py | 1,607 | 4.21875 | 4 | # A currency convert python program, using tkinter
#
# Currencies used in program:
# USD (Dollar of The United States), EUR (Euro), CZK (Czech koruna),
# PLN (Polish Zloty), GBP (British pound sterling)
#
# Values provided in roubles (Actual on 16.10.2021):
# https://www.cbr.ru/currency_base/daily/
from tkinter imp... | true |
79c5889ac738f33a1a2db58b377cf693712fb283 | prachi1807/Data-Structures-and-Algorithms | /Linked List/dll_insertions.py | 2,931 | 4.1875 | 4 | # Implementation of a Doubly Linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
self.prev = None
class DoublyLinkedList:
def __init__(self):
self.head = None
def printdll(self):
if self.head == None:
return
... | true |
fddd63cfcfed754d8015de3e860212e37032677c | ojudz08/Statistics-and-Machine-Learning-in-Python | /statmlpython/3.5.1_func.py | 1,768 | 4.46875 | 4 | # define a function with no arguments and no return values
def print_text():
print('this is text')
print_text() # call the function
# define a function with one argument and no return values
def print_this(x):
print(x)
print_this(3) # call the function, prints 3
n = print_th... | true |
40b84f67ebb54b6bd27f6adbaf149df1d44f79f7 | ojudz08/Statistics-and-Machine-Learning-in-Python | /statmlpython/3.3.2_loops.py | 804 | 4.28125 | 4 | # create a tuple
digits = (0, 1, 'two') # create a tuple directly
digits = tuple([0, 1, 'two']) # create a tuple from a list
zero = (0,) # trailing comma is required to indicate it's a tuple
# examine a tuple
digits[2] # returns 'two'
len(digits) # returns 3
digits.count(0) ... | true |
6c0088d8172f43b6e14dd9496553c1dab6ffff12 | WeijieH/ProjectEuler | /PythonScripts/XOR decryption.py | 2,878 | 4.1875 | 4 | '''
Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107.
A modern encryption method is to take a text file, convert the bytes to ASCII, then XOR each byte... | true |
9ab6b5c76e50c03c93d189250cce6b1787f69251 | WeijieH/ProjectEuler | /PythonScripts/Passcode derivation.py | 1,646 | 4.125 | 4 | '''
A common security method used for online banking is to ask the user for three random characters from a passcode. For example, if the passcode was 531278, they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317.
The text file, keylog.txt, contains fifty successful login attempts.
Given ... | true |
3b3486f91923b76dd4089546a2c2498a5713da51 | WeijieH/ProjectEuler | /PythonScripts/Multiples_of_3_and_5.py | 680 | 4.25 | 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 multiples_of_3_and_5(upper_limit):
if (upper_limit < 3):
return 0
result = 0
m3 = 3
m5 = 5
... | true |
c09d1fff0c09d728afbb620a66c55d1b9227b6bd | Diplomarbeit-Datenbank/User_Widget | /lib/basics/encode.py | 2,693 | 4.28125 | 4 | """
This file is to decode umlauts from a file
Exchange:
- 'ß' -> ß
- 'Ä' -> Ä
- 'ä' -> ä
- 'Ü' -> Ü
- 'ü' -> ü
- 'Ö' -> Ö
- 'ö' -> ö
Just put the output from the text file into the class and get the encoded string with the fu... | true |
8c00dd3f48582ebdb8fb6077c704897f4645c6e7 | sunny-/python | /factor_while.py | 284 | 4.15625 | 4 | # For a given number x, this program
# prints factors for that number using while loop
x= 0.1 # input number factor to be found
i= 1 # iteration counter
if x>=1:
while i <= x:
if x%i==0:
print (i)
i=i+1
else:
print('invalid number') # factors can only be of positive number
| true |
490846db3345216aac66c2cddd3799ae4869af3a | sunny-/python | /sqrt.py | 502 | 4.34375 | 4 | #this program gives square root of a given number.
def sqrt(x):
'''The function give square-rrot of given number x'''
ans = 0
if x<=0:
print ('Not a positive number')
return None
else:
while ans*ans < x:
ans = ans+1
... | true |
10b6a20a89c4b72c2b6646f19ca06d68703e2b16 | priyanshugithub/Data-Structures-and-Algorithms-in-Python | /Trees/Tree_Structure_Using_Classes/__init__.py | 1,990 | 4.3125 | 4 | class BinaryTree:
"""
Creates a Binary Tree with a root, left child and
right child.
Attributes:
rootObj(any): The value of the root of the tree
leftChild(BinaryTree): The left child of the tree
rightChild(BinaryTree): The right child of the tree
"""
def __init__(self... | true |
5d4e7c45571f0bef8c3b8e1139dfea63b1a5eccd | Iniyan19/LetsUpgrade-Python-Essentials | /Day-3/Day-3_Assignment-2.py | 444 | 4.1875 | 4 | #find if prime or not
import math
number = int(input("Enter an Integer : \n"))
#number is a prime number only if it has its factors as 1 and the number itself
#10
flag =0
if number == 0:
print("0 is neither prime nor composite number.")
else:
for num in range(1,math.floor((number+1)/2)):
if(... | true |
06078cf9e59ef700a4e688a7900b881d382645e2 | skbhagat40/Coursera-Stanford-Algorithms-Course | /Python Concepts/python-talks/pycon-seattle/yield.py | 1,257 | 4.46875 | 4 | # Example of generator using yield.
# yield preserves the state.
# refer demo implementation.py
def get_ten_nos():
counter = 0
while counter < 10:
yield counter
counter += 1
for i in get_ten_nos():
print("number fetched is {}".format(i))
# we can see yield as a way of interchange of con... | true |
6d5ee635ec903d355d9961d25031d7fa937ec352 | AkshayMukkavilli/Analyzing-the-Significance-of-Structure-in-Amazon-Review-Data-Using-Machine-Learning-Approaches | /src/crawlers/upper_lower_percentages.py | 870 | 4.125 | 4 | """
Method to calculate the percentage of upper case and lower case letters in
a given line.
"""
def percentages_upper_lower(line):
"""
Calculates the percentage of upper case and lower case letters.
:param line:
:return: upper case percentage and lower case percentage
"""
no_upper_case_lette... | true |
11a38a253122c2a06a9a9d1572f902b4b086668d | CamiLG/PythonInterviewExamples | /queue_example.py | 411 | 4.21875 | 4 | """try out the Python queue functions"""
from collections import deque
#TODO: create a new empty deque object that will function as a queue
queue = deque()
#TODO: add some items to the queue
queue.append(1)
queue.append(2)
queue.append(3)
queue.append(4)
queue.append(5)
#TODO: print the queue contents
print(queue)... | true |
831be85eaa627d4322a63b8274b36672a2c04ff3 | vishalsharma14/algo | /string/9.reverse_only_letters.py | 1,119 | 4.125 | 4 | """
LeetCode 917. Reverse Only Letter
Given a string S, return the "reversed" string where all characters that are
not a letter stay in the same place, and all letters reverse their positions.
Example 1:
Input: "ab-cd"
Output: "dc-ba"
Example 2:
Input: "a-bC-dEf-ghIj"
Output: "... | true |
790a6a942796a3eac462e4ae8fcdee8869033a02 | vishalsharma14/algo | /array/1.find_common_characters.py | 1,543 | 4.125 | 4 | """
LeetCode 1002. Find Common Characters
Given an array A of strings made only from lowercase letters, return a list of all
characters that show up in all strings within the list (including duplicates).
For example, if a character occurs 3 times in all strings but not 4 times,
you need to include ... | true |
651616d4e163f45b05de60374e80cc62ecc254ce | vishalsharma14/algo | /array/8.reshape_the_matrix.py | 2,059 | 4.15625 | 4 | """
LeetCode 566. Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into
a new one with different size but keep its original data.
You're given a matrix represented by a two-dimensional array, and two positive integers r and c
representing t... | true |
22911a395050e86e1f820cb3e216f6062fb6828d | jazzathoth/Intro-Python-I | /src/13_file_io.py | 952 | 4.28125 | 4 | """
Python makes performing file I/O simple. Take a look
at how to read and write to files here:
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
"""
# Open up the "foo.txt" file (which already exists) for reading
# Print all the contents of the file, then close the file
f = open('foo.t... | true |
44c222218c5deccacbde4d97e7aca7ee4fbbec3e | DarioCozzuto/list | /change list items.py | 941 | 4.5 | 4 | #Change the second item:
thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
print(thislist)
#Change the values "banana" and "cherry" with the values "blackcurrant" and "watermelon":
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"]
thislist[1:3] = ["blackcurrant", "waterme... | true |
15ca92aabd6bd9742704351f6c24af69055c9364 | yuliakon27/basics | /variables.py | 503 | 4.125 | 4 | # variables naming :
# should not start with numbers
# start with lower cases
vname= "Yulia"
msg = "Hello class, we are learning Python today!"
print("hello again")
print(vname)
print(f"he said: {msg} His name is {vname}")
print("---------------------------------")
vname= "Akmal"
print(vname)
msg = "i like being he... | true |
cf07a6f22f8205b3e9f84cb6501b471c661fd90f | keegaz/Python | /march_24/assignment_8.py | 710 | 4.1875 | 4 | #Increase the speed of the square on the canvas.
#Display a red square moving down the canvas window.
from tkinter import *
window = Tk()
canvas = Canvas (window,width = 1000, height =700)
canvas.pack()
#create polygon - first parameters are the four corners to the make square
#there is also create_oval method
canva... | true |
47f86974cdfaeff087fec0e22b451d13964af534 | Damephena/algo | /movezeros.py | 876 | 4.21875 | 4 | '''
A program that moves all 0s to the end of list.
Maintains the relative order of non-zero elements.
@param arr: a list of integers.
@returns: a list of initial array with 0's at the list's end.
'''
from collections import Counter
def move_zeroes(arr):
'''Returns a new array with all zeros at the list's end.''... | true |
29c282344a7ccbd6afb799059795dfa10a8b8daa | akurbanovv/ds125 | /hw1 : ps 0, ps2/ps1/ps1c.py | 1,802 | 4.25 | 4 | """
@author: Akhmad Kurbanov
The programm is doing opposite of what we did in part
B with predefined values. We have 32 months and we have to get
the right rate with which we will save our money to pay down
payment.
"""
# getting value from the user
annual_salary = float(input("Enter the starting salary: "))
# in... | true |
5d022eec5ee84452c0cd0ce3904005da570d8f48 | Darth-Neo/Examples | /NLTK_Examples/Basic_Op_in_Text.py | 936 | 4.125 | 4 | #!/usr/bin/env python
from __future__ import division
import os
from nltk.book import *
# lexical richness of the text
def lexical_richness(text):
return len(set(text)) / len(text)
# percentage of the text is taken up by a specific word
def percentage(word, text):
return (100 * text.count(word) / len(text))
... | true |
f5c1716da323680d5a746e14acf13fa4e87edc15 | Darth-Neo/Examples | /DriCrawler_Examples/print environ.py | 975 | 4.4375 | 4 | #!/usr/bin/env python
import os, sys
variable = sys.argv
def enVar(variable):
"""
This function returns all the environment variable set on the machine or in active project.
if environment variable name is passed to the enVar function it returns its values.
"""
nVar = len(sys.argv)-1
... | true |
d08df245a4647c09791c03592b2d38d6f699193b | hunterxpatterson/Lab9 | /lab9-70pt.py | 608 | 4.1875 | 4 | ############################################
# #
# 70pt #
# #
############################################
# Create a celcius to fahrenheit calculator.
# Multiply by 9, then divide by 5, then add 32 t... | true |
ca9e617d6e8499a7df1e99755edc8c0b2c1c5934 | Chen-Po-Chen/LeetCode_Python | /Reverse Integer.py | 1,041 | 4.25 | 4 | # Reverse Integer
# Given a 32-bit signed integer, reverse digits of an integer.
# Example 1:
# Input: 123
# Output: 321
# Example 2:
# Input: -123
# Output: -321
# Example 3:
# Input: 120
# Output: 21
# Note:
# Assume we are dealing with an environment which could only store integers within the 3... | true |
679efdfc9534450b718cffb5be8d4fdbb1a1bbfe | Youngjun-Kim-02/ICS3U-Assignment4-python | /weekdays.py | 965 | 4.21875 | 4 | #!/usr/bin/env python3
# created by: Youngjun Kim
# created on: May 2021
# This program checks the number's weekday
def main():
# this function checks the number's weekday
# input
integer_as_string = input("Enter the number of a weekday: ")
print("")
# process & output
try:
integer_... | true |
26890364c78da43d46f1d0055732cbaa0cba8b54 | PierceLovesee/Data_Structures_and_Algorithms | /2 - Data Structures/week2_priority_queues_and_disjoint_sets/1_make_heap/build_heap.py | 1,921 | 4.1875 | 4 | # python3
# Pierce Lovesee
# January 5th, 2021
# Grader Output: (Max time used: 0.21/3.0, max memory used: 26038272/536870912.)
def swap(data, swaps, x, y):
""" Two indicies in the data array
Swaps the two values at the given idexes in inplace
Record the indicies swapped in the swaps list
"""
data... | true |
45327fc2689333358533a82c68c4f70f3fc2f8bc | PierceLovesee/Data_Structures_and_Algorithms | /2 - Data Structures/week1_basic_data_structures/1_brackets_in_code/check_brackets.py | 2,071 | 4.21875 | 4 | # python3
# Pierce Lovesee
# December 26th, 2020
from collections import namedtuple
# defining bracket data structure named tuple
Bracket = namedtuple("Bracket", ["char", "position"])
# helper function to determine if two sets of parens are matching
def are_matching(left, right):
return (left + right) in ["()", ... | true |
5b1ea7e5bc12fc6b17064fe801a1aee4e3cd582d | kimbrow-slice/LinkedIn_Learning_Python | /if.py | 484 | 4.21875 | 4 | # if statements concepts same as JS but syntac is differnet
if 5 < 6: # notice the : at the end of IF not the ; at the end of statement like JS
print("Yes, 5 is less than 6.")
print("Everyone should know that!")
print("This IS NOT PART OF OUR BLOCK THOUGH")
# if statements are held together by print until it ... | true |
c05ce65d5f8746d68f90d423e8bb50a7caba2a4b | Okikijoshua/PythonProjects | /simple_menu.py | 205 | 4.125 | 4 | menu = int(input("Pleasw select options of your choice \n Option(1) \n Option(2)\n"))
if menu ==1:
print("sea food")
elif menu ==2:
print("Swallow with vegetable")
else:
print("invalid input")
| true |
6b655abbcef6120d6f453f523df43c44a5b061ef | GitGudCoder/CP1404 | /cp1404practicals/prac_4/list_excercises.py | 1,269 | 4.21875 | 4 | # INTERMEDIATE EXCERCISES
def main():
perform_basic_list_operations()
access = woefully_inadequate_security_checker()
if access:
print("Access granted")
else:
print("Access denied")
# 1. BASIC LIST OPERATIONS
def perform_basic_list_operations():
user_inputs = int(input("Please ente... | true |
f4e34d144a4b6811fbb3cff48a374ea22c6782a1 | rahulmohang/Learning | /Myfirst.py | 1,169 | 4.5625 | 5 | # print ("My first python program in github")
# Python program to illustrate the use of
# @property decorator
# Creating class
class Celsius:
# Defining init method with its parameter
def __init__(self, temp = 0):
self._temperature = temp
# @property decorator
@property
... | true |
52c75d17207376f01a4a4fae7d6b3b7b44ae0001 | bidahor13/Python_projects | /P7_wk2/Q1.py | 2,091 | 4.28125 | 4 | #BABATUNDE IDAHOR
#PROJECT_4
#COURSE : CS133
#TERM: FALL 2015
##This program translates an English word or phrase and translate it into Pig Latin using a Pig Latin translator.
print ('Welcome to the Pig Latin Converter')
playAgain = 'yes'
while playAgain.lower() == 'yes':
try: #Exception handler
phras... | true |
856df9d01ca2ea04ac71b5de5b3d73b2828c18ca | bidahor13/Python_projects | /P1/Project_1.py | 1,537 | 4.4375 | 4 | #AUTHOR: BABATUNDE IDAHOR
#COURSE: CS133
#TERM : FALL 2015
#DATE : 10/8/2015
#This program shows the comparison of the balance of a bank account
#over time between simple, monthly and daily methods of compounding interest.
print('Project_1: Question_1')
print(' Calculate the simple, monthly and daily methods of com... | true |
11c64eaab9075ba5c8ddfab78a791c67c0ba25f8 | macarro/imputena | /imputena/deletion/delete_listwise.py | 1,742 | 4.15625 | 4 | import pandas as pd
def delete_listwise(data=None, threshold=None, inplace=False):
"""Performs listwise deletion on the data: Drops any rows that contain
missing values. If a threshold is given, the function drops those rows
which have less non-NA values. If the operation should only affect certain
co... | true |
7dc3bea38c8b63d53c29625d1add0120e0eef274 | Saevon/Recipes | /interview/interview_reverse.py | 872 | 4.28125 | 4 | '''
Reversing a string
'''
import math
def reverse(string):
'''
A Fun reverse "optimization" using a half-loop and letter swapping
'''
letters = list(string)
# Do a half loop
for i in range(math.floor(len(letters) / 2)):
high = (len(letters) - 1) - i
# Swap letters
l... | true |
573cdc9fb46120ffb9f038cfcf85443e2dc64b96 | kelvincaoyx/UTEA-PYTHON | /Week 2/PythonUnitTwoPractice/linear.py | 836 | 4.15625 | 4 | '''
A calculator for a linear equation
'''
#Checks if the equation can be solved/ returns the answer
def linearEquationSolver(a,b,c):
if a == "" or b == "" or c == "" or a == "0":
return None
x = (float(c) - float(b))/float(a)
return x
#Header of the calculator
print("This calculator sol... | true |
32e7f3e2d3077fbc97b66741f58af6be55256346 | kelvincaoyx/UTEA-PYTHON | /Week 6/pythonUnitSixPractice/testAlgebra.py | 484 | 4.28125 | 4 | '''this program is designed to create pascal's triangle and print it out'''
#importing necessary functions
from algebra import createEmptyTriangle
from algebra import printTriangle
from algebra import generateTriangle
#creating the triangles
triangleSize = 10
print("creating empty triangle")
printTriangle(createEmptyT... | true |
40f7cb6273e8f435b61a99956425803775bd8327 | kelvincaoyx/UTEA-PYTHON | /Week 3/pythonUnitThreePractice/multipleDataSets.py | 1,804 | 4.125 | 4 | '''A program that reads data from two different files. One file corresponds to the word while the
other one corresponds to the word's frequency. This program will accept a cutoff frequency and
print all the words that make the cutoff
'''
#funtion that accepts two text files and a cutoff and uses these variables to ou... | true |
21589f2d1899b217261b6d30d9f694e31d58f13d | shreyashpatil26/banking-system | /try.py | 2,494 | 4.1875 | 4 | acholder={"ab":"10","bc":"20","cd":"30","de":"40"}
balance={"10":"100", "20":"200", "30":"300","40":"400"}
def print_menu():
print ("1. List Account holders and Account no")
print ("2. Open an Account")
print ("3. Close an Account")
print ("4. Withdraw money")
print ("5. Deposit Money")
... | true |
86196a795ad855b76c65ebaabd98ab088c1373f1 | exercism/python | /exercises/concept/guidos-gorgeous-lasagna/.meta/exemplar.py | 1,834 | 4.34375 | 4 | """Functions used in preparing Guido's gorgeous lasagna.
Learn about Guido, the creator of the Python language: https://en.wikipedia.org/wiki/Guido_van_Rossum
"""
# time the lasagna should be in the oven according to the cookbook.
EXPECTED_BAKE_TIME = 40
PREPARATION_TIME = 2
def bake_time_remaining(elapsed_bake_tim... | true |
18c0947716f1e13578627d5144b13775193e16ad | exercism/python | /exercises/concept/little-sisters-essay/string_methods.py | 1,287 | 4.53125 | 5 | """Functions to help edit essay homework using string manipulation."""
def capitalize_title(title):
"""Convert the first letter of each word in the title to uppercase if needed.
:param title: str - title string that needs title casing.
:return: str - title string in title case (first letters capitalized)... | true |
41e248fd3e72613e9a469aef968917ab5457bf02 | lorcosta/Lab1_IS | /ex2.py | 533 | 4.15625 | 4 | def count_occurrences(word, character):
i = 0
for _ in word:
if _ == character:
i += 1
return i
if __name__ == '__main__':
word = raw_input('Write a word: ')
character = raw_input('Type a character to look for: ')
number = count_occurrences(word, character)
if number ==... | true |
aeb57ea30b2582bda2a2cd809280386cae9fe879 | ericpongpugdee/mycode | /custif/myscript02.py | 578 | 4.15625 | 4 | #!/usr/bin/env python3
import sys
print("what should I have for lunch today?")
try:
wallet = input("what is in my wallet? ")
except ValueError:
wallet = float(wallet)
print('that does not belong in a wallet')
sys.exit(0)
def main():
if wallet == 'cc':
print("Anything I want")
elif ... | true |
45daa29dceb7879d02963ea61a1ca2489c65ffbf | rrebase/algorithms | /d01_breadth-first_search.py | 915 | 4.125 | 4 | # Breadth-first search algorithm
# dictionary representations of graph
graph = {
'A': ['Z'],
'Z': ['C', 'Y'],
'C': ['D', 'F'],
'D': ['B'],
'F': ['G'],
}
# visits all the nodes of a graph (connected component) using BFS
def bfs(start): # start node
visited = [] # keep track of all visited no... | true |
e0ae814486c53a076ac644192918128b9076438b | kuljotbiring/Automate-the-Boring-Stuff | /regexcharacterclass.py | 1,776 | 4.25 | 4 | # import the regex module
import re
# \d does any digit 0 to 9
# \D any character that is NOT a numeric digit 0 to 9
# \w any letter, numeric digit, or underscore char
# \W any character that is not a letter, digit, or underscore
# \s any space, tab, or newline char
# \S any character that is NOT space, tab, or newlin... | true |
31a73d9f55e16c0813024a2b6fe5ecc9e4089658 | HarpreetS27/PythonProjects | /GuessGame.py | 691 | 4.15625 | 4 | print("Guess Game\n")
NumtoGuess=20
Guessleft=5
Guesstook=0
while (Guessleft!=0):
print("Enter your Guess")
guessed=int(input())
if(guessed>NumtoGuess):
print("Guess a smaller number \n")
Guessleft-=1
Guesstook+=1
print("Guesstook : ",Guesstook," ","Guessleft... | true |
f82da5337f1e9bdc8523e43c1e79f3433e1939b3 | Kavri/CODEME-PYTHON | /Control instructions/4 - abracadabra.py | 745 | 4.15625 | 4 | #Create a variable that has a string.
#Check if the string: is longer than 5 characters | has the letter a.
#If the string has a - wreplace all letters a with z | display string.
magic = 'Abracadabra'
print('Check if the string: is longer than 5 characters | has the letter a.')
magicNumb = len(magic)
if magic... | true |
63a58e5ac36b7d97fd2337c8c293e9fce3c3608c | Kavri/CODEME-PYTHON | /Control instructions/5 - password.py | 824 | 4.34375 | 4 | #Create variable "password".
#The password has letters and numbers, at least 1 capital letter and minimum length of 8 characters.
#If the password is incorrect - display the message.
#Display message depending on the error.
password = input('Enter your password:')
passwordUser = password.isalnum()
if password... | true |
45bd62b096d60e26da6ecaa3e459339e7288b8ca | Kavri/CODEME-PYTHON | /Control instructions/10 - guess the number.py | 349 | 4.15625 | 4 | # Create a simple game
# The user guesses a number from 0 to 20.
# The number is hidden in the program (np. secret_num = 5).
secretNum = 5
while True:
num = int(input('Enter the number: 0 - 20: '))
if num == secretNum:
print('Guess the number. Congratulations! ! :)')
break
else:
... | true |
9bbc3c4e3ee81e3ffde7509f812f243d0ee6304b | Visheshjha09/project_sorting_visualization_using_python_gui | /selectionsort.py | 1,409 | 4.28125 | 4 | #////////////////////////////#
#The selection sort algorithm sorts an array by repeatedly finding the minimum element
#(considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
#1) The subarray which is already sorted.
#2) Remaining subarr... | true |
e76dbfd843c07bee810406cf68a595be4511be68 | erockx1n/python_speed_test | /timer.py | 709 | 4.21875 | 4 | #!/usr/bin/env python
import time
class Timer:
"""Simple timer to be used to output the time needed for execution"""
def __init__(self):
self.start_time = 0
self.end_time = 0
def start(self):
"""Sets and returns the start time"""
self.start_time = time.time()
retur... | true |
d21c0414b1602dcd13de877e0e54a01ac07d9a2e | mecampen/computational_physics | /collatz_sequence.py | 2,560 | 4.4375 | 4 | import matplotlib
import matplotlib.pyplot as plt
import numpy as np
def collatz_sequence(an):
"""
the function computes the next term of the collatz sequence given a
last term as arguement.
an: start value or last value of the sequence
"""
if an % 2 == 0:
next = an/2
elif an % 2 == 1:
next = 3*an+1
#pri... | true |
112378e5fa00dbac2e41f3a106420b031159519c | DanielCT20/PythonMadeEasy | /17- Python Functions Class 2- Scope/functions_scopes.py | 1,251 | 4.3125 | 4 | #EXAMPLE #1
##x = 50 # defined in the global scope
##def func(y): # func defined in the global scope
## z = x + y # y,z local, x is defined in the global scope
##
## return z
##
##print("Example #1", func(25))
##
##
###EXAMPLE #2
##x = 50 # defined in the global scope
##def func(y): # func defined in the global... | true |
562967a254c93e3d81e10b04f4981f248c74f98a | mjpawesome/cs-module-project-algorithms | /moving_zeroes/moving_zeroes.py | 1,287 | 4.25 | 4 | '''
Input: a List of integers
Returns: a List of integers
'''
# def moving_zeroes(arr):
# new_arr = []
# for i in arr:
# if i != 0:
# new_arr.append(i)
# for i in arr:
# if i == 0:
# new_arr.append(i)
# return new_arr
# complexity O(n
# space O(1)
def moving... | true |
238ba478d834793232670b9886b2988254180027 | AlecLankford/PythonPractice | /UdemyCourse/GUIPractice/KmToMiles.py | 804 | 4.25 | 4 | from tkinter import *
#Creates the window
window = Tk()
#Converts kilometers put in by
def kmToMiles():
#Equation to convert km to miles
miles = float(entry1Value.get())*1.6
#Puts the value entered at the end of the text1 variable
text1.insert(END, miles)
#Creates a button within the window, assign... | true |
622c990031c22ffad1426652b753c5981099c84b | sczapuchlak/Dog_Database | /AddRowOfDataToTable.py | 1,507 | 4.3125 | 4 |
# this file adds a row of data to the table
import sqlite3
def main():
addRow()
def addRow():
# Call the UserInformationFunction
askUser = userInformation()
# this names the database
file = "Dog_Database.sqlite"
# this names the table
dog_table = 'Dog_Table'
# Connecting to the dat... | true |
905dc56d3587a9ed4a7b7141813c1e8c6cd9c060 | pbyriel/classes_excercise_band | /band.py | 2,855 | 4.125 | 4 | #python3
#thinkful python track 1.3 "Modeling things using Python classes"
class Musician(object):
def __init__(self, sounds):
self.sounds = sounds
def solo(self, length):
for i in range(length):
#modulus on length gets position of sound to be played
print(self.sou... | true |
be809a616081f2e8bb031d408bd20662014ccb82 | cnbala/Python_Practice | /Factorial.py | 390 | 4.1875 | 4 | # loop
def factorial(n):
fact=1
for i in range(n,1,-1):
fact=fact*(i)
return fact
n=int(input("Enter number:"))
print(factorial(n))
#Recursion
def factorial(n):
fact=1
if (n ==0 or n==1):
print("loop")
return fact
else:
fact=n*factorial(n-1)
... | true |
f0ffdbd5467574fe76fec8a37e50fca99abe85a4 | jwatson-CO-edu/py_info | /Learning/list-list-comprehension.py | 1,051 | 4.21875 | 4 | # -*- coding: utf-8 -*-
""" Multiple variables can be populated in a list comprehension """
for a, b, c, d in [[1,2,3,4],
['A','B','C','D'],
[[1,2,3,4],[4,3,2,1],[5,6,7,8],[8,7,6,5]]]:
print "a:",a,"\tb:",b,"\tc:",c,"\td:",d
foo = [[x[0],x[1... | true |
825e768a581293ae7a47444bbda30ec3ac2e0e62 | jwatson-CO-edu/py_info | /Snippets/average_nested.py | 716 | 4.3125 | 4 | # -*- coding: utf-8 -*-
def avg(*args):
""" Average of args, where args can be a list or nested lists """
total, N = accumulate(args)
return float(total) / N
def accumulate(pLst):
""" Return the sum of all items in 'pLst'. Return the total number of non-list/tuple items in 'pLst'. Recursiv... | true |
57d7dff5a81fbd4cb2a7843fe676122b56448d23 | jwatson-CO-edu/py_info | /Snippets/enumerate-reversed_with-generator.py | 646 | 4.34375 | 4 | # Non-generator option
for i, e in reversed(list(enumerate(['a','b','c']))):
print i, e
"""
2 c
1 b
0 a
"""
print '\n',list(enumerate(['a','b','c'])),'\n' # [(0, 'a'), (1, 'b'), (2, 'c')]
# Calling 'list' on 'enumerate' creates a list of index-value tuples!
# Generator option
def enumerate_reverse(L):
"""... | true |
73dbdb45facf632d5ae9a8741a6cd9d72d2185a2 | mkds/MSDA | /Python/Prog1.py | 1,962 | 4.25 | 4 | __author__ = 'Mohan Kandaraj'
# 1. fill in this function
# it takes a list for input and return a sorted version
# do this with a loop, don't use the built in list functions
def sortwithloops(input):
"""Implements Quick Sort"""
if len(input) > 1:
pivot = input[-1]
swapPos = 0
for i ... | true |
78ec2cbdf563b03429325e292186956fa1fbb4de | SaurabhKolhe/Python | /05_operator.py | 2,041 | 4.1875 | 4 | '''
Arithmetic Operator:
1.Addition +
2.Substraction -
3.Multiplication *
4.Division / (gives answer in float eg. 2/2=1.0)
// (gives answer in integer eg.2//2=1)
5.mod %
6.power to ** (gives power of number eg.2*3=8)
Cond... | true |
77f344c5159c35bb4402ff763fbff7e19006baae | SaurabhKolhe/Python | /01hello.py | 876 | 4.3125 | 4 | '''
Flow/Syntax: 1.Semicolon(;) is not use in python.
2.Indentation: We give some spaces or tab new line after for(),while(),if(),etc.
3.declaration is not available in python.We cannot do like a instead we do like a=0 or a=None or a=" "
Comments in Python: 1.Single line comment... | true |
da871b055f47a2742802f9d4e5efafcc0d110fb4 | SaurabhKolhe/Python | /13_dictionary.py | 852 | 4.40625 | 4 | '''
Dictionary:
1.class of dictionary : dict
2.Indexing is not supported in Dictionary.
3. Dictionary is mutable i.e. we can add,delete,modify in dictionary using key.
Syntax:
a={key:value,key:value}
eg. student={"Name":"Shrikan... | true |
a0f5bf65784375bdbdd63850e4509319031bad11 | SaurabhKolhe/Python | /19_for.py | 1,573 | 4.375 | 4 | '''
For Loop:
1.Syntax:
.........code.........
for i in range(number): #i start with 0 and number-1 is end
....code....
....code....
...........code........
In range one parameter is mandatory.
Ther is no decrement in for l... | true |
3c2bf64ede7e4a1621b20ba47e98fd76c7f68a66 | SaurabhKolhe/Python | /26_formatstring.py | 776 | 4.75 | 5 | '''
Formatting of string:
1.format
2.f
'''
a=10
b=20
#When we want to print 1 variable
print("Value of A: ",a)
#When we want to print 2 value a and b then we can write:
print("Value of A: and B: ",a,b)
#But it is not giving in proper way
#So We can use 'format... | true |
8a8540aee24482651d83714271ea484af9788898 | MuddSub/CVImageHandling | /count.py | 1,297 | 4.21875 | 4 | '''
count counts the number of files of a given type inside of a directory and all of its subdirectory
'''
import os
def count(directory, file_type):
all_files = os.listdir(directory)
if all_files == []:
return 0
else:
return sum(list(map(lambda x: diverse_counting(directory, x, file_ty... | true |
0815c753c2bc965d8837273ed22ae339755e1af1 | Aenimus/Project-Euler | /4 Largest palindrome product.py | 709 | 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.
"""
def reverse_string(input):
return input[::-1]
def find_palindrome():
a = 999
b = 500
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.