mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Simplify code by dropping support for legacy Python (#1143)
* Simplify code by dropping support for legacy Python * sort() --> sorted()
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
import collections, pprint, time, os
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
# https://en.wikipedia.org/wiki/Euclidean_algorithm
|
||||
|
||||
def euclidean_gcd(a, b):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
__author__ = "Tobias Carryer"
|
||||
|
||||
from time import time
|
||||
@@ -7,11 +6,11 @@ class LinearCongruentialGenerator(object):
|
||||
"""
|
||||
A pseudorandom number generator.
|
||||
"""
|
||||
|
||||
|
||||
def __init__( self, multiplier, increment, modulo, seed=int(time()) ):
|
||||
"""
|
||||
These parameters are saved and used when nextNumber() is called.
|
||||
|
||||
|
||||
modulo is the largest number that can be generated (exclusive). The most
|
||||
efficent values are powers of 2. 2^32 is a common value.
|
||||
"""
|
||||
@@ -19,7 +18,7 @@ class LinearCongruentialGenerator(object):
|
||||
self.increment = increment
|
||||
self.modulo = modulo
|
||||
self.seed = seed
|
||||
|
||||
|
||||
def next_number( self ):
|
||||
"""
|
||||
The smallest number that can be generated is zero.
|
||||
|
||||
@@ -13,9 +13,6 @@ The function called is_balanced takes as input a string S which is a sequence of
|
||||
returns true if S is nested and false otherwise.
|
||||
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
def is_balanced(S):
|
||||
|
||||
stack = []
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"""Password generator allows you to generate a random password of length N."""
|
||||
from __future__ import print_function
|
||||
from random import choice
|
||||
from string import ascii_letters, digits, punctuation
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from __future__ import print_function
|
||||
def moveTower(height, fromPole, toPole, withPole):
|
||||
def moveTower(height, fromPole, toPole, withPole):
|
||||
'''
|
||||
>>> moveTower(3, 'A', 'B', 'C')
|
||||
moving disk from A to B
|
||||
|
||||
@@ -9,8 +9,6 @@ Given nums = [2, 7, 11, 15], target = 9,
|
||||
Because nums[0] + nums[1] = 2 + 7 = 9,
|
||||
return [0, 1].
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
def twoSum(nums, target):
|
||||
"""
|
||||
:type nums: List[int]
|
||||
@@ -20,7 +18,7 @@ def twoSum(nums, target):
|
||||
chk_map = {}
|
||||
for index, val in enumerate(nums):
|
||||
compl = target - val
|
||||
if compl in chk_map:
|
||||
if compl in chk_map:
|
||||
indices = [chk_map[compl], index]
|
||||
print(indices)
|
||||
return [indices]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
import pprint, time
|
||||
|
||||
def getWordPattern(word):
|
||||
|
||||
Reference in New Issue
Block a user