blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
80906ba30bc751f48e177907ab2967803c269022
Vinod096/learn-python
/lesson_02/personal/chapter_5/12_Maximum_of_Two_Values.py
867
4.625
5
#Write a function named max that accepts two integer values as arguments and returns the #value that is the greater of the two. For example, if 7 and 12 are passed as arguments to #the function, the function should return 12. Use the function in a program that prompts the #user to enter two integer values. The program ...
true
83b9e523b3ff90d47c7689f3293b77a16d05a965
Vinod096/learn-python
/lesson_02/personal/chapter_5/06_calories.py
1,078
4.65625
5
#A nutritionist who works for a fitness club helps members by evaluating their diets. As part #of her evaluation, she asks members for the number of fat grams and carbohydrate grams #that they consumed in a day. Then, she calculates the number of calories that result from #the fat, using the following formula: #calorie...
true
11a462649f8ebd34f0d29ab619e6d36bc98160af
Moandh81/python-self-training
/tuple/9.py
494
4.34375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # Write a Python program to find the repeated items of a tuple. mytuple = ("dog", "cat", "cow", "fox", "hen", "cock", "lion" , "zebra","duck" ,"bull", "sheep", "cat", "cow", "fox", "lion") frequency = {} for item in mytuple: if item.lower() not in frequency: ...
true
ac6d44000cce88e231a9a85d082c8538b44fd515
Moandh81/python-self-training
/datetime/32.py
272
4.375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # Write a Python program to calculate a number of days between two dates. from datetime import date t1 = date(year = 2018, month = 7, day = 12) t2 = date(year = 2017, month = 12, day = 23) t3 = t1 - t2 print("t3 =", t3)
true
fee021a37c322579ad36109a92c914eaf4a809b7
Moandh81/python-self-training
/functions/1.py
657
4.375
4
#!/usr/bin/env python # -*- coding: utf-8 -* # Write a Python function to find the Max of three numbers. import re expression = r'[0-9]+' numberslist = [] number1 = number2 = number3 = "" while re.search(expression, number1) is None: number1 = input('Please input first number: \n') while re.search(expressio...
true
4a43f7f498cda12296b75247c5b6d45941519527
Moandh81/python-self-training
/conditional-statements-and-loops/5.py
268
4.375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # Write a Python program that accepts a word from the user and reverse it. word = input("Please input a word : \n") newword = "" i = len(word) while i > 0: newword = newword + word[i-1] i = i - 1 print(newword)
true
c78566301e0cc885f89c65310e9245fb5072dce1
Moandh81/python-self-training
/dictionary/24.py
517
4.5
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # Write a Python program to create a dictionary from a string. Go to the editor # Note: Track the count of the letters from the string. # Sample string : 'w3resource' # Expected output: {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1, 'e': 2, 'o': 1} txt = input('Please...
true
7897869a67893a3ea72027ae8911e80e9e1d8f6a
Moandh81/python-self-training
/datetime/7.py
450
4.4375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # Write a Python program to print yesterday, today, tomorrow from datetime import datetime, date, time today = datetime.today() print("Today is " , today) yesterday = today.timestamp() - 60*60*24 yesterday = date.fromtimestamp(yesterday) print( "Yesterday is " ...
true
cdf3abaafdf05f6cc6a164b72120b100c010fe28
Moandh81/python-self-training
/sets/6.py
256
4.15625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # Write a Python program to create an intersection of sets. set1 = {"apple", "banana", "cherry" , "strawberry"} set2 = {"cherry", "ananas", "strawberry", "cocoa"} set3 = set1.intersection(set2) print(set3)
true
c05aca3c8637d78d9f31db8209ec7f3f1d6060cd
Moandh81/python-self-training
/functions/2.py
360
4.1875
4
#!/usr/bin/env python # -*- coding: utf-8 -* # Write a Python function to sum all the numbers in a list. Go to the editor # Sample List : (8, 2, 3, 0, 7) # Expected Output : 20 liste = [1,2,3,4,5] def sumliste(liste): sum = 0 for item in liste: sum = sum + item print("The sum of the numbers in the list ...
true
4870640a39e9da3773c603ccb30b877b56c6c693
J-Krisz/project_Euler
/Problem 4 - Largest palindrome product.py
462
4.125
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 is_palindrome(n): return str(n) == str(n)[::-1] my_list = [] for n_1 in range(100, 1000): for...
true
4f05572563bd615a85bccc3d225f28b8a4ae36b5
djeikyb/learnpythonthehardway
/ex19a.py
1,298
4.125
4
# write a comment above each line explaining # define a function. eats counters for cheese and cracker boxen # shits print statements def cheese_and_crackers(cheese_count, boxes_of_crackers): # print var as decimal print "You have %d cheeses!" % cheese_count # print var as decimal pr...
true
44142626c57508d50cf1977411479703657439fc
stjohn/csci127
/errorsHex.py
1,179
4.21875
4
#CSci 127 Teaching Staff #October 2017 #A program that converts hex numbers to decimal, but filled with errors... Modified by: ADD YOUR NAME HERE define convert(s): """ Takes a hex string as input. Returns decimal equivalent. """ total = 0 for c in s total = total * 16 ...
true
59412e27906d5aa3a7f435bfb4ab63d9ee5ed5a2
RamrajSegur/Computer-Vision-Python
/OpenCV-Python/line.py
1,046
4.125
4
#Program to print a line on an image using opencv tools import numpy as np import cv2 # Create a grayscale image or color background of desired intensity img = np.ones((480,520,3),np.uint8) #Creating a 3D array b,g,r=cv2.split(img)#Splitting the color channels img=cv2.merge((10*b,150*g,10*r))#Merging the color channels...
true
c954b3d5067de813172f46d1ce5b610a5adc6317
LL-Pengfei/cpbook-code
/ch2/vector_arraylist.py
421
4.125
4
def main(): arr = [7, 7, 7] # Initial value [7, 7, 7] print("arr[2] = {}".format(arr[2])) # 7 for i in range(3): arr[i] = i; print("arr[2] = {}".format(arr[2])) # 2 # arr[5] = 5; # index out of range error generated as index 5 does not exist # uncomment the line above to see the error arr.append...
true
039e8c37b1c95e7659c109d2abbef9b697e7ca3d
xiaochenchen-PITT/CC150_Python
/Design_Patterns/Factory.py
2,731
4.78125
5
'''The essence of Factory Design Pattern is to "Define a factory creation method(interface) for creating objects for different classes. And the factory instance is to instantiate other class instances. The Factory method lets a class defer instantiation to subclasses." Key point of Factory Design Pattern is-- Only ...
true
6ce064242cb40428e52917203518b1291ceeb0e5
emetowinner/python-challenges
/Phase-1/Python Basic 2/Day-26.py
2,807
4.5625
5
''' 1. Write a Python program to count the number of arguments in a given function. Sample Output: 0 1 2 3 4 1 2. Write a Python program to compute cumulative sum of numbers of a given list. Note: Cumulative sum = sum of itself + all previous numbers in the said list. Sample Output: [10, 30, 60, 100, 150, 210, 217] [1...
true
48449d264326a4508b0f111d19a6f5832155485d
emetowinner/python-challenges
/Phase-1/Python Basic 2/Day-28.py
2,740
4.375
4
''' 1. Write a Python program to check whether two given circles (given center (x,y) and radius) are intersecting. Return true for intersecting otherwise false. Sample Output: True False 2. Write a Python program to compute the digit distance between two integers. The digit distance between two numbers is the absolute...
true
6ece47524c7619b649fd02a684262c06eac17f53
Megha2122000/python3
/3.py
361
4.21875
4
# -*- coding: utf-8 -*- """ Created on Thu Aug 19 15:30:29 2021 @author: Comp """ # Python program to print positive Numbers in a List # list of numbers list1 = [-12 , -7 , 5 ,64 , -14] # iterating each number in list for num in list1: # checking condition if n...
true
ccad48e6c0098ebc9f19b8218034baada0a18a53
sushrest/machine-learning-intro
/decisiontree.py
1,455
4.4375
4
# scikit-learn Machine Learning Library in python # Environment Python Tensorflow # Following example demonstrates a basic Machine Learning examples using # Supervised Learning by making use of Decision Tree Classifier and its fit algorithm to predict whether the given # features belong to Apple or Orange from sklea...
true
ccc3abda28abe8e4719c043e55fe47fe3e9f7b53
fight741/DaVinciCode
/main.py
435
4.15625
4
import numpy as np start = input("start from : ") end = input("end with : ") number = int(np.random.randint(int(start), int(end)+1)) g = int(input("Input your guess here : ")) while g != number: if g > number: print("The number is smaller") g = int(input("Give another guess : ")) else: ...
true
8bb4ef10fa5bb4e81806cdb797e2a7d857854f37
mbeliogl/simple_ciphers
/Caesar/caesar.py
2,137
4.375
4
import sys # using caesar cipher to encrypy a string def caesarEncrypt(plainText, numShift): alphabet = 'abcdefghijklmnopqrstuvwxyz ' key = [] cipherText = '' plainText = plainText.lower() # the for loop ensures we are looping around for i in range(len(alphabet)): if i + numShift >...
true
4d969849727d7b049825d2dcf47db14b7dd16a67
AndrewBowerman/example_projects
/Python/oopRectangle.py
1,745
4.5625
5
""" oopRectangle.py intro to OOP by building a Rectangle class that demonstrates inheritance and polymorphism. """ def main(): print ("Rectangle a:") a = Rectangle(5, 7) print ("area: {}".format(a.area)) print ("perimeter: {}".format(a.perimeter)) print ("") print ("Rectan...
true
6f7d33585fac28efdcbd848c65e489bb71044b0b
singhankur7/Python
/advanced loops.py
2,306
4.375
4
# -*- coding: utf-8 -*- """ Created on Sat Feb 9 23:48:15 2019 @author: New """ """ Python is easy: Homework assignment #6 Advanced Loops """ # for the maximum width(columns) and maximum height(rows) that my playing board can take # This was achieved by trial and error # Defining the function which...
true
b6b9a578c524fa372d4adf93096d3a5c29b5c5d0
sagarneeli/coding-challenges
/Linked List/evaluate_expression.py
2,583
4.59375
5
# Python3 program to evaluate a given # expression where tokens are # separated by space. # Function to find precedence # of operators. def precedence(op): if op == '+' or op == '-': return 1 if op == '*' or op == '/': return 2 return 0 # Function to perform arithmetic # operations. def applyOp(a, ...
true
0a1a0f66af66feb4ee13899192bc64ef2d66f018
sy-li/ICB_EX7
/ex7_sli.py
1,791
4.375
4
# This script is for Exercise 7 by Shuyue Li # Q1 import pandas as pd def odd(df): ''' This function is aimed to return the add rows of a pandas dataframe df should be a pandas dataframe ''' nrow = df.shape[0] odds = pd.DataFrame() for i in range(1,nrow): if i%2 == 0: ...
true
c24b76b40773bcde6356d5ba2f951cdd3eea5d94
io-ma/Zed-Shaw-s-books
/lmpthw/ex4_args/sys_argv.py
1,302
4.4375
4
""" This is a program that encodes any text using the ROT13 cipher. You need 2 files in the same dir with this script: text.txt and result.txt. Write your text in text.txt, run the script and you will get the encoded version in result.txt. Usage: sys_argv.py -i <text.txt> -o <result.txt> """ import sys, codecs ...
true
e015f0925ccb831ef32e805bd81fff3db46668f6
io-ma/Zed-Shaw-s-books
/lpthw/ex19/ex19_sd1.py
1,485
4.34375
4
# define a function called cheese_and_crackers that takes # cheese_count and boxes_of_crackers as arguments def cheese_and_crackers(cheese_count, boxes_of_crackers): # prints a string that has cheese_count in it print(f"You have {cheese_count} cheeses!") # prints a string that has boxes_of_crackers in it ...
true
a6da253639d8ca65b62444ec6bc60545c11d2501
blakfeld/Data-Structures-and-Algoritms-Practice
/Python/general/binary_search_rotated_array.py
1,661
4.34375
4
#!/usr/bin/env python """ binary_search_rotated_array.py Author: Corwin Brown <blakfeld@gmail.com> """ from __future__ import print_function import sys import utils def binary_search(list_to_search, num_to_find): """ Perform a Binary Search on a rotated array of ints. Args: list_to_search (lis...
true
c6b2dab45e102ae19dc887e97e296e5c90f68a51
tocxu/program
/python/function_docstring.py
264
4.34375
4
def print_max(x,y): '''Prints the maximum of two numbers. The two values must be integers.''' #convert to integers, if possible x=int(x) y=int(y) if x>y: print x, 'is maximum' else: print y,'is maximum' print (3,5) print_max(3,5) print print_max.__doc__
true
a4b203896d017258eb8d703b4afc92ce8d03df7c
humbertoperdomo/practices
/python/PythonCrashCourse/PartI/Chapter09/number_served.py
1,550
4.15625
4
#!e/urs/bn/python3 # restaurant.py """Class Restaurant""" class Restaurant(): """Class that represent a restaurant.""" def __init__(self, restaurant_name, cuisine_type): """Initialize restaurant_name and cuisine_type attributes.""" self.restaurant_name = restaurant_name self.cuisine_typ...
true
5d2c49f3e11cc346105c7fb02c59435e2b56af76
Necmttn/learning
/python/algorithms-in-python/r-1/main/twenty.py
790
4.25
4
""" Python’s random module includes a function shuffle(data) that accepts a list of elements and randomly reorders the elements so that each possi- ble order occurs with equal probability. The random module includes a more basic function randint(a, b) that returns a uniformly random integer from a to b (including both ...
true
d69ba19f1271f93a702fd8009c57a34a11122c6b
Necmttn/learning
/python/algorithms-in-python/r-1/main/sixteen.py
684
4.21875
4
""" In our implementation of the scale function (page25),the body of the loop executes the command data[j]= factor. We have discussed that numeric types are immutable, and that use of the *= operator in this context causes the creation of a new instance (not the mutation of an existing instance). How is it still poss...
true
8cc73de7110d0300d84909f76d7cebb6f0e772e9
tboy4all/Python-Files
/csv_exe.py
684
4.1875
4
#one that prints out all of the first and last names in the users.csv file #one that prompts us to enter a first and last name and adds it to the users.csv file. import csv # Part 2 def print_names(): with open('users.csv') as file: reader = csv.DictReader(file) for row in reader: pri...
true
0fbfcaafa9794d32855c67db1117c3ec4d682864
holomorphicsean/PyCharmProjectEuler
/euler9.py
778
4.28125
4
"""A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a**2 + b**2 = c**2 For example, 3**2 + 4**2 = 9 + 16 = 2**5 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.""" import time import math # We are going to just brute force this and ch...
true
1dbf066eeb432496cb1cc5dec86d41f54eefd74f
Murali1125/Fellowship_programs
/DataStructurePrograms/2Darray_range(0,1000).py
901
4.15625
4
"""-------------------------------------------------------------------- -->Take a range of 0 - 1000 Numbers and find the Prime numbers in that --range. Store the prime numbers in a 2D Array, the first dimension --represents the range 0-100, 100-200, and so on. While the second --dimension represents the prime numbers ...
true
ebfd35ab13d1b55fe3b78f1974a512a1dccb7a4d
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/921 Minimum Add to Make Parentheses Valid.py
1,116
4.21875
4
#!/usr/bin/python3 """ Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', and in any positions ) so that the resulting parentheses string is valid. Formally, a parentheses string is valid if and only if: It is the empty string, or It can be written as AB (A concatenate...
true
3e60a45e7923bb72bece7ee0f705b2d6467ee4a6
syurskyi/Python_Topics
/070_oop/001_classes/examples/The_Complete_Python_Course_l_Learn_Python_by_Doing/61. More about classes and objects.py
1,239
4.5
4
""" Object oriented programming is used to help conceptualise the interactions between objects. I wanted to give you a couple more examples of classes, and try to answer a few frequent questions. """ class Movie: def __init__(self, name, year): self.name = name self.year = year """ Parameter na...
true
bbbd1d21e8e907c7353f2a1aee9c6c2984a4c255
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/Algorithmic Problems in Python/binary_search.py
986
4.3125
4
#we can achieve O(logN) but the array must be sorted ___ binary_search(array,item,left,right): #base case for recursive function calls #this is the search miss (array does not contain the item) __ right < left: r.. -1 #let's generate the middle item's index middle left + (right-left)//2 print("Middle index...
true
5fb93b463f49e0440570a02f3d1eea4cc91e8d0f
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/405 Convert a Number to Hexadecimal.py
1,467
4.3125
4
""" Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two's complement method is used. Note: All letters in hexadecimal (a-f) must be in lowercase. The hexadecimal string must not contain extra leading 0s. If the number is zero, it is represented by a single zero character '0'; ...
true
e415830c017fb802d0f55c1f525d59af43fe82b1
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/838 Push Dominoes.py
2,392
4.1875
4
#!/usr/bin/python3 """ There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dom...
true
e9e455eacdb596a36f52fee4dd8175aa37686023
syurskyi/Python_Topics
/030_control_flow/example/Python-from-Zero-to-Hero/03-Коллеции, циклы, логика/11_ДЗ-1-2_solution.py
259
4.125
4
# 1 rows = int(input('Enter the number of rows')) for x in range(rows): print('*' * (x+1)) # 2 limit = int(input('Enter the limit')) for x in range(limit): if x % 2 == 0: print(f'{x} is EVEN') else print(f'{x} is ODD')
true
d83552fae236deecb6b23fb25234bdf7ff6f26b9
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/771 Jewels and Stones.py
763
4.1875
4
#!/usr/bin/python3 """ You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels. The letters in J are guaranteed distinct, and all characters in J ...
true
e9b7e415a19e4aae056651b649a4744fe88aba1b
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/693 Binary Number with Alternating Bits.py
729
4.34375
4
#!/usr/bin/python3 """ Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Input: 5 Output: True Explanation: The binary representation of 5 is: 101 Example 2: Input: 7 Output: False Explanation: The binary representation of 7 is: ...
true
550e085e7618bbc1b7046419f23a47587965a162
syurskyi/Python_Topics
/070_oop/004_inheritance/examples/super/Python 3 super()/001_super function example.py
1,476
4.78125
5
# At first, just look at the following code we used in our Python Inheritance tutorial. In that example code, # the superclass was Person and the subclass was Student. So the code is shown below. class Person: # initializing the variables name = "" age = 0 # defining constructor def __init__(self,...
true
eb10863faaab3eabc8f28a687d4d698567c8cea0
syurskyi/Python_Topics
/125_algorithms/_examples/_algorithms_challenges/pybites/beginner/149/solution.py
560
4.125
4
words = ("It's almost Holidays and PyBites wishes You a " "Merry Christmas and a Happy 2019").split() def sort_words_case_insensitively(words): """Sort the provided word list ignoring case, and numbers last (1995, 19ab = numbers / Happy, happy4you = strings, hence for numbers you only n...
true
167776832ada38867f57a79bd37cf80b5ef2ff70
syurskyi/Python_Topics
/050_iterations_comprehension_generations/001_iterations_and_iteration_tool/examples/013_Copying an Iterator.py
1,344
4.90625
5
# "Copying" an Iterator # Sometimes we may have an iterator that we want to use multiple times for some reason. # As we saw, iterators get exhausted, so # simply making multiple references to the same iterator will not work - # they will just point to the same iterator object. # # What we would really like is a way to ...
true
0c8fc8a50961f4cd18c3b1bfe27baf3beb6e8cdc
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/Array/SortArrayByParity.py
889
4.125
4
""" 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 [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be...
true
fc8d7266535b1af6ba76aac70e15c867ee09d069
syurskyi/Python_Topics
/125_algorithms/_examples/Python_Hand-on_Solve_200_Problems/Section 14 Array/array_longest_non_repeat_solution.py
2,461
4.25
4
# To add a new cell, type '# %%' # To add a new markdown cell, type '# %% [markdown]' # %% # --------------------------------------------------------------- # python best courses https://courses.tanpham.org/ # --------------------------------------------------------------- # Challenge # Given a string, find the length ...
true
2bfd3d1c05de676850cd447ca2f9adab34335e98
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/String/SortCharactersByFrequency.py
1,384
4.15625
4
""" Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer. Example 2: Input: "cccaaa" Output: "...
true
f6266f2a13c31a765420db79fdb8235f06487c5e
syurskyi/Python_Topics
/125_algorithms/_exercises/exercises/_algorithms_challenges/pybites/beginner/beginner-bite-208-find-the-number-pairs-summing-up-n.py
1,075
4.34375
4
''' In this Bite you complete find_number_pairs which receives a list of numbers and returns all the pairs that sum up N (default=10). Return this list of tuples from the function. So in the most basic example if we pass in [2, 3, 5, 4, 6] it returns [(4, 6)] and if we give it [9, 1, 3, 8, 7] it returns [(9, 1), (3, 7...
true
69ad335243346001307df683f73d09e66a0e72d3
syurskyi/Python_Topics
/095_os_and_sys/examples/realpython/018_Deleting Directories.py
1,222
4.3125
4
# The standard library offers the following functions for deleting directories: # # os.rmdir() # pathlib.Path.rmdir() # shutil.rmtree() # # To delete a single directory or folder, use os.rmdir() or pathlib.rmdir(). These two functions only work if the d # irectory you’re trying to delete is empty. If the di...
true
3ea4a2eeebbb4784a57accf7184350ed53c503ff
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/Array/SortArrayByParityII.py
968
4.21875
4
""" Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even. You may return any answer array that satisfies this condition. Example 1: Input: [4,2,5,7] Output: [4,5...
true
0586551822d2c81be6473a3604a06b80f558c254
syurskyi/Python_Topics
/120_design_patterns/016_iterator/examples/Iterator_003.py
1,326
4.375
4
#!/usr/bin/env python # Written by: DGC #============================================================================== class ReverseIterator(object): """ Iterates the object given to it in reverse so it shows the difference. """ def __init__(self, iterable_object): self.list = iterable_obje...
true
14e23ea3e3de89813068797bce4742c01e62044d
syurskyi/Python_Topics
/045_functions/008_built_in_functions/reduce/_exercises/templates/002_Using Operator Functions.py
829
4.28125
4
# # python code to demonstrate working of reduce() # # using operator functions # # # importing functools for reduce() # ____ f.. # # # importing operator for operator functions # ____ o.. # # # initializing list # lis _ 1 3 5 6 2 # # # using reduce to compute sum of list # # using operator functions # print ("The sum...
true
048985656c8b9aa4fdd20d5f4485302a9059ebe2
syurskyi/Python_Topics
/095_os_and_sys/examples/pathlib — Filesystem Paths as Objects/009_Deleting/001_pathlib_rmdir.py
926
4.28125
4
# There are two methods for removing things from the file system, depending on the type. To remove an empty directory, use rmdir(). # pathlib_rmdir.py # # import pathlib # # p = pathlib.Path('example_dir') # # print('Removing {}'.format(p)) # p.rmdir() # # A FileNotFoundError exception is raised if the post-conditions ...
true
a64c2c4481a7f03ccad171656f3430c81f4496db
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/pybites/intermediate/intermediate-bite-18-find-the-most-common-word.py
2,185
4.25
4
""" Write a function that returns the most common (non stop)word in this Harry Potter text. Make sure you convert to lowercase, strip out non-alphanumeric characters and stopwords. Your function should return a tuple of (most_common_word, frequency). The template code already loads the Harry Potter text and list of s...
true
d6457e1f59aa2e7f58e030cdc15209bc2e73432b
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/Recursion, Backtracking and Dynamic Programming in Python/Section 3 Search Algorithms/LinearSearch.py
489
4.1875
4
___ linear_search(container, item # the running time of this algorithms is O(N) # USE LINEAR SEARCH IF THE DATA STRUCTURE IS UNORDERED !!! ___ index __ ra__(le_(container)): __ container[index] __ item: # if we find the item: we return the index of that item r_ index ...
true
ab0688242ee45e648ef23c6aea22c389a47fb746
syurskyi/Python_Topics
/095_os_and_sys/_exercises/exercises/realpython/017_Deleting Files in Python.py
2,381
4.28125
4
# # To delete a single file, use pathlib.Path.unlink(), os.remove(). or os.unlink(). # # os.remove() and os.unlink() are semantically identical. To delete a file using os.remove(), do the following: # # ______ __ # # data_file _ 'C:\\Users\\vuyisile\\Desktop\\Test\\data.txt' # __.r.. ? # # # Deleting a file using os.un...
true
b6e934cfc5af74841bd8c4a8f951220163ce6bb0
syurskyi/Python_Topics
/125_algorithms/_examples/Learn_Python_by_solving_100_Coding_Challenges/Coding Challenge No. 92 - SortColours.py
757
4.15625
4
# Sort Colours # Question: Given an array with n objects coloured red, white or blue, sort them so that objects of the same colour are adjacent, with the colours in the order red, white and blue. # Here, we will use the integers 0, 1, and 2 to represent the colour red, white, and blue respectively. # Note: You are not ...
true
8b3ff422b9e6313a0af0302c628c4179f750d85e
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/227 Basic Calculator II py3.py
2,303
4.21875
4
#!/usr/bin/python3 """ Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero. Example 1: Input: "3+2*2" Output: 7 Example 2: Input: " 3/2 " Output: 1 Exa...
true
58cf2e0e3efb0f44bce7b4ef7c203fc27a443842
syurskyi/Python_Topics
/095_os_and_sys/examples/realpython/005_Listing All Files in a Directory.py
2,565
4.375
4
# This section will show you how to print out the names of files in a directory using os.listdir(), os.scandir(), # and pathlib.Path(). To filter out directories and only list files from a directory listing produced by os.listdir(), # use os.path: # import os # List all files in a directory using os.listdir basepath =...
true
29313678d25756a660eef4638259ee18459be08c
syurskyi/Python_Topics
/125_algorithms/_examples/Practice_Python_by_Solving_100_Python_Problems/77.py
219
4.125
4
#Create a script that gets user's age and returns year of birth from datetime import datetime age = int(input("What's your age? ")) year_birth = datetime.now().year - age print("You were born back in %s" % year_birth)
true
08eff574578ac91abce96916bc188833ac922619
syurskyi/Python_Topics
/125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/intermediate-bite-3-word-values.py
2,365
4.3125
4
""" Calculate the dictionary word that would have the most value in Scrabble. There are 3 tasks to complete for this Bite: First write a function to read in the dictionary.txt file (= DICTIONARY constant), returning a list of words (note that the words are separated by new lines). Second write a function that receiv...
true
dccee39c84fc8a8b20b0cb56c22b64111a294a7d
syurskyi/Python_Topics
/125_algorithms/_examples/_algorithms_challenges/pybites/topics/intro/intro-bite102-infinite-loop-input-continue-break.py
1,151
4.15625
4
VALID_COLORS = ['blue', 'yellow', 'red'] def my_print_colors(): """Ask for color, lowercase it, check if 'quit' is entered, if so print 'bye' and break, next check if given color is in VALID_COLORS, if not, continue, finally if that check passes, print the color""" while True: inp = inpu...
true
b7bad63ce92b0c02cb75adfbd722b04af3be1127
syurskyi/Python_Topics
/125_algorithms/_examples/Learn_Python_by_solving_100_Coding_Challenges/Coding Challenge No. 93 - SpiralMatrix.py
1,543
4.15625
4
# Spiral Matrix # Question: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. # For example: # Given the following matrix: # [ [ 1, 2, 3 ], # [ 4, 5, 6 ], # [ 7, 8, 9 ] ] # You should return [1,2,3,6,9,8,7,4,5]. # Solutions: class Solution: # @param matrix, a...
true
1dde8cb11156223aecd6a4a81853f4045270155d
syurskyi/Python_Topics
/125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/299_v4/base_converter.py
780
4.34375
4
def digit_map(num): """maps numbers greater than a single digit to letters (UPPER)""" return chr(num + 55) if num > 9 else str(num) def convert(number: int, base: int = 2) -> str: """Converts an integer into any base between 2 and 36 inclusive Args: number (int): Integer to convert bas...
true
dc8846f3e74b784dcee36049f2735d7dd2ae3c4d
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/581 Shortest Unsorted Continuous Subarray.py
2,052
4.3125
4
#!/usr/bin/python3 """ Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find the shortest such subarray and output its length. Example 1: Input: [2, 6, 4, 8, 10, 9, 15] Outp...
true
7a183c9f407ec53a128bb57bfd6e5f0f9e10df7d
syurskyi/Python_Topics
/070_oop/008_metaprogramming/_exercises/templates/Abstract Classes in Python/a_004_Concrete Methods in Abstract Base Classes.py
848
4.21875
4
# # Concrete Methods in Abstract Base Classes : # # Concrete classes contain only concrete (normal)methods whereas abstract class contains both concrete methods # # as well as abstract methods. Concrete class provide an implementation of abstract methods, the abstract base class # # can also provide an implementation b...
true
98357c37192a91a3dc3afbe121908ae36db45019
syurskyi/Python_Topics
/125_algorithms/_examples/Learn_Python_by_solving_100_Coding_Challenges/Coding Challenge No. 84 - ReverseInt.py
382
4.15625
4
# Reverse Integer # Question: Reverse digits of an integer. # Example1: x = 123, return 321 # Example2: x = -123, return -321. # Solutions: class Solution: # @return an integer def reverse(self, x): if x<0: sign = -1 else: sign = 1 strx=str(abs(x)) r = s...
true
c9481862292b011e70bf73b3d62078e3a0122ab7
syurskyi/Python_Topics
/120_design_patterns/025_without_topic/examples/MonoState.py
2,609
4.28125
4
#!/usr/bin/env python # Written by: DGC # python imports #============================================================================== class MonoState(object): __data = 5 @property def data(self): return self.__class__.__data @data.setter def data(self, value): self.__class...
true
42ea23542608d894bf2c4c50394464b9d68d0eeb
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/769 Max Chunks To Make Sorted.py
1,315
4.28125
4
#!/usr/bin/python3 """ Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into some number of "chunks" (partitions), and individually sort each chunk. After concatenating them, the result equals the sorted array. What is the most number of chunks we could have made? Example 1...
true
0291f8953312c8c71a778cb5defd91ca5c24ef09
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/AdvancedPython_OOP_with_Real_Words_Programs/App-6-Project-Calorie-Webapp/src/calorie.py
564
4.125
4
____ temperature _____ Temperature c_ Calorie: """Represents optimal calorie amount a person needs to take today""" ___ - weight, height, age, temperature): weight weight height height age age temperature temperature ___ calculate _ result 10 * weight + 6...
true
23c0c2ee5b6165c16168522bf61bc190696b3161
syurskyi/Python_Topics
/079_high_performance/examples/Writing High Performance Python/item_49.py
1,819
4.15625
4
import logging from pprint import pprint from sys import stdout as STDOUT # Example 1 def palindrome(word): """Return True if the given word is a palindrome.""" return word == word[::-1] assert palindrome('tacocat') assert not palindrome('banana') # Example 2 print(repr(palindrome.__doc__)) # Example 3 "...
true
2f0cd45309945619d5e95e75abf7be9718989ddf
syurskyi/Python_Topics
/120_design_patterns/009_decorator/_exercises/templates/decorator_003.py
1,334
4.1875
4
# """Decorator pattern # # Decorator is a structural design pattern. It is used to extend (decorate) the # functionality of a certain object at run-time, independently of other instances # of the same class. # The decorator pattern is an alternative to subclassing. Subclassing adds # behavior at compile time, and the c...
true
b7e17d3710c68df3ebf3b937d389f40cf4257d7e
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/959 Regions Cut By Slashes.py
2,876
4.1875
4
#!/usr/bin/python3 """ In a N x N grid composed of 1 x 1 squares, each 1 x 1 square consists of a /, \, or blank space. These characters divide the square into contiguous regions. (Note that backslash characters are escaped, so a \ is represented as "\\".) Return the number of regions. Example 1: Input: [ " /",...
true
2901e2dbaab6f155dfd2d32feeed803ef2d07a5d
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/674 Longest Continuous Increasing Subsequence.py
978
4.15625
4
#!/usr/bin/python3 """ Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). Example 1: Input: [1,3,5,4,7] Output: 3 Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3. Even though [1,3,5,7] is also an increasing subsequence, i...
true
69accf57e5d5b8c3921c910a0f19e3b4def863dc
syurskyi/Python_Topics
/125_algorithms/_examples/_algorithms_challenges/pybites/topics/supplementary exercises/e0001-zip.py
857
4.53125
5
# zip(), lists, tuples # list is a sequence type # list can hold heterogenous elements # list is mutable - can expand, shrink, elements can be modified # list is iterable # tuple is a sequence type # tuple can hold heterogeneous data # tuple is immutable # tuple is iterable # Test case 1 - when iterables are of equa...
true
438cb7633c606ebafa831e5a24a8ceb3ae2ba851
syurskyi/Python_Topics
/125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/intermediate-bite-272-find-common-words.py
1,862
4.34375
4
""" Given two sentences that each contains words in case insensitive way, you have to check the common case insensitive words appearing in both sentences. If there are duplicate words in the results, just choose one. The results should be sorted by words length. The sentences are presented as list of words. Example: ...
true
ab296e2bb06b26e229bf476a06432826585dbbb5
syurskyi/Python_Topics
/125_algorithms/_examples/Python_Hand-on_Solve_200_Problems/Section 4 Condition and Loop/2_dimensional_array_solution.py
1,011
4.375
4
# To add a new cell, type '# %%' # To add a new markdown cell, type '# %% [markdown]' # %% # --------------------------------------------------------------- # python best courses https://courses.tanpham.org/ # --------------------------------------------------------------- # Write a Python program which takes two digit...
true
650b2156b592b55355fcd441cdf6a29ba8760226
syurskyi/Python_Topics
/050_iterations_comprehension_generations/006_nested_comprehensions/examples/006_nested_comprehensions.py
1,954
4.75
5
# Nested Comprehensions # Just as with list comprehensions, we can nest generator expressions too: # A multiplication table: # Using a list comprehension approach first: # The equivalent generator expression would be: # We can iterate through mult_list: # But you'll notice that our rows are themselves generators! # o f...
true
f0deed5e91dc4476292f10ac0e544bd0a8290bb1
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/746 Min Cost Climbing Stairs.py
1,291
4.125
4
#!/usr/bin/python3 """ 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 steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1. Exampl...
true
69fb9eab9782d4b53bbd781db80061561795fe8e
syurskyi/Python_Topics
/045_functions/013_switch_simulation/003.py
922
4.125
4
def add(x, to=1): return x + to def divide(x, by=2): return x / by def square(x): return x ** 2 def invalid_op(x): raise Exception("Invalid operation") def perform_operation(x, chosen_operation, operation_args=None): # If operation_args wasn't provided (i.e. it is None), set it to be an empt...
true
0aa08a662cb93ae1b78a565535806c5f649c40c2
syurskyi/Python_Topics
/125_algorithms/_examples/Python_Hand-on_Solve_200_Problems/Section 4 Condition and Loop/triangle_types_solution.py
645
4.125
4
# To add a new cell, type '# %%' # To add a new markdown cell, type '# %% [markdown]' # %% # Write a Python program to check a triangle is equilateral, isosceles or scalene. # Note : # An equilateral triangle is a triangle in which all three sides are equal. # A scalene triangle is a triangle that has three unequal sid...
true
9668ed9b59dffd211b71d671e99bff049ca83215
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/232 Implement Queue using Stacks.py
1,349
4.28125
4
""" Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. empty() -- Return whether the queue is empty. Notes: You must use only standard operations of a stack -- which means only...
true
46b95cecb37be01d2c4ced998e143f9f08a7b9b2
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/pybites/intermediate/intermediate-bite-13-convert-dict-to-namedtuple-json.py
2,029
4.1875
4
""" TASK DESCRIPTION: Write a function to convert the given blog dict to a namedtuple. Write a second function to convert the resulting namedtuple to json. Here you probably need to use 2 of the _ methods of namedtuple :) """ ____ c.. _______ n.. ____ c.. _______ O.. ____ d__ _______ d__ _______ j__ # Q: What is the ...
true
1af8cd8a831f0b63b8c77d2ff35f4ec3e6a1b3f8
syurskyi/Python_Topics
/125_algorithms/_examples/Learn_Python_by_solving_100_Coding_Challenges/Coding Challenge No. 60 - MergeSortLists.py
1,158
4.15625
4
# Merge Sorted Lists # Question: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. # Solutions: class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: # @param two ListNo...
true
56ff56c9d7977a59184e97c87a15187edbd1a63f
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/520 Detect Capital.py
1,228
4.375
4
#!/usr/bin/python3 """ Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this word are capitals, like "USA". All letters in this word are not capitals, like "leetcode". Only t...
true
d30652b267569247f9d3c6a1f20ad03f3f902250
syurskyi/Python_Topics
/115_testing/_exercises/_templates/temp/Github/_Level_1/UnitTesting-master/Proj4/ListsAndTuples/listAndTuples.py
2,218
4.375
4
______ ___ ______ timeit # https://www.youtube.com/watch?v=NI26dqhs2Rk # Tuple is a smaller faster alternative to a list # List contains a sequence of data surrounded by brackets # Tuple contains a squence of data surrounded by parenthesis """ Lists can have data added, removed, or changed Tuples cannot change. Tu...
true
c035fcefec027a5b8e1c619b49d09c7c96cbc330
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/pybites/beginner/beginner-bite-169-simple-length-converter.py
1,245
4.34375
4
''' Your task is to complete the convert() function. It's purpose is to convert centimeters to inches and vice versa. As simple as that sounds, there are some caveats: convert(): The function will take value and fmt parameters: value: must be an int or a float otherwise raise a TypeError fmt: string containing either ...
true
0e1f60a4dd71d99753e8a19d3f767d8d2815615d
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/768 Max Chunks To Make Sorted II.py
1,673
4.40625
4
#!/usr/bin/python3 """ This question is the same as "Max Chunks to Make Sorted" except the integers of the given array are not necessarily distinct, the input array could be up to length 2000, and the elements could be up to 10**8. Given an array arr of integers (not necessarily distinct), we split the array into some...
true
2a941e251d78633d70caf05e60efa864cc49aba9
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/701 Insert into a Binary Search Tree.py
1,190
4.375
4
#!/usr/bin/python3 """ Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST. Note that there may exist multiple valid ways fo...
true
f50b7d8beae1763ff2665416301bec37eff8fc53
syurskyi/Python_Topics
/050_iterations_comprehension_generations/009_permutations/examples/009_permutations.py
1,745
4.46875
4
# Permutations # In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence # or order, or if the set is already ordered, rearranging (reordering) its elements, a process called permuting. # These differ from combinations, which are selections of some members o...
true
c3cac517a34075d13cc9839c5aafffab20eefd1d
syurskyi/Python_Topics
/045_functions/007_lambda/examples/The_Modern_Python_3_Bootcamp/Coding Exercise 67 sum_even_values.py
566
4.21875
4
# Sum Even Values Solution # # I define a function called sum_even_values which accepts any number of arguments, thanks to *args # I grab the even numbers using the generator expression (arg for arg in args if arg % 2 == 0) # (could also use a list comp) # I pass the even numbers I extracted into sum()...
true
e68fa28abb8eb130145171dbbaadced13f473c6d
syurskyi/Python_Topics
/125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/953 Verifying an Alien Dictionary.py
1,996
4.21875
4
#!/usr/bin/python3 """ In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if th...
true
c7fde44dbdbdd8fbf0a8f75bc98819f46a6d2dd2
Nunziatellanicolepalarymzai/Python-104
/mean.py
883
4.375
4
# Python program to print # mean of elements # list of elements to calculate mean import csv with open('./height-weight.csv', newline='') as f: reader = csv.reader(f) #csv.reader method,reads and returns the current row and then moves to the next file_data = list(reader) #list(reader) adds the...
true
34b74af222fda40f35d744e2909cde08df0f3092
ravis3517/i-neuron-assigment-and-project-
/i neuron_python_prog_ Assignment_3.py
1,845
4.34375
4
#!/usr/bin/env python # coding: utf-8 # 1. Write a Python Program to Check if a Number is Positive, Negative or Zero # In[25]: num = float(input("Enter a number: ")) if num >0: print("positive") elif num <0 : print("negative") else: print(" number is zero") # 2. Wri...
true
07540d509c99f96db7fcc7f7362a36f5dc52d36d
bowie2k3/cos205
/COS-205_assignment4b_AJ.py
683
4.5
4
# Write a program that counts the number of words in a text file. # the program should print out [...] the number of words in the file. # Your program should prompt the user for the file name, which # should be stored at the same location as the program. # It should consider anything that is separated by white space o...
true
b6d35f31562d97ec2fe4c6d9a1d349d23a45e7ea
jmmalnar/python_projects
/primes.py
1,896
4.40625
4
import unittest # Find all the prime numbers less than a given integer def is_prime(num): """ Iterate from 2 up to the (number-1). Assume the number is prime, and work through all lower numbers. If the number is divisible by ANY of the lower numbers, then it's not prime """ prime_status = ...
true
69d63e236fd5585208ec5bebab45137c260c3562
lmhavrin/python-crash-course
/chapter-seven/deli.py
536
4.4375
4
# Exercise: 7-8 Deli # A for loop is useful for looping through a list # A while loop is useful for looping through a list AND MODIFYING IT sandwich_orders = ["turkey", "roast beef", "chicken", "BLT", "ham"] finished_sandwiches = [] while sandwich_orders: making_sandwich = sandwich_orders.pop() print("I made...
true