from itertools import permutations
def allPermutations(str):
permList = permutations(str)
for perm in list(permList):
print (''.join(perm))
if __name__ == "__main__":
str = 'ABC'
allPermutations(str)
Solve Problems by Coding Solutions - A Complete solution for python programming
from itertools import permutations
def allPermutations(str):
permList = permutations(str)
for perm in list(permList):
print (''.join(perm))
if __name__ == "__main__":
str = 'ABC'
allPermutations(str)
import re
def Validate_It(IP):
regex = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|"\
"2[0-4][0-9]|25[0-5])\\.){3}"\
"([0-9]|[1-9][0-9]|1[0-9][0-9]|"\
"2[0-4][0-9]|25[0-5])"
regex1 = "((([0-9a-fA-F]){1,4})\\:){7}"\
"([0-9a-fA-F]){1,4}"
p = re.compile(regex)
p1 = re.compile(regex1)
if (re.search(p, IP)):
return "Valid IPv4"
elif (re.search(p1, IP)):
return "Valid IPv6"
return "Invalid IP"
IP = "203.120.223.13"
print(Validate_It(IP))
IP = "fffe:3465:efab:23fe:2235:6565:aaab:0001"
print(Validate_It(IP))
IP = "2F33:12a0:3Ea0:0302"
print(Validate_It(IP))
import folium
my_map4 = folium.Map(location = [28.5011226,77.4099794],zoom_start =12)
folium.Marker([28.704059, 77.102490],popup = 'Delhi').add_to(my_map4)
folium.Marker([28.5011226, 77.4099794],popup = 'Python For Engineers').add_to(my_map4)
folium.PolyLine(locations = [(28.704059, 77.102490), (28.5011226, 77.4099794)],line_opacity =0.5).add_to(my_map4)
my_map4.save("my_map4.html")
my_map4
def cocktailSort(a):
n = len(a)
swapped = True
start = 0
end = n-1
while (swapped==True):
swapped = False
for i in range (start, end):
if (a[i] > a[i+1]) :
a[i], a[i+1]= a[i+1], a[i]
swapped=True
if (swapped==False):
break
swapped = False
end = end-1
for i in range(end-1, start-1,-1):
if (a[i] > a[i+1]):
a[i], a[i+1] = a[i+1], a[i]
swapped = True
start = start+1
a = [5, 1, 4, 2, 8, 0, 2 ,6,7]
cocktailSort(a)
print("Sorted array is:")
for i in range(len(a)):
print ("%d" %a[i]),
def gnomeSort( arr, n):
index = 0
while index < n:
if index == 0:
index = index + 1
if arr[index] >= arr[index - 1]:
index = index + 1
else:
arr[index], arr[index-1] = arr[index-1], arr[index]
index = index - 1
return arr
arr = [ 34, 2, 10, -9]
n = len(arr)
arr = gnomeSort(arr, n)
print ("Sorted seqquence after applying Gnome Sort :")
for i in arr:
print (i)