blob_id stringlengths 40 40 | repo_name stringlengths 5 127 | path stringlengths 2 523 | length_bytes int64 22 3.06M | score float64 3.5 5.34 | int_score int64 4 5 | text stringlengths 22 3.06M |
|---|---|---|---|---|---|---|
dbc0858c29b42a577ffc2a2a939cc2a293d07368 | syurskyi/Python_Topics | /070_oop/007_exceptions/_exercises/templates/The_Complete_Python_Course_l_Learn_Python_by_Doing/side_projects/handling_errors_in_user_input/errors.py | 608 | 4.03125 | 4 | def power_of_two():
user_input = input('Please enter a number: ')
try:
n = float(user_input)
n_square = n ** 2
return n_square
except ValueError:
print('Your input was invalid. Using default value 0')
return 0
print(power_of_two())
print(power_of_two())
# Define a... |
427f25eeaec738cf00e6b14a733d6f981bd4a63d | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/pybites/intermediate/intermediate-bite-135-sort-a-list-of-book-objects.py | 1,643 | 4.03125 | 4 | """
In this Bite you are going to look at a list of Book namedtuples and sort them by various criteria.
Complete the 4 functions below. Consider using lambda and/or one or more helper functions and/or
attrgetter (operator module). Good luck and have fun!
"""
____ c.. _______ n..
____ d__ _______ d__
____ o.. _______ a... |
553b58eaecdc8fedb8c451c1e9d35940b7d5cd72 | syurskyi/Python_Topics | /018_dictionaries/examples/Python 3 Most Nessesary/9.1.Listing 9.3. Creating a complete copy of the dictionary.py | 582 | 3.796875 | 4 | d1 = {"a": 1, "b": [20, 30, 40]}
# d2 = dict(d1) # Создаем поверхностную копию
# d2["b"][0] = "test"
# d1, d2 # Изменились значения в двух переменных!!!
# # ({'a': 1, 'b': ['test', 30, 40]}, {'a': 1, 'b': ['test', 30, 40]})
# import copy
# d3 = copy.deepcopy(d1) # Создаем полную копию
# d3["b"]... |
76751388da7addf8780880881fbcccc9dc38b93c | syurskyi/Python_Topics | /025_print/examples/025_print.py | 4,546 | 3.90625 | 4 | # -*- coding: utf-8 -*-
# Строка-разделитель выводиться не будет
x = 'spam'
y = 99
z = ['eggs']
print(x, y, z, sep='')
# Нестандартная строка-разделитель
x = 'spam'
y = 99
z = ['eggs']
print(x, y, z, sep=', ')
# Подавление вывода символа конца строки
x = 'spam'
y = 99
z = ['eggs']
print(x, y, z, end='')
# Вывод дву... |
56992da99dfce4fc45484256df0a63cb6f2d082a | syurskyi/Python_Topics | /045_functions/007_lambda/examples/004_Closures.py | 613 | 4.40625 | 4 | # -*- coding: utf-8 -*-
def outer_func(x):
y = 4
def inner_func(z):
print(f"x = {x}, y = {y}, z = {z}")
return x + y + z
return inner_func
for i in range(3):
closure = outer_func(i)
print(f"closure({i+5}) = {closure(i+5)}")
# Точно так же лямбда также может быть замыканием. ... |
ea7311d342a87982b177bc9d256f87684fd45410 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/409 Longest Palindrome.py | 874 | 3.96875 | 4 | """
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be
built with those letters.
This is case sensitive, for example "Aa" is not considered a palindrome here.
Note:
Assume the length of given string will not exceed 1,010.
Example:
Input:
"abccccdd... |
d3e9bd61135b603f1f8b149781f49b88e49eb11f | syurskyi/Python_Topics | /030_control_flow/001_if/examples/Python 3 Most Nessesary/4.2. Listing 4.2. Check several conditions.py | 790 | 4.21875 | 4 | # -*- coding: utf-8 -*-
print("""Какой операционной системой вы пользуетесь?
1 — Windows 8
2 — Windows 7
3 — Windows Vista
4 — Windows XP
5 — Другая""")
os = input("Введите число, соответствующее ответу: ")
if os == "1":
print("Вы выбрали: Windows 8")
elif os == "2":
print("Вы выбрали: Windows 7")
elif os ==... |
e58907b658aa64f39602711e90e8954b3d9ec228 | syurskyi/Python_Topics | /120_design_patterns/001_SOLID_design_principles/_exercises/_templates/dip/dependency_inversion_principle.py | 2,727 | 3.765625 | 4 | # """
# High level modules should not depend on low-level modules, both should depend on abstractions and Abstractions should
# not depend on details. Details should depend on abstractions.
# """
#
# # BAD PRACTICE
# print('>' * 10)
# print('BAD PRACTICE')
# print('>' * 10)
# from abc import ABCMeta, abstractmethod
#
#... |
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')
|
7c1e3d910e4171a54ebbb58ee6de5f9d2bcd5227 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/DynamicProgramming/121_BestTimeToBuyAndSellStock.py | 1,230 | 3.90625 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
c.. Solution o..
""" Same as "max subarray problem" using Kadane's Algorithm.
Just need one scan through the array values,
computing at each position the max profit ending at that position.
https://en.wikipedia.org/wiki/Maximum_subarray_problem
"""
... |
fa766880da60df8ad60e49550779bac2707a9cf1 | syurskyi/Python_Topics | /018_dictionaries/examples/Python 3 Deep Dive (Part 3)/16. Updating, Merging, and Copying - Coding.py | 5,226 | 4.4375 | 4 | # print('#' * 52 + ' Updating an existing keys value in a dictionary is straightforward: ')
#
# d = {'a': 1, 'b': 2, 'c': 3}
# d['b'] = 200
# print(d)
#
# print('#' * 52 + ' ')
# d1 = {'a': 1, 'b': 2}
# d2 = {'c': 3, 'd': 4}
# d1.update(d2)
# print(d1)
#
# print('#' * 52 + ' Note how the key order is maintained and ba... |
02326748ee457155d6e8f5d5a1499a63d7157f24 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/leetcode/leetCode/Array/SearchInRotatedSortedArray.py | 3,044 | 3.96875 | 4 | """
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).
You are given a target value to search. If found in the array return its index, otherwise return -1.
You may assume no duplicate exists in the array.
Your algorith... |
628cf9043b8d901c2123abb494aca0441c59a8e8 | syurskyi/Python_Topics | /070_oop/001_classes/_exercises/exercises/Learning Python/031_004_Implications for type testing.py | 922 | 3.5 | 4 | # c_ C:
# p___
#
# c_ D:
# p___
#
# c = C()
# d = D()
# print('#' * 23 + ' 3.0: compares the instances classes')
# print(ty.. c __ ty.. d # 3.0: compares the instances' classes
#
#
# print(ty.. c ty.. d
#
# c. -c, d. -c
#
#
# c1, c2 = C(), C()
# print(ty.. c1 __ ty.. c2
#
#
# c_ C
# p___
#
#... |
6c918e87b863ab1e3291fb39e9e7c78f79d82028 | syurskyi/Python_Topics | /125_algorithms/005_searching_and_sorting/_exercises/exersises/03_Buble Sort/4 - Bubble Sort - timeit.py | 1,963 | 3.75 | 4 | # ______ ti..
#
# NUM_REPETITIONS _ 500
#
# SETUP_CODE _ "from random import shuffle"
#
# # Bubble Sort Algorithm Implementations
#
# ___ bubble_sort lst
#
# n _ le. ?
#
# ___ i __ ra.. ?
# ___ j __ ra.. 0 ?-1
# __ ?|? > ?|?+1
# ?|? ?|?+1 _ ?|?+1 ?|?
#
# ___ bubble_sort_optim... |
f1cd67923e90294c3a5c457d1925664b58b06270 | syurskyi/Python_Topics | /125_algorithms/_exercises/exercises/Python_Hand-on_Solve_200_Problems/Section 7 Dictionary/check_key_exist_solution.py | 753 | 3.6875 | 4 | # # To add a new cell, type '# %%'
# # To add a new markdown cell, type '# %% [markdown]'
# # %%
# # ---------------------------------------------------------------
# # python best courses https://courses.tanpham.org/
# # ---------------------------------------------------------------
# # Check if a given key already e... |
a04d43d47db4b5358097188df07a0c25393bb3f4 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/100_Python_Exercises_Evaluate_and_Improve_Your_Skills/Exercise 91 - CSV to Database NUKE.py | 475 | 3.90625 | 4 | #Please download the database file database.db and and the ten_more_countries.txt file. Then, add the rows of the text file to the database file.
_______ sqlite3
_______ pandas
data pandas.read_csv("ten_more_countries.txt")
conn sqlite3.connect("database.db")
cur conn.cursor()
___ index, row __ data.iterrows
p... |
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 ... |
afad1ed9a71a346d6cadfff3f7ca922426047b88 | syurskyi/Python_Topics | /070_oop/006_enumerations/examples/Python 3 An Intro to Enumerations.py | 4,889 | 4.46875 | 4 | # Python added the enum module to the standard library in version 3.4. The Python documentation describes an enum like
# this: An enumeration is a set of symbolic names (members) bound to unique, constant values. Within an enumeration,
# the members can be compared by identity, and the enumeration itself can be iterate... |
4ceaf0265f4600274ff1d1002480e41d0441450a | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/82_v4/score.py | 365 | 3.625 | 4 | from enum import Enum
THUMBS_UP = '👍' # in case you go f-string ...
class Score(Enum):
BEGINNER = 2
INTERMEDIATE = 3
ADVANCED = 4
CHEATED = 1
def __str__(self):
return f'{self.name} => {THUMBS_UP * self.value}'
def average():
vals = [s.value for s in Score.__members__.valu... |
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: ... |
5d2df31c20546ffa5cded20386f6e03c6a1af097 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/459 Repeated Substring Pattern.py | 1,661 | 3.75 | 4 | #!/usr/bin/python3
"""
Given a non-empty string check if it can be constructed by taking a substring
of it and appending multiple copies of the substring together. You may assume
the given string consists of lowercase English letters only and its length will
not exceed 10000.
"""
c_ Solution:
___ repeatedSubstrin... |
6c27ed30f7c0259092479eae4b54a924d55e3251 | syurskyi/Python_Topics | /045_functions/_examples/Python-from-Zero-to-Hero/04-Функции и модули/06-Decorators.py | 1,179 | 4.125 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[ ]:
def hello_world():
print('Hello, world!')
hello_world()
# In[ ]:
hello2 = hello_world
hello2()
# In[ ]:
#return func from func
#pass in a func as an arg
# In[ ]:
def log_decorator(func):
def wrap():
print(f'Calling func {func}')
func(... |
a2694917932bacba638fec6327d5993272b652cc | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/LinkedList/83_RemoveDuplicatesFromSortedList.py | 892 | 3.8125 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: xuezaigds@gmail.com
# @Last Modified time: 2016-04-29 16:18:37
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
# Recursively
c.. Solution_2 o..
___ deleteDuplic... |
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,... |
b6aaf21d66855444a6f681923a383ca687e40f4b | syurskyi/Python_Topics | /070_oop/001_classes/examples/ITDN Python RUS/001_Vvedenie v OOP/02-class-attributes.py | 1,718 | 4.0625 | 4 | # -*- coding: utf-8 -*-
# Все члены класса в терминологии Python называются атрибутами
# Объявление класса MyClass с двумя атрибутами int_field
# и str_field. Атрибуты класса, являющиеся переменными,
# примерно соответствуют статическим полям класса в других
# языках программирования
class MyClass:
int_field = 8... |
6ee5d8d89559db11d88b34e9d985c35fb554695a | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/advanced/31_v3/matmul.py | 684 | 3.84375 | 4 | class Matrix(object):
def __init__(self, values):
self.values = values
def __repr__(self):
return f'<Matrix values="{self.values}">'
def __matmul__(self, other):
A = self.values
B = list(zip(*other.values))
print(A)
print(B)
Y = [[0 for _ in range(l... |
67592f055428cf2fd1aefd14a535c9d855a5a881 | syurskyi/Python_Topics | /010_strings/_exercises/_templates/Python 3 Most Nessesary/6.3. Row operations.py | 2,523 | 4.15625 | 4 | # # -*- coding: utf-8 -*-
# f__ -f _______ p.... # for Python 2.7
#
# s = "Python"
# print(s[0], s[1], s[2], s[3], s[4], s[5])
# # ('P', 'y', 't', 'h', 'o', 'n')
#
#
# s = "Python"
# # s[10]
# """
# Traceback (most recent call last):
# File "<pyshell#90>", line 1, in <module>
# s[10]
# IndexError: string index ... |
808cd586104300ae94577177ef184aa7f5c5e010 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/leetcode/leetCode/Array/IntersectionOfTwoArraysII.py | 2,297 | 3.828125 | 4 | """
Given two arrays, write a function to compute their intersection.
Example 1:
Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2,2]
Example 2:
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [4,9]
Note:
Each element in the result should appear as many times as it shows in both arrays.
The result can be in an... |
8496596aefa39873f8321a61d361bf209e54dcbd | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/108_Convert_Sorted_Array_to_Binary_Search_Tree.py | 977 | 3.859375 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
c_ Solution o..
# def sortedArrayToBST(self, nums):
# """
# :type nums: List[int]
# :rtype: TreeNode
# """
# ... |
580c6f1c7c387f91b9ff8782a595ed7f0ed4c183 | syurskyi/Python_Topics | /070_oop/001_classes/_exercises/_templates/Python_3_Deep_Dive_Part_4/Section 02 - Classes/06-Function_Attributes.py | 5,496 | 3.796875 | 4 | # # %%
# '''
# ### Function Attributes
# '''
#
# # %%
# '''
# So far, we have been dealing with non-callable attributes. When attributes are actually functions,
# things behave differently.
# '''
#
# # %%
# c_ Person
# ___ say_hello
# print('Hello!')
#
# # %%
# print ?.s..
#
# # %%
# print(ty..(?.s...
#
# #... |
401a88672799653d6ec7622503562ca9ade096c5 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/539 Minimum Time Difference.py | 1,007 | 3.84375 | 4 | #!/usr/bin/python3
"""
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the
minimum minutes difference between any two time points in the list.
Example 1:
Input: ["23:59","00:00"]
Output: 1
Note:
The number of time points in the given list is at least 2 and won't exceed 20000.
The input time is ... |
4a5bffa178e6da609717a681b19c51537a278a60 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/100_python_Best_practices_for_absolute_beginers/Project+1 How to detect Positive and Negative Numbers.py | 175 | 4.0625 | 4 | x float(input("Insert any number: "))
__ x>0:
print("This is a POSITIVE number")
____ x < 0:
print("This is a NEGATIVE number")
____:
print("The number is ZERO") |
819f625f8be17ccc19566382dbd6b8eb68b39580 | syurskyi/Python_Topics | /070_oop/001_classes/examples/Python 3 Most Nessesary/13.3.Listing 13.7. Inheritance.py | 671 | 3.78125 | 4 | class Class1: # Базовый класс
def func1(self):
print("Метод func1() класса Class1")
def func2(self):
print("Метод func2() класса Class1")
class Class2(Class1): # Класс Class2 наследует класс Class1
def func3(self):
print("Метод func3() класса Class2")
c = Class2() # ... |
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... |
4b608473f7af8c94e1e98dae58a5cdfac59943d2 | syurskyi/Python_Topics | /070_oop/001_classes/examples/Python_3_Deep_Dive_Part_4/Section 6 Single Inheritance/75. Delegating to Parent - Coding.py | 9,481 | 4.09375 | 4 | # %%
'''
### Delegating to Parent
'''
# %%
'''
You'll most likely encounter `super()` in the `__init__` method of custom classes, but delegation is not restricted to
__init__`. You can use `super()` anywhere you need to explicitly instruct Python to use a callable definition that is
higher up in the inheritance chain... |
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 ... |
0c0ac5a38c38b07dbcb2bca1dbcf4a7500700ef1 | syurskyi/Python_Topics | /085_regular_expressions/examples/Python 3 Most Nessesary/7.20. Finding the first pattern match.py | 1,533 | 3.828125 | 4 | # -*- coding: utf-8 -*-
import re
p = re.compile(r"[0-9]+")
print("Найдено" if p.match("str123") else "Нет")
# Нет
print("Найдено" if p.match("str123", 3) else "Нет")
# Найдено
print("Найдено" if p.match("123str") else "Нет")
# Найдено
p = r"[0-9]+"
print("Найдено" if re.match(p, "str123") else "Нет")
# Нет
print("Н... |
c1d5564b0ac514129054bc175764a865aa6e6e07 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/119_xmas_tree_generator/save1_passed.py | 487 | 3.796875 | 4 | def generate_xmas_tree(rows=10):
"""Generate a xmas tree of stars (*) for given rows (default 10).
Each row has row_number*2-1 stars, simple example: for rows=3 the
output would be like this (ignore docstring's indentation):
*
***
*****"""
tree_stars = [(line * 2 - 1) * '*'... |
a2ef98f9c2960ed70c81aeaf7add720023be160f | syurskyi/Python_Topics | /115_testing/examples/Github/_Level_1/unittest_example-master/test/test_example.py | 2,756 | 3.59375 | 4 | import unittest
# from typing import ...
# Example code to organize the unit testing of a class following xUnit philosophy with 'unittest'
# Designed following chapters 3 and 6 of "Python Unit Test Automation" - Ashwin Pajankar
# It has been written in a typed manner (PEP 484) (hence, only fully work as of Python 3.6... |
b515b48cbe2000b9d0ef4145af2b0ccb1e197bb1 | syurskyi/Python_Topics | /121_refactoring/Code_Smells/Bloaters/Long_Method/Replace_Temp_with_Query/006.py | 1,081 | 3.734375 | 4 | # Problem
def calculateTotal():
subtotal = calculateSubtotal()
discount = 0
if subtotal > 100:
discount = subtotal * 0.1
total = subtotal - discount
return total
def calculateSubtotal():
pass
# calculation logic for subtotal
# Solution
def calculateTotal():
subtotal = calcu... |
1f3cdd17aad7658f6e1eb39cf1e234514707db76 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/Recursion, Backtracking and Dynamic Programming in Python/Section 4 Selection Algorithms/QuickSelect.py | 1,433 | 3.5 | 4 | _____ r__
c_ QuickSelect:
___ - nums
nums nums
first_index 0
last_index le_(nums) - 1
___ run k
r_ select(first_index, last_index, k-1)
# PARTITION PHASE
___ partition first_index, last_index
# generate a random value within the range [first, last]
... |
4fd8358ac28cd3b5366ed7f9cb94833e72d8559a | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/DFS/WordSearchII.py | 3,633 | 3.953125 | 4 | """
Given a 2D board and a list of words from the dictionary, find all words in the board.
Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
Example:
Input: ... |
82432656d06b812015a3cb455c5c05085c762933 | syurskyi/Python_Topics | /125_algorithms/005_searching_and_sorting/_exercises/templates/02_Binary Search/4 Binary Search/Binary-Search-Recursive-Implementation-with-Print-Statements.py | 1,170 | 4.25 | 4 | # ___ binary_search data low high item
#
# print("\n===> Calling Binary Search")
# print("Lower bound:" ?
# print("Upper bound:" ?
#
# __ ? <_ ?
# middle _ ? + ?//2
# print("Middle index:" ?
# print("Item at middle index:" ?|?
# print("We are looking for:" ?
# pri... |
ff244299c6831f01e62b6e1ec05c777c9840c057 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/197/mday.py | 618 | 4.28125 | 4 | from datetime import date
def get_mothers_day_date(year):
"""Given the passed in year int, return the date Mother's Day
is celebrated assuming it's the 2nd Sunday of May."""
day_counter = 1
mothers_day = date(year, 5, day_counter)
sunday_count = 0
while sunday_count < 2:
if mothers_day.wee... |
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... |
08e9f80faf31bc8002939a3833f17f6c784e2b48 | syurskyi/Python_Topics | /070_oop/001_classes/_exercises/_templates/Python 3 Most Necessary/13.6.Listing 13.14. An example of overloading mathematical operators.py | 907 | 4.03125 | 4 | # -*- coding: utf-8 -*-
class MyClass:
def __init__(self, y):
self.x = y
def __add__(self, y): # Перегрузка оператора +
print("Экземпляр слева")
return self.x + y
def __radd__(self, y): # Перегрузка оператора +
print("Экземпляр справа")
return se... |
5b20636dd84b1d2d0e6ddee5cfe760bcebae38aa | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/Practical_Python_Programming_Practices/Practice 3. How to check for Greatest of 3 Numbers.py | 259 | 3.640625 | 4 | # x _ in. i.. "Insert first number: "
# y _ in. i.. "Insert second number: "
# z _ in. i.. "Insert third number: "
#
# print("The maximum number is : ", e.._"")
# __ y<_ x >_z:
# print(x)
# ____ x <_ y >_z:
# print(y)
# ____ x<_ z >_ y:
# print(z) |
fa5ce2dd1e40237d09d030ef93cc02a501f28d69 | syurskyi/Python_Topics | /125_algorithms/_exercises/exercises/Python_Hand-on_Solve_200_Problems/Section 10 Math/standard_deviation_solution.py | 823 | 3.546875 | 4 | # # To add a new cell, type '# %%'
# # To add a new markdown cell, type '# %% [markdown]'
# # %%
# # Write a Python program to calculate the standard deviation of the following data.
# # Input
# # Sample Data: [4, 2, 5, 8, 6]
# # Output
# # Standard Deviation : 2.23606797749979
#
# ______ ma__
# ______ ___
#
# ___ sd... |
56babf76fe75de9231d6b9079eeb56190fa70312 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/Practice_Python_by_Solving_100_Python_Problems/52.py | 278 | 4 | 4 | # #Please fix the script so that it returns the user submited first name for the first %s
# #and the second name for the second %s
#
# firstname = ? ("Enter first name: ")
# secondname = ? ("Enter second name: ")
# print("Your first name is __ and your second name is __" _ ? ?
|
b93d47200a6b3d85b091efd78c2d3ca1bac9f217 | syurskyi/Python_Topics | /018_dictionaries/examples/The_Modern_Python_3_Bootcamp/Coding Exercise 28 Totaling Donations Exercise.py | 741 | 3.828125 | 4 | # Version 1
#
# Loop over donations, add all the VALUES together and store in a variable called total_donations
donations = dict(sam=25.0, lena=88.99, chuck=13.0, linus=99.5, stan=150.0, lisa=50.25, harrison=10.0)
total_donations = 0
for donation in donations.values():
total_donations += donation
# Advanced Ver... |
c91dfb6cd0b30ca592645fcf0a1fa05ee0c13ad0 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/216 Combination Sum III.py | 1,182 | 3.671875 | 4 | """
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used
and each combination should be a unique set of numbers.
Ensure that numbers within the set are sorted in ascending order.
Example 1:
Input: k = 3, n = 7
Output:
[[1,2,4]]
Example 2:
Input: ... |
49a39ee32f845817124fe2e1cd2112ba6c790282 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/topics/Itertools/65/test_yield.py | 125 | 3.703125 | 4 |
def some_list(x):
for i in range(x):
for j in range(i):
yield (i+1)*(j+1)
print(list(some_list(5))) |
9823abdc5913bf193054f16ca7a44b5d55f69d99 | syurskyi/Python_Topics | /070_oop/008_metaprogramming/examples/Expert Python Programming/properties_decorator.py | 1,167 | 4.53125 | 5 | """
"Properties" section example of writing properties using
`property` decorator
"""
class Rectangle:
def __init__(self, x1, y1, x2, y2):
self.x1, self.y1 = x1, y1
self.x2, self.y2 = x2, y2
@property
def width(self):
"""rectangle height measured from top"""
return self.x... |
349f3736e7f0501b25121416277c49c97428fee4 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/pybites/intermediate/142_v2/scores.py | 1,604 | 4 | 4 | # ____ c.. _______ n..
#
# MIN_SCORE 4
# DICE_VALUES r.. 1, 7
#
# Player n..('Player', 'name scores')
#
#
# ___ calculate_score scores
# """Based on a list of score ints (dice roll), calculate the
# total score only taking into account >= MIN_SCORE
# (= eyes of the dice roll).
#
# If one of the... |
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 ... |
8aa25e67573a2f055e7a9846d5c1c26d7e08605c | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/BreadthFirstSearch/127_WordLadder.py | 2,448 | 3.875 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
c.. Solution o..
___ ladderLength beginWord, endWord, wordList
"""
Breadth First Search
When build the adjacency tree, skip the visited word
"""
__ beginWord __ endWord:
r_ 1
cur_level = [beginWord]
... |
588bf0bbec704e41a0cd2915531d901029ae21c0 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/beginner/beginner-bite-1-sum-n-numbers.py | 2,579 | 3.890625 | 4 |
"""
TASK DESCRIPTION:
Write a function that can sum up numbers:
It should receive a list of n numbers.
If no argument is provided, return sum of numbers 1..100.
Look closely to the type of the function's default argument ...
"""
# ??? Co powinno sie wydarzyc, jesli przekazemy pusta liste ???
input = []
###########... |
8d70800936635d3784421da646d1c8eebf91ae17 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/advanced/268_newbie_bite/save1_nopass.py | 106 | 3.6875 | 4 | # Enter your code below this line
month = input("What's the name of the 12th month of the calendar year?") |
7fbb8d1a8f6ba5adb4f40772214e605c8c901a24 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/387 First Unique Character in a String.py | 739 | 3.984375 | 4 | """
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.
Note: You may assume the string contain only lowercase letters.
"""
__author__ 'Daniel'
c_ Solution(o..
___ firstUniqChar s... |
848f72a5bccaaf413b9fcc51b5751a42a969a604 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/leetcode/leetCode/Backtracking/79_WordSearch.py | 2,328 | 3.953125 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
class Solution(object):
def exist(self, board, word):
if not board and word:
return False
if not word:
return True
m_rows = len(board)
n_cols = len(board[0])
for row in range(m_rows):
for co... |
6b5576d476a5b235e2152e5753db888d5b912fba | syurskyi/Python_Topics | /012_lists/_exercises/_templates/Learning Python/009_003_Python 2.X and 3.X mixed-type comparisons and sorts.py | 824 | 3.71875 | 4 | __author__ = 'sergejyurskyj'
L1 = [1, ('a', 3)] # Same value, unique objects
L2 = [1, ('a', 3)]
print(L1 == L2, L1 is L2) # Equivalent? Same object?
S1 = 'spam'
S2 = 'spam'
print(S1 == S2, S1 is S2)
S1 = 'a longer string'
S2 = 'a longer string'
print(S1 == S2, S1 is S2)
L1 = [1, ('a', 3)]
L2 = [1... |
a59eb87232f3f07450acc97b0ecccca53c611d09 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/beginner/254/scoping.py | 504 | 3.78125 | 4 | num_hundreds = -1
def sum_numbers(numbers: list) -> int:
"""Sums passed in numbers returning the total, also
update the global variable num_hundreds with the amount
of times 100 fits in total"""
sumlist = sum(numbers)
globals()['num_hundreds'] += sumlist //100
return sumlist
""" numlis... |
0048c207702b1fac7f6c1d42162732567d0749e6 | syurskyi/Python_Topics | /070_oop/001_classes/_exercises/exercises/Python_3_Deep_Dive_Part_4/Section 8 Descriptors/89. Descriptors - Coding.py | 3,307 | 4.21875 | 4 | # # %%
# '''
# ### Descriptors
# '''
#
# # %%
# '''
# Python **descriptors** are simply objects that implement the **descriptor protocol**.
# The protocol is comprised of the following special methods - not all are required.
# - `__get__`: used to retrieve the property value
# - `__set__`: used to store the property va... |
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:
"... |
a7d7ec6ef2a98fd3407265cd5af6c7f8f35d9e37 | syurskyi/Python_Topics | /070_oop/004_inheritance/examples/super/Understanding Python super()/001.py | 250 | 3.515625 | 4 | class Base(object):
def __init__(self):
print("Base created")
class ChildA(Base):
def __init__(self):
Base.__init__(self)
class ChildB(Base):
def __init__(self):
super(ChildB, self).__init__()
ChildA()
ChildB()
|
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... |
b3a301679651342e857b909786567e3792548d25 | syurskyi/Python_Topics | /095_os_and_sys/examples/realpython/031_Working With Compressed Archives.py | 950 | 3.578125 | 4 | # tarfile can also read and write TAR archives compressed using gzip, bzip2, and lzma compression.
# To read or write to a compressed archive, use tarfile.open(), passing in the appropriate mode for
# the compression type.
#
# For example, to read or write data to a TAR archive compressed using gzip, use the 'r:gz' or ... |
79f63e8ffd91b098a1bc5431b1c56a83ae08e113 | syurskyi/Python_Topics | /045_functions/007_lambda/_exercises/templates/003_Decorator can be applied to lambda_!cool!.py | 769 | 3.515625 | 4 | # -*- coding: utf-8 -*-
# ___ some_decorator f
# ___ wraps $
# print _*Calling function * | ?. -n |**|
# r_ ? a___
#
# r_ ?
#
# ??
# ___ decorated_function x
# print _*With argument *|x|**|
#
# ? 2
#
# print('#' * 52 + ' ')
# print('#' * 52 + ' ')
# print('#' * 52 + ' ')
#
# # Defining a... |
76d2c1b04fbd323151d922175310497a5cb8eb07 | syurskyi/Python_Topics | /070_oop/008_metaprogramming/examples/Abstract Classes in Python/a_003_Implementation Through Subclassing.py | 333 | 4.03125 | 4 | # Python program showing
# implementation of abstract
# class through subclassing
import abc
class parent:
def geeks(self):
pass
class child(parent):
def geeks(self):
print("child class")
# Driver code
print(issubclass(child, parent))
print(isinstance(child(), parent))
# Output:
#... |
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... |
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... |
834d18a6ecbdf21fa47341260b9a1fb240e5d200 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/324 Wiggle Sort II.py | 2,802 | 3.6875 | 4 | """
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
Example:
(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6].
(2) Given nums = [1, 3, 2, 2, 3, 1], one possible answer is [2, 3, 1, 3, 1, 2].
Note:
You may assume all input has valid answer.
Fo... |
e078c1706b2bf4fc5458e0377519db5d6243c4d4 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/algorithm-master/leetcode/684_redundant_connection.py | 1,647 | 3.625 | 4 | """
given input is an undirected graph
1. iterate edges
2. if u and v are connected before we add edge in nodes (graph)
=> that is the edge should be removed
"""
c_ Solution:
"""
UnionFind
"""
___ findRedundantConnection edges
"""
:type edges: List[List[int]]
:rtype: List[... |
a4246818f77617532d4e5049fe334f4a598c35bd | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/pybites/intermediate/325/arithmetic.py | 949 | 3.5 | 4 | # ____ t___ _______ G..
#
# VALUES "[0.1, 0.2, 0.3, 0.005, 0.005, 2.67]"
#
#
# ___ calc_sums values s.. ? __ G.. s.. N.. N..
# """
# Process the above JSON-encoded string of values and calculate the sum of each adjacent pair.
#
# The output should be a generator that produces a string that recites the calcu... |
f788a24381a9a53b3d2c1e1006cf7314749a80ec | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/042_Trapping_Rain_Water.py | 2,264 | 3.546875 | 4 | c_ Solution o..
___ trap height
"""
:type height: List[int]
:rtype: int
"""
ls = l.. height)
__ ls __ 0:
r_ 0
res, left = 0, 0
w.. left < ls a.. height[left] __ 0:
left += 1
pos = left + 1
w.. pos < ls:
... |
2eea360e8642372c4134745ba2fb376c0202b200 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/70/eggs.py | 438 | 3.625 | 4 | from random import choice
COLORS = 'red blue green yellow brown purple'.split()
class EggCreator:
def __init__(self, max) -> None:
self.max = max
self.count = 0
def __iter__(self):
return self
def __next__(self):
self.count += 1
if self.count <= self.max:
... |
00b1d1d09e4f4f30bdd78dd2ed68cc3cc03c5a79 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/Tree/ConvertSortedArrayToBinarySearchTree.py | 1,918 | 3.96875 | 4 | """
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
Example:
Given the sorted array: [-10,-3,0,5,9],
One pos... |
a5ae2046a401cae347fe7a33ccf0c96ec51dcef5 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/codeabbey/_Python_Problem_Solving-master/Palindrome.py | 474 | 4.25 | 4 | #The word or whole phrase which has the same sequence of letters in both directions is called a palindrome.
___ i __ r..(i..(i.. ))):
rev_str ''
s__ ''.j..(e ___ e __ i.. ).l.. __ e.islower
#here iam storing the string in the reverse form
___ j __ r..(l..(s__)-1,-1,-1
rev_str += s__[j]
#once... |
cce1bccf64a44bd76dba1e146f9de2de03f49171 | syurskyi/Python_Topics | /125_algorithms/_examples/Python_Hand-on_Solve_200_Problems/Section 12 Regex/all_word_contain_5_chracters_solution.py | 368 | 3.6875 | 4 | # To add a new cell, type '# %%'
# To add a new markdown cell, type '# %% [markdown]'
# %%
# Write a Python program to find all five characters long word in a string.
# Input
# 'The quick brown fox jumps over the lazy dog.'
# Output
# ['quick', 'brown', 'jumps']
import re
text = 'The quick brown fox jumps over the laz... |
cb921dc911e9303043b1928211b8573584a79a73 | syurskyi/Python_Topics | /115_testing/_exercises/_templates/temp/Github/_Level_1/unittest_examples-master/proj/sample_module.py | 244 | 3.90625 | 4 | ___ add2num(a,b
"""This function return sum of 2 numbers
>>> add2num(5,6)
11
>>> add2num(-10.5,3)
-7.5
>>> add2num(8, 'hello')
Traceback (most recent call last):
TypeError: unsupported operand type(s) for +: 'int' and 'str'
"""
r_ a+b |
c2ed4a564cc754afbee699556ef3b5483dca28ed | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/pybites/intermediate/9_v2/palindrome.py | 1,427 | 4.15625 | 4 | # """A palindrome is a word, phrase, number, or other sequence of characters
# which reads the same backward as forward"""
# _______ __
# _______ u__.r..
# _______ __
#
# TMP __.g.. TMP /tmp
# DICTIONARY __.p...j..? dictionary_m_words.txt
# u__.r...u..
# 'https://bites-data.s3.us-east-2.amazonaws.com/dictionary_... |
51d6368c8a9162ae4c13b7f6d07ee40bbe120e9b | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/Array/MergeSortedArray.py | 4,069 | 4.15625 | 4 | """
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Note:
The number of elements initialized in nums1 and nums2 are m and n respectively.
You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
Example:
I... |
6caab5b5e7ff9b156330d7302bf1567b16c8ea59 | syurskyi/Python_Topics | /125_algorithms/_examples/Python_Hand-on_Solve_200_Problems/Section 7 Dictionary/check_key_exist_solution.py | 816 | 4 | 4 | # To add a new cell, type '# %%'
# To add a new markdown cell, type '# %% [markdown]'
# %%
# ---------------------------------------------------------------
# python best courses https://courses.tanpham.org/
# ---------------------------------------------------------------
# Check if a given key already exists in a dic... |
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... |
c2821b1b84aa545178d219f8c8f21b7ab1aefd9d | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/intermediate/030_movie_data_analysis/save4_nopass.py | 1,812 | 3.6875 | 4 | import csv
from collections import defaultdict, namedtuple
import os
from u__.r.. import u..
BASE_URL = 'https://bites-data.s3.us-east-2.amazonaws.com/'
TMP = '/tmp'
fname = 'movie_metadata.csv'
remote = os.path.join(BASE_URL, fname)
local = os.path.join(TMP, fname)
u..(remote, local)
MOVIE_DATA = local
MIN_MOVIES =... |
8135e47c83f7b497b5b96684ea6dbf1328eddc6f | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/100_Python_Exercises_Evaluate_and_Improve_Your_Skills/Exercise 98 - Desktop GUI.py | 806 | 4.03125 | 4 | # #Create a program that asks the user to submit text through a GUI
#
# ____ tkinter ______ *
#
# window _ Tk()
#
# file _ o..("user_gui.txt", "a+")
#
# ___ add
# file.w..(user_value.g..() + "\n")
# entry.delete(0, END)
#
# ___ save
# global file
# file.c..
# file _ o..("user_gui.txt", "a+")
#
# ___... |
d30db8111d0afde19ad5f64be9cfeb27beb7393e | syurskyi/Python_Topics | /010_strings/examples/Learning Python/005_Basic Operations.py | 929 | 4.09375 | 4 | print('#' * 52 + ' Length: number of items')
print(len('abc')) # Length: number of items
print('#' * 52 + ' Concatenation: a new string')
print('abc' + 'def') # Concatenation: a new string
print('#' * 52 + ' Repetition: like "Ni!" + "Ni!" + ...')
print('Ni!' * 4) # Repetition: like "Ni!" + "Ni!" + ...
print('#' *... |
c290512c87d484d91c2e31f4bf02a5a0578629c3 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/100_python_Best_practices_for_absolute_beginers/Project+18 How to convert from base 2 to 9.py | 223 | 3.890625 | 4 | num1 i..(input("Insert number to convert: "))
base_num i..(input("Choose the base(2-9): "))
__ n..(2< base_num <9):
quit()
num2 ''
w___ num1>0:
num2 s..(num1%base_num) + num2
num1 // base_num
print(num2) |
b0492ca55a573aa06a266384bafc66cc425fc948 | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/pybites/advanced/63/traffic.py | 782 | 3.828125 | 4 | from collections import namedtuple
from itertools import cycle, islice
from time import sleep
State = namedtuple('State', 'color command timeout')
def traffic_light():
"""Returns an itertools.cycle iterator that
when iterated over returns State namedtuples
as shown in the Bite's description"""
... |
9c9a0bf6f5564a308d1ef43be06858a3bd0380b9 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/346_Moving_Average_from_Data_Stream.py | 788 | 3.703125 | 4 | c_ MovingAverage o..
___ - size
"""
Initialize your data structure here.
:type size: int
"""
size = size
curr_range = # list
___ next val
"""
:type val: int
:rtype: float
"""
__ l.. curr_range) __ size:
... |
9859f5948489eebbab89c8db62e707fd77f0d5fb | syurskyi/Python_Topics | /070_oop/001_classes/_exercises/_templates/Python_OOP_Object_Oriented_Programming/Section 17/Special-Methods-Code/9 - __bool__().py | 418 | 3.53125 | 4 | class SavingsAccount:
def __init__(self, owner, acc_number):
self.owner = owner
self._acc_number = acc_number
# The balance starts at 0
self.balance = 0
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
if self.balance - amount >... |
7acf2a5f96bd85fb45d1fb6ed4dc0f683f79eeaf | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/911 Online Election.py | 2,019 | 3.609375 | 4 | #!/usr/bin/python3
"""
In an election, the i-th vote was cast for persons[i] at time times[i].
Now, we would like to implement the following query function:
TopVotedCandidate.q(int t) will return the number of the person that was leading
the election at time t.
Votes cast at time t will count towards our query. In t... |
baa6b0b8905dfc9e832125196f3503f271557273 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/Array/SlidingWindowMaximum.py | 2,656 | 4.03125 | 4 | """
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.
Example:
Input: nums = [1,3,-1,-3,5,3,6,7], and k = 3
O... |
42623f87735e09a8941af14ec047671e235218ec | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/721 Accounts Merge.py | 3,528 | 4.59375 | 5 | #!/usr/bin/python3
"""
Given a list accounts, each element accounts[i] is a list of strings, where the
first element accounts[i][0] is a name, and the rest of the elements are emails
representing emails of the account.
Now, we would like to merge these accounts. Two accounts definitely belong to
the same person if the... |
d42ee9dfb7fbeb18b1efa91d44196ed24445d9dd | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/codeabbey/_Python_Problem_Solving-master/Triangle Area.py | 529 | 3.734375 | 4 | _______ m__
___ i __ r..(i..(i.. ))):
x1,y1,x2,y2,x3,y3 l.. m..(i..,i.. ).s..()))
#distance formula
a m__.sqrt((x2-x1)**2 + (y2-y1)**2)
b m__.sqrt((x3-x1)**2 + (y3-y1)**2)
c m__.sqrt((x3-x2)**2 + (y3-y2)**2)
#Heron's formula s = 1/2(a+b+c)
s 0.5 * (a + b + c)
s1= a..(s-a)
... |
a4491e5f9eec461e4263797ff2b83265f9a1e530 | syurskyi/Python_Topics | /070_oop/008_metaprogramming/examples/Interface/Implementing an Interface in Python/a_007_Using Abstract Method Declaration.py | 3,682 | 4.25 | 4 | # Using Abstract Method Declaration
# An abstract method is a method that's declared by the Python interface, but it may not have a useful implementation.
# The abstract method must be overridden by the concrete class that implements the interface in question.
#
# To create abstract methods in Python, you add the @abc.... |
39c485baf4869ac0756987e22ea9013dbfe661f3 | syurskyi/Python_Topics | /110_concurrency_parallelism/_examples/Gitlab/_qt/PYQT_QThread/Thread_Sync.py | 160 | 4 | 4 | def square_numbers(nums):
result = []
for i in nums:
result.append(i*i)
my_nums = square_numbers(1,2,3,4,5)
for num in my_nums:
print(num) |
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... |
61fa0a364f6a3dea96e0d5b9747203877d72f4f1 | syurskyi/Python_Topics | /115_testing/examples/The_Ultimate_Python_Unit_Testing_Course/Section 6 Coding Challenge #2 - Testing Classes/tests/test_chanllege.py | 1,981 | 3.5625 | 4 | import unittest
from challenge import Car
class EasyTestCase(unittest.TestCase):
def setUp(self):
self.car = Car()
self.car.start_car()
def test_easy_input(self):
self.car.add_speed()
self.car.add_speed()
self.car.add_speed()
self.car.add_speed()
self.... |
680e9aad720a7ad02ffe15251087b91ddf3889cd | syurskyi/Python_Topics | /125_algorithms/012_backtracking/_exercises/templates/Cracking Coding Interviews - Mastering Algorithms/permutations.py | 539 | 3.5625 | 4 | # ______ co..
# # Given a collection of distinct integers, return all possible permutations.
#
# # Example:
#
# # Input: [1,2,3]
# # Output:
# # [
# # [1,2,3],
# # [1,3,2],
# # [2,1,3],
# # [2,3,1],
# # [3,1,2],
# # [3,2,1]
# # ]
#
# ___ permutation_recursive nums path
# __ le. ? __ 0
# r_ |?
#
# output... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.