Skip to content

Instantly share code, notes, and snippets.

# Merge Sort in Python
def mergeSort(array):
if len(array) > 1:
# r is the point where the array is divided into two subarrays
r = len(array)//2
L = array[:r]
M = array[r:]
# Sort the two halves by recursive method
# MergeSort in Python
def mergeSort(array):
if len(array) > 1:
# r is the point where the array is divided into two subarrays
r = len(array)//2
L = array[:r]
M = array[r:]
# Sort the two halves by recursive method
# Quick Sort in Python
#finding the partition position
def partition(array, lowest, highest):
# choose the rightmost element as pivot
pivot = array[highest]
# pointer for greater element
i = lowest - 1
# compare each element with pivot
# Insertion sort in Python
def insertionSort(array):
for step in range(1, len(array)):
key = array[step]
j = step - 1
# Compare key with each element on the left of it until an element smaller than it is found
while j >= 0 and key < array[j]:
array[j + 1] = array[j]
j = j - 1
# Place key at after the element just smaller than it.
# Bubble sort in Python
def bubbleSort(array):
# Outer loop to access each element of array
for i in range(len(array)):
# inner loop to compare array elements with outer loop iteration element
for j in range(0, len(array) - i - 1):
# compare two adjacent elements
import pyttsx3
engine = pyttsx3.init()
"""Saving Voice to a file"""
# On linux make sure that 'espeak' and 'ffmpeg' are installed
#saving and runing
engine.save_to_file("I'm a Programmer", 'test.mp3')
engine.runAndWait()
import pyttsx3
#changing voice
engine = pyttsx3.init(driverName='sapi5')
engine.say("I'm a Programmer')
engine.runAndWait()
#importing module
import pyttsx3
#initializing the engine
engine = pyttsx3.init()
engine.say("I'm a Coder")
"""VOICE"""
voices = engine.getProperty('voices') # getting details of current voice
#engine.setProperty('voice', voices[0].id) # changes voices. o for male
#importing module
import pyttsx3
#initializing the engine
engine = pyttsx3.init()
engine.say("I'm a Coder")
""" RATE"""
rate = engine.getProperty('rate') # getting details of current speaking rate
print (rate) # print the current voice rate
#importing module
import pyttsx3
#initializing the engine
engine = pyttsx3.init()
engine.say("I'm a Coder")
#running code
engine.runAndWait()