Skip to content

Commit fedb3e7

Browse files
authored
Merge pull request TheAlgorithms#477 from ParthS007/patch1
Fixes#476 : Remove Multiple Unused Imports and Variable
2 parents 765a326 + 0856a61 commit fedb3e7

22 files changed

+34
-50
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __pycache__/
77
*.so
88

99
# Distribution / packaging
10+
.vscode/
1011
.Python
1112
env/
1213
build/

.vscode/settings.json

-3
This file was deleted.

ArithmeticAnalysis/LUdecomposition.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import math
21
import numpy
32

4-
def LUDecompose (table): #table that contains our data
3+
def LUDecompose (table):
4+
#table that contains our data
55
#table has to be a square array so we need to check first
66
rows,columns=numpy.shape(table)
77
L=numpy.zeros((rows,columns))
@@ -31,4 +31,4 @@ def LUDecompose (table): #table that contains our data
3131
matrix =numpy.array([[2,-2,1],[0,1,2],[5,3,1]])
3232
L,U = LUDecompose(matrix)
3333
print(L)
34-
print(U)
34+
print(U)

ArithmeticAnalysis/NewtonRaphsonMethod.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33

44
from sympy import diff
55
from decimal import Decimal
6-
from math import sin, cos, exp
76

87
def NewtonRaphson(func, a):
98
''' Finds root from the point 'a' onwards by Newton-Raphson method '''
109
while True:
11-
x = a
1210
c = Decimal(a) - ( Decimal(eval(func)) / Decimal(eval(str(diff(func)))) )
1311

14-
x = c
1512
a = c
13+
1614
# This number dictates the accuracy of the answer
1715
if abs(eval(func)) < 10**-15:
1816
return c

Multi_Hueristic_Astar.py Graphs/Multi_Hueristic_Astar.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import print_function
22
import heapq
33
import numpy as np
4-
import math
5-
import copy
64

75
try:
86
xrange # Python 2

Graphs/basic-graphs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def dijk(G, s):
140140

141141

142142
def topo(G, ind=None, Q=[1]):
143-
if ind == None:
143+
if ind is None:
144144
ind = [0] * (len(G) + 1) # SInce oth Index is ignored
145145
for u in G:
146146
for v in G[u]:

Project Euler/Problem 09/sol2.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Given N, Check if there exists any Pythagorean triplet for which a+b+c=N
44
Find maximum possible value of product of a,b,c among all such Pythagorean triplets, If there is no such Pythagorean triplet print -1."""
55
#!/bin/python3
6-
import sys
76

87
product=-1
98
d=0

Project Euler/Problem 15/sol1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import print_function
2-
from math import factorial, ceil
2+
from math import factorial
33

44
def lattice_paths(n):
55
n = 2*n #middle entry of odd rows starting at row 3 is the solution for n = 1, 2, 3,...

ciphers/affine_cipher.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def getRandomKey():
6868
while True:
6969
keyA = random.randint(2, len(SYMBOLS))
7070
keyB = random.randint(2, len(SYMBOLS))
71-
if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1:
72-
return keyA * len(SYMBOLS) + keyB
71+
if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1:
72+
return keyA * len(SYMBOLS) + keyB
7373

7474
if __name__ == '__main__':
7575
import doctest

data_structures/LinkedList/DoublyLinkedList.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def deleteHead(self):
2424
temp = self.head
2525
self.head = self.head.next # oldHead <--> 2ndElement(head)
2626
self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
27-
if(self.head == None):
27+
if(self.head is None):
2828
self.tail = None
2929
return temp
3030

@@ -58,7 +58,7 @@ def delete(self, x):
5858
current.next.previous = current.previous # 1 <--> 3
5959

6060
def isEmpty(self): #Will return True if the list is empty
61-
return(self.head == None)
61+
return(self.head is None)
6262

6363
def display(self): #Prints contents of the list
6464
current = self.head

data_structures/LinkedList/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def remove(self):
1919
return item
2020

2121
def is_empty(self):
22-
return self.head == None
22+
return self.head is None

data_structures/LinkedList/singly_LinkedList.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ def reverse(Head):
6767
current = next_node
6868
# Return prev in order to put the head at the end
6969
Head = prev
70+
return Head

dynamic_programming/k_means_clustering_tensorflow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tensorflow as tf
2-
from random import choice, shuffle
2+
from random import shuffle
33
from numpy import array
44

55

machine_learning/linear_regression.py

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def sum_of_square_error(data_x, data_y, len_data, theta):
5959
:param theta : contains the feature vector
6060
:return : sum of square error computed from given feature's
6161
"""
62-
error = 0.0
6362
prod = np.dot(theta, data_x.transpose())
6463
prod -= data_y.transpose()
6564
sum_elem = np.sum(np.square(prod))

other/game_of_life/game_o_life.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
comes a live cell, as if by reproduction.
2929
'''
3030
import numpy as np
31-
import random, time, sys
31+
import random, sys
3232
from matplotlib import pyplot as plt
33-
import matplotlib.animation as animation
3433
from matplotlib.colors import ListedColormap
3534

3635
usage_doc='Usage of script: script_nama <size_of_canvas:int>'

other/primelib.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def goldbach(number):
290290

291291
while (i < lenPN and loop):
292292

293-
j = i+1;
293+
j = i+1
294294

295295

296296
while (j < lenPN and loop):
@@ -300,9 +300,8 @@ def goldbach(number):
300300
ans.append(primeNumbers[i])
301301
ans.append(primeNumbers[j])
302302

303-
j += 1;
304-
305-
303+
j += 1
304+
306305
i += 1
307306

308307
# precondition

searches/interpolation_search.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
This is pure python implementation of interpolation search algorithm
33
"""
44
from __future__ import print_function
5-
import bisect
65

76
try:
87
raw_input # Python 2

searches/quick_select.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import collections
2-
import sys
31
import random
4-
import time
5-
import math
2+
63
"""
74
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
85
https://en.wikipedia.org/wiki/Quickselect
@@ -25,23 +22,23 @@ def _partition(data, pivot):
2522
equal.append(element)
2623
return less, equal, greater
2724

28-
def quickSelect(list, k):
25+
def quickSelect(list, k):
2926
#k = len(list) // 2 when trying to find the median (index that value would be when list is sorted)
30-
smaller = []
31-
larger = []
32-
pivot = random.randint(0, len(list) - 1)
33-
pivot = list[pivot]
34-
count = 0
35-
smaller, equal, larger =_partition(list, pivot)
36-
count = len(equal)
37-
m = len(smaller)
27+
smaller = []
28+
larger = []
29+
pivot = random.randint(0, len(list) - 1)
30+
pivot = list[pivot]
31+
count = 0
32+
smaller, equal, larger =_partition(list, pivot)
33+
count = len(equal)
34+
m = len(smaller)
3835

39-
#k is the pivot
40-
if m <= k < m + count:
36+
#k is the pivot
37+
if m <= k < m + count:
4138
return pivot
4239
# must be in smaller
43-
elif m > k:
40+
elif m > k:
4441
return quickSelect(smaller, k)
4542
#must be in larger
46-
else:
43+
else:
4744
return quickSelect(larger, k - (m + count))

sorts/external-sort.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Sort large text files in a minimum amount of memory
55
#
66
import os
7-
import sys
87
import argparse
98

109
class FileSplitter(object):

sorts/random_normaldistribution_quicksort.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from random import randint
33
from tempfile import TemporaryFile
44
import numpy as np
5-
import math
65

76

87

sorts/tree_sort.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def __init__(self, val):
1111
def insert(self,val):
1212
if self.val:
1313
if val < self.val:
14-
if self.left == None:
14+
if self.left is None:
1515
self.left = node(val)
1616
else:
1717
self.left.insert(val)
1818
elif val > self.val:
19-
if self.right == None:
19+
if self.right is None:
2020
self.right = node(val)
2121
else:
2222
self.right.insert(val)

strings/min-cost-string-conversion.py

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def assemble_transformation(ops, i, j):
6868
return seq
6969

7070
if __name__ == '__main__':
71-
from time import sleep
7271
_, operations = compute_transform_tables('Python', 'Algorithms', -1, 1, 2, 2)
7372

7473
m = len(operations)

0 commit comments

Comments
 (0)