From fd1c9b24942ab603f891dfd84c9a7156042ce445 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 5 Aug 2020 22:03:39 +0200 Subject: [PATCH 1/4] PIL.Image.point() takes an int, not a float @furkanatesli Trying to remove these warnings from our Travis CI build logs... https://travis-ci.com/github/TheAlgorithms/Python/builds/178602503#L809 --- digital_image_processing/change_brightness.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/change_brightness.py b/digital_image_processing/change_brightness.py index 97493f1a399e..96fb22c81a01 100644 --- a/digital_image_processing/change_brightness.py +++ b/digital_image_processing/change_brightness.py @@ -6,12 +6,12 @@ def change_brightness(img: Image, level: float) -> Image: Change the brightness of a PIL Image to a given level. """ - def brightness(c: int) -> float: + def brightness(c: int) -> int: """ Fundamental Transformation/Operation that'll be performed on every bit. """ - return 128 + level + (c - 128) + return int(128 + level + (c - 128)) if not -255.0 <= level <= 255.0: raise ValueError("level must be between -255.0 (black) and 255.0 (white)") From e47325cfd68534013a25ce58e78fc599e11e0ed1 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 5 Aug 2020 20:04:24 +0000 Subject: [PATCH 2/4] fixup! Format Python code with psf/black push --- graphs/karger.py | 35 +++++++++++++++----------- other/scoring_algorithm.py | 10 ++++---- web_programming/world_covid19_stats.py | 8 +++--- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/graphs/karger.py b/graphs/karger.py index d5a27c285fd4..589b8c733dde 100644 --- a/graphs/karger.py +++ b/graphs/karger.py @@ -5,20 +5,19 @@ import random from typing import Dict, List, Set, Tuple - # Adjacency list representation of this graph: # https://en.wikipedia.org/wiki/File:Single_run_of_Karger%E2%80%99s_Mincut_algorithm.svg TEST_GRAPH = { - '1': ['2', '3', '4', '5'], - '2': ['1', '3', '4', '5'], - '3': ['1', '2', '4', '5', '10'], - '4': ['1', '2', '3', '5', '6'], - '5': ['1', '2', '3', '4', '7'], - '6': ['7', '8', '9', '10', '4'], - '7': ['6', '8', '9', '10', '5'], - '8': ['6', '7', '9', '10'], - '9': ['6', '7', '8', '10'], - '10': ['6', '7', '8', '9', '3'] + "1": ["2", "3", "4", "5"], + "2": ["1", "3", "4", "5"], + "3": ["1", "2", "4", "5", "10"], + "4": ["1", "2", "3", "5", "6"], + "5": ["1", "2", "3", "4", "7"], + "6": ["7", "8", "9", "10", "4"], + "7": ["6", "8", "9", "10", "5"], + "8": ["6", "7", "9", "10"], + "9": ["6", "7", "8", "10"], + "10": ["6", "7", "8", "9", "3"], } @@ -61,8 +60,10 @@ def partition_graph(graph: Dict[str, List[str]]) -> Set[Tuple[str, str]]: for neighbor in uv_neighbors: graph_copy[neighbor].append(uv) - contracted_nodes[uv] = {contracted_node for contracted_node in - contracted_nodes[u].union(contracted_nodes[v])} + contracted_nodes[uv] = { + contracted_node + for contracted_node in contracted_nodes[u].union(contracted_nodes[v]) + } # Remove nodes u and v. del graph_copy[u] @@ -75,8 +76,12 @@ def partition_graph(graph: Dict[str, List[str]]) -> Set[Tuple[str, str]]: # Find cutset. groups = [contracted_nodes[node] for node in graph_copy] - return {(node, neighbor) for node in groups[0] - for neighbor in graph[node] if neighbor in groups[1]} + return { + (node, neighbor) + for node in groups[0] + for neighbor in graph[node] + if neighbor in groups[1] + } if __name__ == "__main__": diff --git a/other/scoring_algorithm.py b/other/scoring_algorithm.py index a5d073d5e8d8..77e614e2622c 100644 --- a/other/scoring_algorithm.py +++ b/other/scoring_algorithm.py @@ -1,4 +1,4 @@ -''' +""" developed by: markmelnic original repo: https://github.com/markmelnic/Scoring-Algorithm @@ -23,17 +23,17 @@ >>> procentual_proximity([[20, 60, 2012],[23, 90, 2015],[22, 50, 2011]], [0, 0, 1]) [[20, 60, 2012, 2.0], [23, 90, 2015, 1.0], [22, 50, 2011, 1.3333333333333335]] -''' +""" -def procentual_proximity(source_data : list, weights : list) -> list: +def procentual_proximity(source_data: list, weights: list) -> list: - ''' + """ weights - int list possible values - 0 / 1 0 if lower values have higher weight in the data set 1 if higher values have higher weight in the data set - ''' + """ # getting data data_lists = [] diff --git a/web_programming/world_covid19_stats.py b/web_programming/world_covid19_stats.py index 1907ed5f35f7..1dd1ff6d188e 100644 --- a/web_programming/world_covid19_stats.py +++ b/web_programming/world_covid19_stats.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 -''' +""" Provide the current worldwide COVID-19 statistics. This data is being scrapped from 'https://www.worldometers.info/coronavirus/'. -''' +""" import requests from bs4 import BeautifulSoup @@ -13,8 +13,8 @@ def world_covid19_stats(url: str = "https://www.worldometers.info/coronavirus") """ Return a dict of current worldwide COVID-19 statistics """ - soup = BeautifulSoup(requests.get(url).text, 'html.parser') - keys = soup.findAll('h1') + soup = BeautifulSoup(requests.get(url).text, "html.parser") + keys = soup.findAll("h1") values = soup.findAll("div", {"class": "maincounter-number"}) keys += soup.findAll("span", {"class": "panel-title"}) values += soup.findAll("div", {"class": "number-table-main"}) From 258fa4415d68f31c9ee6a813a0d1b7dbc402fd94 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 5 Aug 2020 22:16:54 +0200 Subject: [PATCH 3/4] Revert changes to change_brightness.py --- digital_image_processing/change_brightness.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/change_brightness.py b/digital_image_processing/change_brightness.py index 96fb22c81a01..97493f1a399e 100644 --- a/digital_image_processing/change_brightness.py +++ b/digital_image_processing/change_brightness.py @@ -6,12 +6,12 @@ def change_brightness(img: Image, level: float) -> Image: Change the brightness of a PIL Image to a given level. """ - def brightness(c: int) -> int: + def brightness(c: int) -> float: """ Fundamental Transformation/Operation that'll be performed on every bit. """ - return int(128 + level + (c - 128)) + return 128 + level + (c - 128) if not -255.0 <= level <= 255.0: raise ValueError("level must be between -255.0 (black) and 255.0 (white)") From 9207b3a769e4588783bdc5350d071668e794c51e Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 5 Aug 2020 20:17:19 +0000 Subject: [PATCH 4/4] updating DIRECTORY.md --- DIRECTORY.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index fb8312c635f8..1dd3b3ade844 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -85,7 +85,9 @@ * [Decimal To Binary](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_binary.py) * [Decimal To Hexadecimal](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_hexadecimal.py) * [Decimal To Octal](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_octal.py) + * [Prefix Conversions](https://github.com/TheAlgorithms/Python/blob/master/conversions/prefix_conversions.py) * [Roman To Integer](https://github.com/TheAlgorithms/Python/blob/master/conversions/roman_to_integer.py) + * [Temperature Conversions](https://github.com/TheAlgorithms/Python/blob/master/conversions/temperature_conversions.py) ## Data Structures * Binary Tree @@ -102,9 +104,6 @@ * [Segment Tree](https://github.com/TheAlgorithms/Python/blob/master/data_structures/binary_tree/segment_tree.py) * [Segment Tree Other](https://github.com/TheAlgorithms/Python/blob/master/data_structures/binary_tree/segment_tree_other.py) * [Treap](https://github.com/TheAlgorithms/Python/blob/master/data_structures/binary_tree/treap.py) - * Data Structures - * Heap - * [Heap Generic](https://github.com/TheAlgorithms/Python/blob/master/data_structures/data_structures/heap/heap_generic.py) * Disjoint Set * [Disjoint Set](https://github.com/TheAlgorithms/Python/blob/master/data_structures/disjoint_set/disjoint_set.py) * Hashing @@ -117,6 +116,7 @@ * Heap * [Binomial Heap](https://github.com/TheAlgorithms/Python/blob/master/data_structures/heap/binomial_heap.py) * [Heap](https://github.com/TheAlgorithms/Python/blob/master/data_structures/heap/heap.py) + * [Heap Generic](https://github.com/TheAlgorithms/Python/blob/master/data_structures/heap/heap_generic.py) * [Max Heap](https://github.com/TheAlgorithms/Python/blob/master/data_structures/heap/max_heap.py) * [Min Heap](https://github.com/TheAlgorithms/Python/blob/master/data_structures/heap/min_heap.py) * Linked List @@ -264,6 +264,7 @@ * [Greedy Best First](https://github.com/TheAlgorithms/Python/blob/master/graphs/greedy_best_first.py) * [Kahns Algorithm Long](https://github.com/TheAlgorithms/Python/blob/master/graphs/kahns_algorithm_long.py) * [Kahns Algorithm Topo](https://github.com/TheAlgorithms/Python/blob/master/graphs/kahns_algorithm_topo.py) + * [Karger](https://github.com/TheAlgorithms/Python/blob/master/graphs/karger.py) * [Minimum Spanning Tree Boruvka](https://github.com/TheAlgorithms/Python/blob/master/graphs/minimum_spanning_tree_boruvka.py) * [Minimum Spanning Tree Kruskal](https://github.com/TheAlgorithms/Python/blob/master/graphs/minimum_spanning_tree_kruskal.py) * [Minimum Spanning Tree Prims](https://github.com/TheAlgorithms/Python/blob/master/graphs/minimum_spanning_tree_prims.py) @@ -292,6 +293,7 @@ * Src * [Lib](https://github.com/TheAlgorithms/Python/blob/master/linear_algebra/src/lib.py) * [Polynom-For-Points](https://github.com/TheAlgorithms/Python/blob/master/linear_algebra/src/polynom-for-points.py) + * [Power Iteration](https://github.com/TheAlgorithms/Python/blob/master/linear_algebra/src/power_iteration.py) * [Rayleigh Quotient](https://github.com/TheAlgorithms/Python/blob/master/linear_algebra/src/rayleigh_quotient.py) * [Test Linear Algebra](https://github.com/TheAlgorithms/Python/blob/master/linear_algebra/src/test_linear_algebra.py) @@ -337,6 +339,7 @@ * [Binary Exp Mod](https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exp_mod.py) * [Binary Exponentiation](https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exponentiation.py) * [Binomial Coefficient](https://github.com/TheAlgorithms/Python/blob/master/maths/binomial_coefficient.py) + * [Binomial Distribution](https://github.com/TheAlgorithms/Python/blob/master/maths/binomial_distribution.py) * [Bisection](https://github.com/TheAlgorithms/Python/blob/master/maths/bisection.py) * [Ceil](https://github.com/TheAlgorithms/Python/blob/master/maths/ceil.py) * [Chudnovsky Algorithm](https://github.com/TheAlgorithms/Python/blob/master/maths/chudnovsky_algorithm.py) @@ -366,6 +369,7 @@ * [Jaccard Similarity](https://github.com/TheAlgorithms/Python/blob/master/maths/jaccard_similarity.py) * [Kadanes](https://github.com/TheAlgorithms/Python/blob/master/maths/kadanes.py) * [Karatsuba](https://github.com/TheAlgorithms/Python/blob/master/maths/karatsuba.py) + * [Krishnamurthy Number](https://github.com/TheAlgorithms/Python/blob/master/maths/krishnamurthy_number.py) * [Kth Lexicographic Permutation](https://github.com/TheAlgorithms/Python/blob/master/maths/kth_lexicographic_permutation.py) * [Largest Of Very Large Numbers](https://github.com/TheAlgorithms/Python/blob/master/maths/largest_of_very_large_numbers.py) * [Least Common Multiple](https://github.com/TheAlgorithms/Python/blob/master/maths/least_common_multiple.py) @@ -382,9 +386,11 @@ * [Number Of Digits](https://github.com/TheAlgorithms/Python/blob/master/maths/number_of_digits.py) * [Numerical Integration](https://github.com/TheAlgorithms/Python/blob/master/maths/numerical_integration.py) * [Perfect Cube](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_cube.py) + * [Perfect Number](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_number.py) * [Perfect Square](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_square.py) * [Pi Monte Carlo Estimation](https://github.com/TheAlgorithms/Python/blob/master/maths/pi_monte_carlo_estimation.py) * [Polynomial Evaluation](https://github.com/TheAlgorithms/Python/blob/master/maths/polynomial_evaluation.py) + * [Power Using Recursion](https://github.com/TheAlgorithms/Python/blob/master/maths/power_using_recursion.py) * [Prime Check](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_check.py) * [Prime Factors](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_factors.py) * [Prime Numbers](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_numbers.py) @@ -415,6 +421,7 @@ ## Matrix * [Count Islands In Matrix](https://github.com/TheAlgorithms/Python/blob/master/matrix/count_islands_in_matrix.py) + * [Inverse Of Matrix](https://github.com/TheAlgorithms/Python/blob/master/matrix/inverse_of_matrix.py) * [Matrix Class](https://github.com/TheAlgorithms/Python/blob/master/matrix/matrix_class.py) * [Matrix Operation](https://github.com/TheAlgorithms/Python/blob/master/matrix/matrix_operation.py) * [Nth Fibonacci Using Matrix Exponentiation](https://github.com/TheAlgorithms/Python/blob/master/matrix/nth_fibonacci_using_matrix_exponentiation.py) @@ -460,6 +467,7 @@ * [Palindrome](https://github.com/TheAlgorithms/Python/blob/master/other/palindrome.py) * [Password Generator](https://github.com/TheAlgorithms/Python/blob/master/other/password_generator.py) * [Primelib](https://github.com/TheAlgorithms/Python/blob/master/other/primelib.py) + * [Scoring Algorithm](https://github.com/TheAlgorithms/Python/blob/master/other/scoring_algorithm.py) * [Sdes](https://github.com/TheAlgorithms/Python/blob/master/other/sdes.py) * [Sierpinski Triangle](https://github.com/TheAlgorithms/Python/blob/master/other/sierpinski_triangle.py) * [Tower Of Hanoi](https://github.com/TheAlgorithms/Python/blob/master/other/tower_of_hanoi.py) @@ -633,6 +641,7 @@ * [I Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/i_sort.py) * [Insertion Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py) * [Iterative Merge Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/iterative_merge_sort.py) + * [Merge Insertion Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_insertion_sort.py) * [Merge Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py) * [Odd Even Transposition Parallel](https://github.com/TheAlgorithms/Python/blob/master/sorts/odd_even_transposition_parallel.py) * [Odd Even Transposition Single Threaded](https://github.com/TheAlgorithms/Python/blob/master/sorts/odd_even_transposition_single_threaded.py) @@ -693,3 +702,4 @@ * [Get Imdb Top 250 Movies Csv](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdb_top_250_movies_csv.py) * [Get Imdbtop](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdbtop.py) * [Slack Message](https://github.com/TheAlgorithms/Python/blob/master/web_programming/slack_message.py) + * [World Covid19 Stats](https://github.com/TheAlgorithms/Python/blob/master/web_programming/world_covid19_stats.py)