From 0856a6185998f664d48904a1bfd5a53f9b8aa4a8 Mon Sep 17 00:00:00 2001 From: ParthS007 Date: Thu, 18 Oct 2018 02:58:57 +0530 Subject: [PATCH] Remove Multiple Unused Imports and Variable --- .gitignore | 1 + .vscode/settings.json | 3 -- ArithmeticAnalysis/LUdecomposition.py | 6 ++-- ArithmeticAnalysis/NewtonRaphsonMethod.py | 4 +-- .../Multi_Hueristic_Astar.py | 2 -- Graphs/basic-graphs.py | 2 +- Project Euler/Problem 09/sol2.py | 1 - Project Euler/Problem 15/sol1.py | 2 +- ciphers/affine_cipher.py | 4 +-- .../LinkedList/DoublyLinkedList.py | 4 +-- data_structures/LinkedList/__init__.py | 2 +- .../LinkedList/singly_LinkedList.py | 1 + .../k_means_clustering_tensorflow.py | 2 +- machine_learning/linear_regression.py | 1 - other/game_of_life/game_o_life.py | 3 +- other/primelib.py | 7 ++--- searches/interpolation_search.py | 1 - searches/quick_select.py | 31 +++++++++---------- sorts/external-sort.py | 1 - sorts/random_normaldistribution_quicksort.py | 1 - sorts/tree_sort.py | 4 +-- strings/min-cost-string-conversion.py | 1 - 22 files changed, 34 insertions(+), 50 deletions(-) delete mode 100644 .vscode/settings.json rename Multi_Hueristic_Astar.py => Graphs/Multi_Hueristic_Astar.py (99%) diff --git a/.gitignore b/.gitignore index 96422cb2e..5f9132236 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ __pycache__/ *.so # Distribution / packaging +.vscode/ .Python env/ build/ diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 615aafb03..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "/usr/bin/python3" -} \ No newline at end of file diff --git a/ArithmeticAnalysis/LUdecomposition.py b/ArithmeticAnalysis/LUdecomposition.py index bb0827bb3..da05fb65d 100644 --- a/ArithmeticAnalysis/LUdecomposition.py +++ b/ArithmeticAnalysis/LUdecomposition.py @@ -1,7 +1,7 @@ -import math import numpy -def LUDecompose (table): #table that contains our data +def LUDecompose (table): + #table that contains our data #table has to be a square array so we need to check first rows,columns=numpy.shape(table) L=numpy.zeros((rows,columns)) @@ -31,4 +31,4 @@ def LUDecompose (table): #table that contains our data matrix =numpy.array([[2,-2,1],[0,1,2],[5,3,1]]) L,U = LUDecompose(matrix) print(L) -print(U) \ No newline at end of file +print(U) diff --git a/ArithmeticAnalysis/NewtonRaphsonMethod.py b/ArithmeticAnalysis/NewtonRaphsonMethod.py index e7abb64e7..5e7e2f930 100644 --- a/ArithmeticAnalysis/NewtonRaphsonMethod.py +++ b/ArithmeticAnalysis/NewtonRaphsonMethod.py @@ -3,16 +3,14 @@ from sympy import diff from decimal import Decimal -from math import sin, cos, exp def NewtonRaphson(func, a): ''' Finds root from the point 'a' onwards by Newton-Raphson method ''' while True: - x = a c = Decimal(a) - ( Decimal(eval(func)) / Decimal(eval(str(diff(func)))) ) - x = c a = c + # This number dictates the accuracy of the answer if abs(eval(func)) < 10**-15: return c diff --git a/Multi_Hueristic_Astar.py b/Graphs/Multi_Hueristic_Astar.py similarity index 99% rename from Multi_Hueristic_Astar.py rename to Graphs/Multi_Hueristic_Astar.py index 7fbd2ff04..1acd098f3 100644 --- a/Multi_Hueristic_Astar.py +++ b/Graphs/Multi_Hueristic_Astar.py @@ -1,8 +1,6 @@ from __future__ import print_function import heapq import numpy as np -import math -import copy try: xrange # Python 2 diff --git a/Graphs/basic-graphs.py b/Graphs/basic-graphs.py index 6e433b5bd..28fa3d180 100644 --- a/Graphs/basic-graphs.py +++ b/Graphs/basic-graphs.py @@ -140,7 +140,7 @@ from collections import deque def topo(G, ind=None, Q=[1]): - if ind == None: + if ind is None: ind = [0] * (len(G) + 1) # SInce oth Index is ignored for u in G: for v in G[u]: diff --git a/Project Euler/Problem 09/sol2.py b/Project Euler/Problem 09/sol2.py index 13674d258..933f5c557 100644 --- a/Project Euler/Problem 09/sol2.py +++ b/Project Euler/Problem 09/sol2.py @@ -3,7 +3,6 @@ a^2+b^2=c^2 Given N, Check if there exists any Pythagorean triplet for which a+b+c=N Find maximum possible value of product of a,b,c among all such Pythagorean triplets, If there is no such Pythagorean triplet print -1.""" #!/bin/python3 -import sys product=-1 d=0 diff --git a/Project Euler/Problem 15/sol1.py b/Project Euler/Problem 15/sol1.py index 9b61b37d2..d24748011 100644 --- a/Project Euler/Problem 15/sol1.py +++ b/Project Euler/Problem 15/sol1.py @@ -1,5 +1,5 @@ from __future__ import print_function -from math import factorial, ceil +from math import factorial def lattice_paths(n): n = 2*n #middle entry of odd rows starting at row 3 is the solution for n = 1, 2, 3,... diff --git a/ciphers/affine_cipher.py b/ciphers/affine_cipher.py index 6c1ba06f6..4fbe87d42 100644 --- a/ciphers/affine_cipher.py +++ b/ciphers/affine_cipher.py @@ -68,8 +68,8 @@ def getRandomKey(): while True: keyA = random.randint(2, len(SYMBOLS)) keyB = random.randint(2, len(SYMBOLS)) - if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1: - return keyA * len(SYMBOLS) + keyB + if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1: + return keyA * len(SYMBOLS) + keyB if __name__ == '__main__': import doctest diff --git a/data_structures/LinkedList/DoublyLinkedList.py b/data_structures/LinkedList/DoublyLinkedList.py index 6f17b7c81..18eb63fea 100644 --- a/data_structures/LinkedList/DoublyLinkedList.py +++ b/data_structures/LinkedList/DoublyLinkedList.py @@ -24,7 +24,7 @@ class LinkedList: temp = self.head self.head = self.head.next # oldHead <--> 2ndElement(head) self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed - if(self.head == None): + if(self.head is None): self.tail = None return temp @@ -58,7 +58,7 @@ class LinkedList: current.next.previous = current.previous # 1 <--> 3 def isEmpty(self): #Will return True if the list is empty - return(self.head == None) + return(self.head is None) def display(self): #Prints contents of the list current = self.head diff --git a/data_structures/LinkedList/__init__.py b/data_structures/LinkedList/__init__.py index 1d220599f..6d50f23c1 100644 --- a/data_structures/LinkedList/__init__.py +++ b/data_structures/LinkedList/__init__.py @@ -19,4 +19,4 @@ class LinkedList: return item def is_empty(self): - return self.head == None + return self.head is None diff --git a/data_structures/LinkedList/singly_LinkedList.py b/data_structures/LinkedList/singly_LinkedList.py index eb7f48f17..0d6157e3e 100644 --- a/data_structures/LinkedList/singly_LinkedList.py +++ b/data_structures/LinkedList/singly_LinkedList.py @@ -67,3 +67,4 @@ class Linked_List: current = next_node # Return prev in order to put the head at the end Head = prev + return Head diff --git a/dynamic_programming/k_means_clustering_tensorflow.py b/dynamic_programming/k_means_clustering_tensorflow.py index ad495c71a..b6813c6a2 100644 --- a/dynamic_programming/k_means_clustering_tensorflow.py +++ b/dynamic_programming/k_means_clustering_tensorflow.py @@ -1,5 +1,5 @@ import tensorflow as tf -from random import choice, shuffle +from random import shuffle from numpy import array diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index eb1f019c5..8c23f1f77 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -59,7 +59,6 @@ def sum_of_square_error(data_x, data_y, len_data, theta): :param theta : contains the feature vector :return : sum of square error computed from given feature's """ - error = 0.0 prod = np.dot(theta, data_x.transpose()) prod -= data_y.transpose() sum_elem = np.sum(np.square(prod)) diff --git a/other/game_of_life/game_o_life.py b/other/game_of_life/game_o_life.py index 32ebe0fc1..1fdaa21b4 100644 --- a/other/game_of_life/game_o_life.py +++ b/other/game_of_life/game_o_life.py @@ -28,9 +28,8 @@ Game-Of-Life Rules: comes a live cell, as if by reproduction. ''' import numpy as np -import random, time, sys +import random, sys from matplotlib import pyplot as plt -import matplotlib.animation as animation from matplotlib.colors import ListedColormap usage_doc='Usage of script: script_nama ' diff --git a/other/primelib.py b/other/primelib.py index 16c44a093..19572f861 100644 --- a/other/primelib.py +++ b/other/primelib.py @@ -290,7 +290,7 @@ def goldbach(number): while (i < lenPN and loop): - j = i+1; + j = i+1 while (j < lenPN and loop): @@ -300,9 +300,8 @@ def goldbach(number): ans.append(primeNumbers[i]) ans.append(primeNumbers[j]) - j += 1; - - + j += 1 + i += 1 # precondition diff --git a/searches/interpolation_search.py b/searches/interpolation_search.py index 7b765c454..db9893bdb 100644 --- a/searches/interpolation_search.py +++ b/searches/interpolation_search.py @@ -2,7 +2,6 @@ This is pure python implementation of interpolation search algorithm """ from __future__ import print_function -import bisect try: raw_input # Python 2 diff --git a/searches/quick_select.py b/searches/quick_select.py index e5e2ce99c..1596cf040 100644 --- a/searches/quick_select.py +++ b/searches/quick_select.py @@ -1,8 +1,5 @@ -import collections -import sys import random -import time -import math + """ A python implementation of the quick select algorithm, which is efficient for calculating the value that would appear in the index of a list if it would be sorted, even if it is not already sorted https://en.wikipedia.org/wiki/Quickselect @@ -25,23 +22,23 @@ def _partition(data, pivot): equal.append(element) return less, equal, greater - def quickSelect(list, k): +def quickSelect(list, k): #k = len(list) // 2 when trying to find the median (index that value would be when list is sorted) - smaller = [] - larger = [] - pivot = random.randint(0, len(list) - 1) - pivot = list[pivot] - count = 0 - smaller, equal, larger =_partition(list, pivot) - count = len(equal) - m = len(smaller) + smaller = [] + larger = [] + pivot = random.randint(0, len(list) - 1) + pivot = list[pivot] + count = 0 + smaller, equal, larger =_partition(list, pivot) + count = len(equal) + m = len(smaller) - #k is the pivot - if m <= k < m + count: + #k is the pivot + if m <= k < m + count: return pivot # must be in smaller - elif m > k: + elif m > k: return quickSelect(smaller, k) #must be in larger - else: + else: return quickSelect(larger, k - (m + count)) diff --git a/sorts/external-sort.py b/sorts/external-sort.py index 6c4adc94c..dece32d48 100644 --- a/sorts/external-sort.py +++ b/sorts/external-sort.py @@ -4,7 +4,6 @@ # Sort large text files in a minimum amount of memory # import os -import sys import argparse class FileSplitter(object): diff --git a/sorts/random_normaldistribution_quicksort.py b/sorts/random_normaldistribution_quicksort.py index bd730b3b1..dfa37da61 100644 --- a/sorts/random_normaldistribution_quicksort.py +++ b/sorts/random_normaldistribution_quicksort.py @@ -2,7 +2,6 @@ from __future__ import print_function from random import randint from tempfile import TemporaryFile import numpy as np -import math diff --git a/sorts/tree_sort.py b/sorts/tree_sort.py index 94cf68033..f8ecf84c6 100644 --- a/sorts/tree_sort.py +++ b/sorts/tree_sort.py @@ -11,12 +11,12 @@ class node(): def insert(self,val): if self.val: if val < self.val: - if self.left == None: + if self.left is None: self.left = node(val) else: self.left.insert(val) elif val > self.val: - if self.right == None: + if self.right is None: self.right = node(val) else: self.right.insert(val) diff --git a/strings/min-cost-string-conversion.py b/strings/min-cost-string-conversion.py index 7e3298137..c233af1c8 100644 --- a/strings/min-cost-string-conversion.py +++ b/strings/min-cost-string-conversion.py @@ -68,7 +68,6 @@ def assemble_transformation(ops, i, j): return seq if __name__ == '__main__': - from time import sleep _, operations = compute_transform_tables('Python', 'Algorithms', -1, 1, 2, 2) m = len(operations)