Run shell script in parallel using


#!/bin/env python
#Run shell scripts in parallel
#using pythong multiprocessing module
# Raju Konduru

import multiprocessing
import time
import os
import sys
import subprocess
from pprint import pprint

if len(sys.argv) == 4:
scriptToRun = sys.argv[1]
inputFile = sys.argv[2]
numOfProcess = int(sys.argv[3])
print type(numOfProcess)
print “Need 2 arguments 1st one input file 2nd one number of concurrent jobs”
print “Example sys.argv[0] myinput.csv 2”

inFile = open(inputFile,’r’)

def mp_worker(GRP):
print “Processs script”+scriptToRun+’ ‘+GRP,GRP)

def mp_handler():
p = multiprocessing.Pool(numOfProcess)
with open(inputFile,’r’) as source_file:
results =, source_file,numOfProcess)
print results

if __name__ == ‘__main__’:




Python: Lists (difference between Lists and Tuples)

#Lecture 6 Lists


Lists look like Tuples, but they have some critical differences. It’s very important to make out the differences

Tuples Lists

===================== ===================================

used () parenthesis Uses [] parenthesis

singlets need , (5,) No additional comma reqired [5]

Immutable, means elements can’t Important feature, Lists are mutable

be modified e.x.,: Trees=[‘Mango’, ‘Neem’, ‘Tamarind’]

we can replace Neem i.e. Trees[1]=’Banian’

Now Trees List will looks as

Trees=[‘Mango’, ‘Banian’, ‘Tamarind’]


Trees=[‘Mango’, ‘Neem’, ‘Tamarind’]

Fruits=[‘Apple’, ‘Banana’]

print Trees, Fruits

#Modify the Trees lists


print Trees

#using methods like append, we can extend Lists


print Fruits

#Now we will see another example called “Aliasng”


Plants1=[[‘Mango’, ‘Banian’, ‘Tamarind’], [‘Apple’, ‘Banana’, ‘Mango’]]

#if you print both look alike

#print Plants

#print Plants1

#Now modify Trees lists using append method


print Plants

print Plants1


OUTPUTs varies

Plants output [[‘Mango’, ‘Neem’, ‘Tamarind’], [‘Apple’, ‘Banana’, ‘Mango’]]

Plants1 output [[‘Mango’, ‘Banian’, ‘Tamarind’], [‘Apple’, ‘Banana’, ‘Mango’]]


python – oddTuples

#Python Function which returns odd Tuples


Write a procedure called oddTuples, which takes a tuple as input,

and returns a new tuple as output, where every other element of the input tuple is copied,

starting with the first one. So if test is the tuple (‘I’, ‘am’, ‘a’, ‘test’, ‘tuple’),

then evaluating oddTuples on this input would return the tuple (‘I’, ‘a’, ‘tuple’).


def oddTuples(aTup):


aTup: a tuple

returns: tuple, every other element of aTup.


# Your Code Here



for i in aTup:

if num%2 == 1:

t1= t1+(i,)




return t1

print oddTuples((1, ‘two’, 3, ‘four’, 5))

python programme to calculate greatest common divisior (GCD) using recursion

def gcdIter(a, b):


a, b: positive integers

returns: a positive integer, the greatest common divisor of a & b.


# Your code here

Recursive Method

 if a == b:

 return a

  elif a > b:

 return gcdIter(a-b, b)

elif b > a:

return gcdIter(a, b-a)