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)

What software can be used to write python programs on windows desktop ?

1. What software can be used to write python programs on windows desktop ?

Enthought Canopy you can download from this link 

You can use standard python programming tool IDLE

2. Python Reference

go here for the “official”/technical explanation of what a particular function/operator does, examples of correct syntax, what the various libraries are, etc.

edx course referring text book

Introduction to Computation and Programming Using Python, Revised And Expanded Edition
by John V. Guttag

edx – Online course from world greatest schools (MIT, Harvard, Berkley…)

I registered Python programming course: “MITx: 6.00.1x Introduction to Computer Science and Programming” and doing well till now. These are the best online course available online for free with good flexibility.
Let me know if you have any queries after going to through this website “”