mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Modernize Python 2 code to get ready for Python 3
This commit is contained in:
parent
4e06949072
commit
e31c780d94
|
@ -85,7 +85,7 @@ def decode(ciphertext, key):
|
|||
plaintext = ""
|
||||
|
||||
# https://en.wikipedia.org/wiki/Playfair_cipher#Description
|
||||
for char1, char2 in chunk(ciphertext, 2):
|
||||
for char1, char2 in chunker(ciphertext, 2):
|
||||
row1, col1 = divmod(table.index(char1), 5)
|
||||
row2, col2 = divmod(table.index(char2), 5)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
'''
|
||||
A AVL tree
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Node:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import print_function
|
||||
|
||||
def printDist(dist, V):
|
||||
print("\nVertex Distance")
|
||||
for i in range(V):
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# Author: OMKAR PATHAK
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph():
|
||||
def __init__(self):
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# Author: OMKAR PATHAK
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph():
|
||||
def __init__(self):
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
|
||||
def printDist(dist, V):
|
||||
print("\nVertex Distance")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
|
||||
def printDist(dist, V):
|
||||
print("\nThe shortest path matrix using Floyd Warshall algorithm\n")
|
||||
|
@ -7,7 +8,7 @@ def printDist(dist, V):
|
|||
print(int(dist[i][j]),end = "\t")
|
||||
else:
|
||||
print("INF",end="\t")
|
||||
print();
|
||||
print()
|
||||
|
||||
|
||||
|
||||
|
@ -29,19 +30,19 @@ def FloydWarshall(graph, V):
|
|||
|
||||
|
||||
#MAIN
|
||||
V = int(input("Enter number of vertices: "));
|
||||
E = int(input("Enter number of edges: "));
|
||||
V = int(input("Enter number of vertices: "))
|
||||
E = int(input("Enter number of edges: "))
|
||||
|
||||
graph = [[float('inf') for i in range(V)] for j in range(V)]
|
||||
|
||||
for i in range(V):
|
||||
graph[i][i] = 0.0;
|
||||
graph[i][i] = 0.0
|
||||
|
||||
for i in range(E):
|
||||
print("\nEdge ",i+1)
|
||||
src = int(input("Enter source:"))
|
||||
dst = int(input("Enter destination:"))
|
||||
weight = float(input("Enter weight:"))
|
||||
graph[src][dst] = weight;
|
||||
graph[src][dst] = weight
|
||||
|
||||
FloydWarshall(graph, V)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph:
|
||||
def __init__(self, vertex):
|
||||
self.vertex = vertex
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph:
|
||||
|
||||
def __init__(self, vertex):
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# Author: Shubham Malik
|
||||
# References: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
|
||||
|
||||
from __future__ import print_function
|
||||
import math
|
||||
import sys
|
||||
# For storing the vertex set to retreive node with the lowest distance
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
- This is an example of a double ended, doubly linked list.
|
||||
- Each link references the next link and the previous one.
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class LinkedList:
|
||||
def __init__(self):
|
||||
self.head = None
|
||||
|
|
|
@ -7,6 +7,8 @@ This is a pure Python implementation of Dynamic Programming solution to the edit
|
|||
The problem is :
|
||||
Given two strings A and B. Find the minimum number of operations to string B such that A = B. The permitted operations are removal, insertion, and substitution.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class EditDistance:
|
||||
"""
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Fibonacci:
|
||||
|
|
|
@ -46,6 +46,7 @@ Usage:
|
|||
5. Have fun..
|
||||
|
||||
'''
|
||||
from __future__ import print_function
|
||||
from sklearn.metrics import pairwise_distances
|
||||
import numpy as np
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ def rmse(predict, actual):
|
|||
actual = np.array(actual)
|
||||
|
||||
difference = predict - actual
|
||||
square_diff = np.square(dfference)
|
||||
square_diff = np.square(difference)
|
||||
mean_square_diff = square_diff.mean()
|
||||
score = np.sqrt(mean_square_diff)
|
||||
return score
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
-The sieve of Eratosthenes is an algorithm used to find prime numbers, less than or equal to a given value.
|
||||
-Illustration: https://upload.wikimedia.org/wikipedia/commons/b/b9/Sieve_of_Eratosthenes_animation.gif
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
from math import sqrt
|
||||
def SOE(n):
|
||||
check = round(sqrt(n)) #Need not check for multiples past the square root of n
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# Code contributed by Honey Sharma
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
def cycle_sort(array):
|
||||
ans = 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user