SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
HKBK COLLEGE OF ENGINEERING, BENGALURU
syllabus
syllabus
Module - 3 : Lists
 List methods
1) append( )
Adds a new element to the end of a list:
>>> t = ['a', 'b', 'c']
>>> t.append('d')
>>> print(t)
['a', 'b', 'c', 'd']
2) extend ( )
Takes a list as an argument and appends all of the elements:
>>> t1 = ['a', 'b', 'c']
>>> t2 = ['d', 'e']
>>> t1.extend(t2)
>>> print(t1)
['a', 'b', 'c', 'd', 'e']
This example leaves t2 unmodified.
Most list methods are void; they modify the list and return
None.
t = t.sort(), the result will be nothing
3) Sort ( )
Arranges the elements of the list from low to high:
>>> t = ['d', 'c', 'e', 'b', 'a']
>>> t.sort()
>>> print(t)
['a', 'b', 'c', 'd', 'e']
Module - 3 : Lists
 List methods -Deleting Elements
4) pop( )
To delete elements from a list. If the index of the
Element is known
>>> t = ['a', 'b', 'c']
>>> x = t.pop(1)
>>> print(t)
['a', 'c']
>>> print(x)
b
pop modifies the list and returns the element that was
removed.
If we don’t provide an index, it deletes and returns the
last element.
5) del( )
If we don’t need the removed value, use the del operator:
>>> t = ['a', 'b', 'c']
>>> del t[1]
>>> print(t)
['a', 'c']
>>> t = ['a', 'b', 'c']
>>> x = t.pop( )
>>> print(t)
['a', ‘b']
>>> print(x)
c
Module - 3 : Lists
 List methods -Deleting Elements
6) remove( )
If any element from the list to be removed , use remove:
>>> t = ['a', 'b', 'c']
>>> t.remove('b')
>>> print(t)
['a', 'c']
# The return value from remove is None.
To remove more than one element, you can use del with a slice index:
>>> t = ['a', 'b', 'c', 'd', 'e', 'f']
>>> del t[1:5]
>>> print(t)
['a', 'f']
As usual, the slice selects all the elements up to, but not including, the
second index.
Module - 3 : Lists
 Lists and functions
There are a number of built-in functions that can be used on lists that allow to quickly look through a list without writing own loops:
>>> nums = [3, 41, 12, 9, 74, 15]
>>> print(len(nums))
6
>>> print(max(nums))
74
>>> print(min(nums))
3
>>> print(sum(nums))
154
>>> print(sum(nums)/len(nums)) # finding average
25
The sum() function only works when the list elements are numbers.
The other functions (max(), len(), etc.) work with lists of strings and
other types that can be comparable.
Module - 3 : Lists
 Lists and functions
We could rewrite the program that computed the average of a list of numbers entered by the user using a list.
The program to compute an average without a list:
total = 0
count = 0
while (True):
inp = input('Enter a number: ')
if inp == 'done': break
value = float(inp)
total = total + value
count = count + 1
average = total / count
print('Average:', average)
Module - 3 : Lists
 Lists and functions
We could rewrite the program that computed the average of a list of numbers entered by the user using a list.
The program to compute an average with a list:
numlist = list() # empty list
while (True):
inp = input('Enter a number: ')
if inp == 'done': break
value = float(inp)
numlist.append(value)
average = sum(numlist) / len(numlist)
print('Average:', average)
Module - 3 : Lists
 Lists and Strings
A string is a sequence of characters and a list is a sequence of values, but a list of characters is not the same
as a string.
To convert from a string to a list of characters, use list:
>>> s = ‘HKBK'
>>> t = list(s)
>>> print(t)
[‘H', ‘K', ‘B', ‘K']
The list function breaks a string into individual letters. If we want to break a string into words, use split method:
>>> s = ‘Welcome to HKBKCE'
>>> t = s.split()
>>> print(t)
[' Welcome ', ‘ to ‘, ‘ HKBKCE ’]
>>> print(t[2])
HKBKCE
Module - 3 : Lists
 Lists and Strings
We can call split with an optional argument called a delimiter that specifies which characters to use as word
boundaries.
The following example uses a hyphen as a delimiter:
>>> s = 'spam-spam-spam'
>>> delimiter = '-'
>>> s.split(delimiter)
['spam', 'spam', 'spam']
Join( ) is the inverse of split. It takes a list of strings and concatenates the elements.
join is a string method, so we have to invoke it on the delimiter and pass the list as a parameter:
>>> t = [' Welcome ', ‘ to ‘, ‘ HKBKCE ’]
>>> delimiter = ‘ '
>>> delimiter.join(t)
‘Welcome to HKBKCE’
Module - 3 : Lists
 Objects and values
a = 'banana'
b = 'banana‘
we know that a and b both refer to a string, but we don’t know whether they refer to the same string.
There are two possible states:
In one case, a and b refer to two different objects that have the same value.
In the second case, they refer to the same object.
Module - 3 : Lists
 Objects and values
To check whether two variables refer to the same object, use the is operator.
>>> a = 'banana'
>>> b = 'banana'
>>> a is b
True
In this example, Python only created one string object, and both a and b refer to it.
Module - 3 : Lists
 Objects and values
create two lists, we get two objects:
>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> a is b
False
In this case , the two lists are equivalent, because they have the same elements, but not identical, because
they are not the same object.
If two objects are identical, they are also equivalent, but if they are equivalent, they are not necessarily
identical.
Module - 3 : Lists
 Aliasing
If a refers to an object and assign b = a, then both variables refer to the same object:
>>> a = [1, 2, 3]
>>> b = a
>>> b is a
True
The association of a variable with an object is called a reference.
In this example, there are two references to the same object.
An object with more than one reference has more than one name, then the object is aliased.
Module - 3 : Lists
 Aliasing
For immutable objects like strings, aliasing is not as much of a problem.
a = 'banana'
b = 'banana'
it almost never makes a difference whether a and b refer to the same string or not.
If the aliased object is mutable, changes made with one alias affect the other:
>>> a = [1, 2, 3]
>>> b = a
>>> b[0] = 17
>>> print(a)
[17, 2, 3]
Module - 3 : Lists
 List arguments
When we pass a list to a function, the function gets a reference to the list.
If the function modifies a list parameter, the caller sees the change.
For example,
delete_head removes the first element from a list:
def delete_head(t):
del t[0]
>>> letters = ['a', 'b', 'c']
>>> delete_head(letters)
>>> print(letters)
['b', 'c']
Module - 3 : Lists
 List arguments
The parameter t and the variable letters are aliases for the same object.
It is important to distinguish between operations that modify lists and operations that create new lists.
For example, the append method modifies a list, but the + operator creates a new list:
>>> t1 = [1, 2]
>>> t2 = t1.append(3)
>>> print(t1)
[1, 2, 3]
>>> print(t2)
None
>>> t3 = t1 + [3]
>>> print(t3)
[1, 2, 3]
>>> t2 is t3
False
Module - 3 : Lists
 List arguments
This difference is important when we write functions that are supposed to modify lists.
For example, this function does not delete the head of a list:
def bad_delete_head(t):
t = t[1:] # WRONG!
The slice operator creates a new list and the assignment makes t refer to it, but none of that has any
effect on the list that was passed as an argument.
An alternative is to write a function that creates and returns a new list.
For example, tail returns all but the first element of a list:
def tail(t):
return t[1:] #This function leaves the original list unmodified. Here’s how it is used:
>>> letters = ['a', 'b', 'c']
>>> rest = tail(letters)
>>> print(rest)
['b', 'c']
Module - 3 : Dictionaries
 Dictionary
• A dictionary is like a list, but more general.
• In a list, the index positions have to be integers; in a dictionary, the indices can be
(almost) any type.
• dictionary is as mapping between a set of indices (which are called keys) and a set
of values.
• Each key maps to a value.
• The association of a key and a value is called a key-value pair or sometimes an
item.
• the keys and the values are all strings.
Module - 3 : Dictionaries
 Dictionary
The function dict() creates a new dictionary with no items.
Because dict is the name of a built-in function, we should avoid using it as a variable name.
>>> city_capital = dict()
>>> print(city_capital)
{ } # The curly brackets, { }, represent an empty dictionary.
To add items to the dictionary, use square brackets:
>>> city_capital[‘KAR'] = ‘Bangalore‘
This line creates an item that maps from the key ’KAR’ to the value “Bangalore”.
If we print the dictionary again, we see a key-value pair with a colon between the key and
value:
>>> print(city_capital)
{‘KAR': ‘Bangalore'}
Module - 3 : Dictionaries
 Dictionary
>>> city_capital={'KAR':'Bangalore','TN':'Chennai','AP':'Hyderabad'}
>>> print(city_capital)
{'KAR': 'Bangalore', 'TN': 'Chennai', 'AP': 'Hyderabad'}
The order of the key-value pairs is not the same.
In general, the order of items in a dictionary is unpredictable.
Use the keys to look up the corresponding values:
>>> print(city_capital['TN'])
Chennai
If the key isn’t in the dictionary, we get an exception:
>>> print(city_capital[‘KN'])
KeyError: ‘KN'
Module - 3 : Dictionaries
 Dictionary
>>> city_capital={'KAR':'Bangalore','TN':'Chennai','AP':'Hyderabad'}
>>> print(city_capital)
{'KAR': 'Bangalore', 'TN': 'Chennai', 'AP': 'Hyderabad'}
The len function works on dictionaries;
it returns the number of key-value pairs:
>>> len(city_capital)
3
Module - 3 : Dictionaries
 Dictionary
>>> city_capital={'KAR':'Bangalore','TN':'Chennai','AP':'Hyderabad'}
>>> print(city_capital)
{'KAR': 'Bangalore', 'TN': 'Chennai', 'AP': 'Hyderabad'}
The in operator works on dictionaries; it tells whether something appears as a key in the
dictionary.
>>> ‘KAR' in city_capital
True
>>> ‘KAN' in city_capital
False
To see whether something appears as a value in a dictionary, use the method values, which
returns the values as a list, and then use the in operator:
>>> city = list(city_capital.values())
>>> ‘Bangalore' in city
True
Module - 3 : Dictionaries
 Dictionary
• The in operator uses different algorithms for lists and dictionaries.
• For lists, it uses a linear search algorithm. As the list gets longer, the search time gets
longer in direct proportion to the length of the list.
• For dictionaries, Python uses an algorithm called a hash table that has a remarkable
property: the in operator takes about the same amount of time no matter how many items
there are in a dictionary.
Module - 3 : Dictionaries
 Dictionary as a set of counters
str = 'Good Morning God Mother'
d = dict()
for ch in str:
if ch not in d:
d[ch] = 1
else:
d[ch] = d[ch] + 1
print(d)
{'G': 2, 'o': 5, 'd': 2, ' ': 3, 'M': 2, 'r': 2, 'n': 2, 'i': 1, 'g': 1, 't': 1, 'h': 1, 'e': 1}
We are effectively computing a histogram, which is a statistical term for a set of counters (or
frequencies).
Module - 3 : Dictionaries
 Dictionary as a set of counters
• Dictionaries have a method called get that takes a key and a default value.
• If the key appears in the dictionary, get returns the corresponding value;
otherwise it returns the default value.
For example:
>>> counts = { ‘Python' : 1 , ‘PCD' : 42, ‘Rupee': 100}
>>> print(counts.get(‘Rupee', 0))
100
>>> print(counts.get(‘doller', 0))
0
Module - 3 : Dictionaries
 Dictionary as a set of counters
str = 'Good Morning God Mother'
d = dict( )
for ch in str:
d[ch] = d.get(ch,0) + 1
print(d)
{'G': 2, 'o': 5, 'd': 2, ' ': 3, 'M': 2, 'r': 2, 'n': 2, 'i': 1, 'g': 1, 't': 1, 'h': 1, 'e': 1}
We can use get to write our histogram loop more concisely.
Because the get method automatically handles the case where a key is not in a dictionary,
we can reduce four lines down to one and eliminate the if statement.
Module - 3 : Dictionaries
 Dictionaries and files
 common uses of a dictionary is to count the occurrence of words in a file with some written
text.
Write a Python program to read through the lines of the file, break each line into a list of words,
and then loop through each of the words in the line and count each word using a dictionary.
We will see that we have two for loops.
The outer loop is reading the lines of the file and the inner loop is iterating through each of the
words on that particular line. This is an example of a pattern called nested loops because one of
the loops is the outer loop and the other loop is the inner loop
Module - 3 : Dictionaries
 Dictionaries and files
fname = input('Enter the file name: ')
try:
fhand = open(fname)
except:
print('File cannot be opened:', fname)
exit()
counts = dict()
for line in fhand:
words = line.split()
for word in words:
if word not in counts:
counts[word] = 1
else:
counts[word] += 1
print(counts)
Enter the file name: hkbk.txt
{'HKBK': 2, 'College': 1, 'of': 2, 'Engineering': 1, 'was': 1, 'established':
1, 'in': 2, '1997.': 1, 'Teaching': 1, 'is': 2, 'more': 1, 'than': 1, 'a': 2,
'profession,': 1, 'for': 1, 'the': 1, 'faculty': 1, 'members': 1, 'HKBKCE': 2,
'situated': 1, 'Bangalore': 1, 'We': 1, 'are': 1, 'proud': 1, 'to': 1, 'be': 1,
'Students.': 1}
HKBK.txt
HKBK College of Engineering was established in 1997.
Teaching is more than a profession, for the faculty
members of HKBKCE
HKBKCE is situated in Bangalore
We are proud to be a HKBK Students.
Module - 3 : Dictionaries
 Looping and dictionaries
If we use a dictionary as the sequence in a for statement, it traverses the keys of the dictionary.
This loop prints each key and the corresponding value:
counts = { 'BNG' : 1 , 'MYS' : 42, 'SMG': 100}
for key in counts:
print(key, counts[key])
Output:
BNG 1
MYS 42
SMG 100
Module - 3 : Dictionaries
 Looping and dictionaries
If we want to print the keys in alphabetical order,
1. make a list of the keys in the dictionary using the keys method available in dictionary objects
2. sort that list and loop through the sorted list, looking up each key
Program for Printing out key-value pairs in sorted order as follows:
Output:
['SMG', 'MYS', 'BNG']
BNG 100
MYS 42
SMG 1
counts = {'SMG' : 1 , 'MYS' : 42, 'BNG' : 100}
lst = list(counts.keys())
print(lst)
lst.sort()
for key in lst:
print(key, counts[key])
Module - 3 : Dictionaries
 Advanced text parsing
Python split function looks for spaces and treats words as tokens separated by spaces.
We can solve both Punctuation and case sensitive problems by using the string methods lower,
punctuation, and translate.
The translate is the most subtle of the methods.
line.translate(str.maketrans(fromstr, tostr, deletestr))
Replace the characters in fromstr with the character in the same position in tostr and delete all
characters that are in deletestr.
The fromstr and tostr can be empty strings and the deletestr parameter can be omitted.
Module - 3 : Dictionaries
 Advanced text parsing
>>> import string
>>> string.punctuation
'!"#$%&'()*+,-./:;<=>?@[]^_`{|}~‘
HKBKpunch.txt
Greetings from HKBKCE!
Hello, How are You?
HKBK College of Engineering was established in 1997.
Teaching is more than a profession, for the faculty members of HKBKCE
HKBKCE is situated in Bangalore
We are proud to be a HKBK Students.
Module - 3 : Dictionaries
 Advanced text parsingimport string
fname = input('Enter the file name: ') #counting words program
try:
fhand = open(fname)
except:
print('File cannot be opened:', fname)
exit()
counts = dict()
for line in fhand:
line = line.rstrip()
line = line.translate(line.maketrans('', '', string.punctuation))
line = line.lower()
words = line.split()
for word in words:
if word not in counts:
counts[word] = 1
else:
counts[word] += 1
print(counts)
Output:
Enter the file name: HKBKpunch.txt
{'greetings': 1, 'from': 1, 'hkbkce': 3, 'hello': 1, 'how': 1, 'are': 2, 'you':
1, 'hkbk': 2, 'college': 1, 'of': 2, 'engineering': 1, 'was': 1, 'established':
1, 'in': 2, '1997': 1, 'teaching': 1, 'is': 2, 'more': 1, 'than': 1, 'a': 2,
'profession': 1, 'for': 1, 'the': 1, 'faculty': 1, 'members': 1, 'situated': 1,
'bangalore': 1, 'we': 1, 'proud': 1, 'to': 1, 'be': 1, 'students': 1}
Module - 3 : Tuples
 Tuples are immutable
 A tuple is a sequence of values much like a list.
 The values stored in a tuple can be any type, and they are indexed by integers.
 The important difference is that tuples are immutable.
 Tuples are also comparable and hashable so we can sort lists of them and use tuples as key
values in Python dictionaries.
 Syntactically, a tuple is a comma-separated list of values:
t = 'a', 'b', 'c', 'd', 'e' or t = ('a', 'b', 'c', 'd', 'e')
>>> t1 = ('a',)
>>> type(t1)
<type 'tuple'>
>>> t2 = ('a')
>>> type(t2)
<type 'str'>
Module - 3 : Tuples
 Tuples are immutable
Another way to construct a tuple is the built-in function tuple.
With no argument, it creates an empty tuple:
>>> t = tuple()
>>> print(t)
()
If the argument is a sequence (string, list, or tuple), the result of the call to tuple is a tuple with
the elements of the sequence:
>>> t = tuple('lupins')
>>> print(t)
('l', 'u', 'p', 'i', 'n', 's')
Because tuple is the name of a constructor, avoid using it as a variable name.
Module - 3 : Tuples
 Tuples are immutable
Most list operators also work on tuples.
The bracket operator indexes an element:
>>> t = ('a', 'b', 'c', 'd', 'e')
>>> print(t[0])
'a'
slice operator selects a range of elements:
>>> print(t[1:3])
('b', 'c')
Module - 3 : Tuples
 Tuples are immutable
But if try to modify one of the elements of the tuple, will get an error:
>>> t[0] = 'A'
TypeError: object doesn't support item assignment
We can’t modify the elements of a tuple, but We can replace one tuple with another:
>>> t = ('A',) + t[1:]
>>> print(t)
('A', 'b', 'c', 'd', 'e')
Module - 3 : Tuples
 Comparing tuples
 The comparison operators work with tuples and other sequences.
 Python starts by comparing the first element from each sequence.
 If they are equal, it goes on to the next element, and so on, until it finds elements that differ.
 Subsequent elements are not considered (even if they are really big).
>>> (0, 1, 2) < (0, 3, 4)
True
>>> (0, 1, 2000000) < (0, 3, 4)
True
Module - 3 : Tuples
 Comparing tuples
 The sort function works the same way.
 It sorts primarily by first element, but in the case of a tie, it sorts by second element, and so
on.
 This feature lends itself to a pattern called DSU for
Decorate a sequence by building a list of tuples with one or more sort keys preceding the
elements from the sequence,
Sort the list of tuples using the Python built-in sort, and
Undecorate by extracting the sorted elements of the sequence.
[DSU]
Module - 3 : Tuples
 Comparing tuples
#Program to sort list of words from shortest to longest
txt = 'HKBK College of Engineering was established in 1997'
words = txt.split()
t = list()
for word in words:
t.append((len(word), word))
print(t)
t.sort()
print(t)
res = list()
for length, word in t:
res.append(word)
print(res)
Output:
[(4, 'HKBK'), (7, 'College'), (2, 'of'), (11, 'Engineering'), (3, 'was'), (11, 'established'),
(2, 'in'), (4, '1997')]
[(2, 'in'), (2, 'of'), (3, 'was'), (4, '1997'), (4, 'HKBK'), (7, 'College'), (11, 'Engineering'),
(11, 'established')]
['in', 'of', 'was', '1997', 'HKBK', 'College', 'Engineering', 'established']
Module - 3 : Tuples
 Tuple assignment
 One of the unique syntactic features of the Python language is the ability to have a tuple on
the left side of an assignment statement.
 This allows to assign more than one variable at a time when the left side is a sequence.
 Two-element list (which is a sequence) and assign the first and second elements of the
sequence to the variables x and y in a single statement.
>>> m = [ 'have', 'fun' ]
>>> x, y = m
>>> x
'have'
>>> y
'fun'
>>>
>>> m = [ 'have', 'fun' ]
>>> x = m[0]
>>> y = m[1]
>>> x
'have'
>>> y
'fun'
>>>
>>> m = [ 'have', 'fun' ]
>>> (x, y) = m
>>> x
'have'
>>> y
'fun'
>>>
Module - 3 : Tuples
 Tuple assignment
Tuple assignment allows us to swap the values of two variables in a single statement:
>>> a, b = b, a
The number of variables on the left and the number of values on the right must be
the same:
>>> a, b = 1, 2, 3
ValueError: too many values to unpack
>>> addr = 'monty@python.org'
>>> uname, domain = addr.split('@')
The return value from split is a list with two elements;
the first element is assigned to uname, the second to domain.
>>> print(uname)
monty
>>> print(domain)
python.org
Module - 3 : Tuples
 Dictionaries and tuples
Dictionaries have a method called items.
Item() returns a list of tuples, where each tuple is a key-value pair:
>>> d = {'a':10, 'b':1, 'c':22}
>>> t = list(d.items())
>>> print(t)
[('b', 1), ('a', 10), ('c', 22)]
As we should expect from a dictionary, the items are in no particular order.
Module - 3 : Tuples
 Dictionaries and tuples
sort the list of tuples.
Converting a dictionary to a list of tuples is a way for us to output the contents of a dictionary
sorted by key:
>>> d = {'a':10, 'b':1, 'c':22}
>>> t = list(d.items())
>>> t
[('b', 1), ('a', 10), ('c', 22)]
>>> t.sort()
>>> t
[('a', 10), ('b', 1), ('c', 22)]
The new list is sorted in ascending alphabetical order by the key value.
Module - 3 : Tuples
 Multiple assignment with dictionaries
Combining items, tuple assignment, and for will give code pattern for traversing the keys and values of a
dictionary in a single loop:
d = {'a':10, 'b':1, 'c':22}
for key, val in list(d.items()):
print(val, key)
This loop has two iteration variables because items returns a list of tuples and key, val is a tuple assignment
that successively iterates through each of the key-value pairs in the dictionary.
For each iteration through the loop, both key and value are advanced to the next key-value pair in the
dictionary (still in hash order).
The output of this loop is:
10 a
22 c
1 b
Module - 3 : Tuples
 The most common words
#program to count words
import string
fhand = open('HKBKpunch.txt')
counts = dict()
for line in fhand:
line = line.translate(str.maketrans('', '', string.punctuation))
line = line.lower()
words = line.split()
for word in words:
if word not in counts:
counts[word] = 1
else:
counts[word] += 1
# Sort the dictionary by value
lst = list()
for key, val in list(counts.items()):
lst.append((val, key))
lst.sort(reverse=True)
for key, val in lst[:10]:
print(key, val)
Output:
3 hkbkce
2 of
2 is
2 in
2 hkbk
2 are
2 a
1 you
1 we
1 was
The fact that this complex data parsing and analysis can be done with an easy-to
understand Python program is one reason why Python is a good choice as
a language for exploring information
Module - 3 : Tuples
 Using tuples as keys in dictionaries
Define the variables last, first, and number, we could write a dictionary assignment statement as
follows:
directory[last,first] = number
The expression in brackets is a tuple. We could use tuple assignment in a for loop to traverse this
dictionary.
for last, first in directory:
print(first, last, directory[last,first])
#Using tuples as keys in dictionaries
phone=dict()
phone['mustafa‘,'syed']=22223333
for lname, fname in phone:
print(fname, lname, phone[lname,fname])
Output: syed mustafa 22223333
Thank You

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Notes3
Notes3Notes3
Notes3
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Python list
Python listPython list
Python list
 
1. python
1. python1. python
1. python
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
List in Python
List in PythonList in Python
List in Python
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Python list
Python listPython list
Python list
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Sequence Types in Python Programming
Sequence Types in Python ProgrammingSequence Types in Python Programming
Sequence Types in Python Programming
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Lists
ListsLists
Lists
 
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - ListsPython Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
 
scripting in Python
scripting in Pythonscripting in Python
scripting in Python
 

Ähnlich wie 15CS664- Python Application Programming - Module 3

GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdfGE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdfAsst.prof M.Gokilavani
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptxYagna15
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdfAshaWankar1
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptxChandanVatsa2
 
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181Mahmoud Samir Fayed
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdfNehaSpillai1
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdfNehaSpillai1
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptxRamiHarrathi1
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxMihirDatir
 
Python elements list you can study .pdf
Python elements list you can study  .pdfPython elements list you can study  .pdf
Python elements list you can study .pdfAUNGHTET61
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84Mahmoud Samir Fayed
 
UNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt pptUNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt pptSuganthiDPSGRKCW
 
The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210Mahmoud Samir Fayed
 

Ähnlich wie 15CS664- Python Application Programming - Module 3 (20)

GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdfGE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptx
 
Python lists
Python listsPython lists
Python lists
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
 
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88
 
Module III.pdf
Module III.pdfModule III.pdf
Module III.pdf
 
The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
 
Python elements list you can study .pdf
Python elements list you can study  .pdfPython elements list you can study  .pdf
Python elements list you can study .pdf
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202
 
The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 
UNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt pptUNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt ppt
 
The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210
 

Mehr von Syed Mustafa

BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfSyed Mustafa
 
18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdf18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdfSyed Mustafa
 
Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5Syed Mustafa
 
15CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 315CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 3Syed Mustafa
 
15CS81- IoT Module-2
15CS81- IoT Module-215CS81- IoT Module-2
15CS81- IoT Module-2Syed Mustafa
 
Internet of Things - module 1
Internet of Things -  module 1Internet of Things -  module 1
Internet of Things - module 1Syed Mustafa
 
15CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 115CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 1Syed Mustafa
 
15CS664- Python Application Programming VTU syllabus
15CS664- Python Application Programming  VTU syllabus15CS664- Python Application Programming  VTU syllabus
15CS664- Python Application Programming VTU syllabusSyed Mustafa
 
15CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 415CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 4Syed Mustafa
 
15CS664 Python Question Bank-3
15CS664 Python Question Bank-315CS664 Python Question Bank-3
15CS664 Python Question Bank-3Syed Mustafa
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manualSyed Mustafa
 
Grid computing notes
Grid computing notesGrid computing notes
Grid computing notesSyed Mustafa
 
Unix system programming
Unix system programmingUnix system programming
Unix system programmingSyed Mustafa
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in CSyed Mustafa
 
Data structures lab c programs
Data structures lab  c programsData structures lab  c programs
Data structures lab c programsSyed Mustafa
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversionSyed Mustafa
 

Mehr von Syed Mustafa (20)

BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
 
18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdf18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdf
 
Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5
 
IoT - module 4
IoT - module 4IoT - module 4
IoT - module 4
 
15CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 315CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 3
 
15CS81- IoT Module-2
15CS81- IoT Module-215CS81- IoT Module-2
15CS81- IoT Module-2
 
Internet of Things - module 1
Internet of Things -  module 1Internet of Things -  module 1
Internet of Things - module 1
 
15CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 115CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 1
 
15CS664- Python Application Programming VTU syllabus
15CS664- Python Application Programming  VTU syllabus15CS664- Python Application Programming  VTU syllabus
15CS664- Python Application Programming VTU syllabus
 
15CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 415CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 4
 
15CS664 Python Question Bank-3
15CS664 Python Question Bank-315CS664 Python Question Bank-3
15CS664 Python Question Bank-3
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manual
 
Usp notes unit6-8
Usp notes unit6-8Usp notes unit6-8
Usp notes unit6-8
 
Grid computing notes
Grid computing notesGrid computing notes
Grid computing notes
 
Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
Data structures lab c programs
Data structures lab  c programsData structures lab  c programs
Data structures lab c programs
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversion
 

Kürzlich hochgeladen

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 

Kürzlich hochgeladen (20)

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 

15CS664- Python Application Programming - Module 3

  • 1. HKBK COLLEGE OF ENGINEERING, BENGALURU
  • 4. Module - 3 : Lists  List methods 1) append( ) Adds a new element to the end of a list: >>> t = ['a', 'b', 'c'] >>> t.append('d') >>> print(t) ['a', 'b', 'c', 'd'] 2) extend ( ) Takes a list as an argument and appends all of the elements: >>> t1 = ['a', 'b', 'c'] >>> t2 = ['d', 'e'] >>> t1.extend(t2) >>> print(t1) ['a', 'b', 'c', 'd', 'e'] This example leaves t2 unmodified. Most list methods are void; they modify the list and return None. t = t.sort(), the result will be nothing 3) Sort ( ) Arranges the elements of the list from low to high: >>> t = ['d', 'c', 'e', 'b', 'a'] >>> t.sort() >>> print(t) ['a', 'b', 'c', 'd', 'e']
  • 5. Module - 3 : Lists  List methods -Deleting Elements 4) pop( ) To delete elements from a list. If the index of the Element is known >>> t = ['a', 'b', 'c'] >>> x = t.pop(1) >>> print(t) ['a', 'c'] >>> print(x) b pop modifies the list and returns the element that was removed. If we don’t provide an index, it deletes and returns the last element. 5) del( ) If we don’t need the removed value, use the del operator: >>> t = ['a', 'b', 'c'] >>> del t[1] >>> print(t) ['a', 'c'] >>> t = ['a', 'b', 'c'] >>> x = t.pop( ) >>> print(t) ['a', ‘b'] >>> print(x) c
  • 6. Module - 3 : Lists  List methods -Deleting Elements 6) remove( ) If any element from the list to be removed , use remove: >>> t = ['a', 'b', 'c'] >>> t.remove('b') >>> print(t) ['a', 'c'] # The return value from remove is None. To remove more than one element, you can use del with a slice index: >>> t = ['a', 'b', 'c', 'd', 'e', 'f'] >>> del t[1:5] >>> print(t) ['a', 'f'] As usual, the slice selects all the elements up to, but not including, the second index.
  • 7. Module - 3 : Lists  Lists and functions There are a number of built-in functions that can be used on lists that allow to quickly look through a list without writing own loops: >>> nums = [3, 41, 12, 9, 74, 15] >>> print(len(nums)) 6 >>> print(max(nums)) 74 >>> print(min(nums)) 3 >>> print(sum(nums)) 154 >>> print(sum(nums)/len(nums)) # finding average 25 The sum() function only works when the list elements are numbers. The other functions (max(), len(), etc.) work with lists of strings and other types that can be comparable.
  • 8. Module - 3 : Lists  Lists and functions We could rewrite the program that computed the average of a list of numbers entered by the user using a list. The program to compute an average without a list: total = 0 count = 0 while (True): inp = input('Enter a number: ') if inp == 'done': break value = float(inp) total = total + value count = count + 1 average = total / count print('Average:', average)
  • 9. Module - 3 : Lists  Lists and functions We could rewrite the program that computed the average of a list of numbers entered by the user using a list. The program to compute an average with a list: numlist = list() # empty list while (True): inp = input('Enter a number: ') if inp == 'done': break value = float(inp) numlist.append(value) average = sum(numlist) / len(numlist) print('Average:', average)
  • 10. Module - 3 : Lists  Lists and Strings A string is a sequence of characters and a list is a sequence of values, but a list of characters is not the same as a string. To convert from a string to a list of characters, use list: >>> s = ‘HKBK' >>> t = list(s) >>> print(t) [‘H', ‘K', ‘B', ‘K'] The list function breaks a string into individual letters. If we want to break a string into words, use split method: >>> s = ‘Welcome to HKBKCE' >>> t = s.split() >>> print(t) [' Welcome ', ‘ to ‘, ‘ HKBKCE ’] >>> print(t[2]) HKBKCE
  • 11. Module - 3 : Lists  Lists and Strings We can call split with an optional argument called a delimiter that specifies which characters to use as word boundaries. The following example uses a hyphen as a delimiter: >>> s = 'spam-spam-spam' >>> delimiter = '-' >>> s.split(delimiter) ['spam', 'spam', 'spam'] Join( ) is the inverse of split. It takes a list of strings and concatenates the elements. join is a string method, so we have to invoke it on the delimiter and pass the list as a parameter: >>> t = [' Welcome ', ‘ to ‘, ‘ HKBKCE ’] >>> delimiter = ‘ ' >>> delimiter.join(t) ‘Welcome to HKBKCE’
  • 12. Module - 3 : Lists  Objects and values a = 'banana' b = 'banana‘ we know that a and b both refer to a string, but we don’t know whether they refer to the same string. There are two possible states: In one case, a and b refer to two different objects that have the same value. In the second case, they refer to the same object.
  • 13. Module - 3 : Lists  Objects and values To check whether two variables refer to the same object, use the is operator. >>> a = 'banana' >>> b = 'banana' >>> a is b True In this example, Python only created one string object, and both a and b refer to it.
  • 14. Module - 3 : Lists  Objects and values create two lists, we get two objects: >>> a = [1, 2, 3] >>> b = [1, 2, 3] >>> a is b False In this case , the two lists are equivalent, because they have the same elements, but not identical, because they are not the same object. If two objects are identical, they are also equivalent, but if they are equivalent, they are not necessarily identical.
  • 15. Module - 3 : Lists  Aliasing If a refers to an object and assign b = a, then both variables refer to the same object: >>> a = [1, 2, 3] >>> b = a >>> b is a True The association of a variable with an object is called a reference. In this example, there are two references to the same object. An object with more than one reference has more than one name, then the object is aliased.
  • 16. Module - 3 : Lists  Aliasing For immutable objects like strings, aliasing is not as much of a problem. a = 'banana' b = 'banana' it almost never makes a difference whether a and b refer to the same string or not. If the aliased object is mutable, changes made with one alias affect the other: >>> a = [1, 2, 3] >>> b = a >>> b[0] = 17 >>> print(a) [17, 2, 3]
  • 17. Module - 3 : Lists  List arguments When we pass a list to a function, the function gets a reference to the list. If the function modifies a list parameter, the caller sees the change. For example, delete_head removes the first element from a list: def delete_head(t): del t[0] >>> letters = ['a', 'b', 'c'] >>> delete_head(letters) >>> print(letters) ['b', 'c']
  • 18. Module - 3 : Lists  List arguments The parameter t and the variable letters are aliases for the same object. It is important to distinguish between operations that modify lists and operations that create new lists. For example, the append method modifies a list, but the + operator creates a new list: >>> t1 = [1, 2] >>> t2 = t1.append(3) >>> print(t1) [1, 2, 3] >>> print(t2) None >>> t3 = t1 + [3] >>> print(t3) [1, 2, 3] >>> t2 is t3 False
  • 19. Module - 3 : Lists  List arguments This difference is important when we write functions that are supposed to modify lists. For example, this function does not delete the head of a list: def bad_delete_head(t): t = t[1:] # WRONG! The slice operator creates a new list and the assignment makes t refer to it, but none of that has any effect on the list that was passed as an argument. An alternative is to write a function that creates and returns a new list. For example, tail returns all but the first element of a list: def tail(t): return t[1:] #This function leaves the original list unmodified. Here’s how it is used: >>> letters = ['a', 'b', 'c'] >>> rest = tail(letters) >>> print(rest) ['b', 'c']
  • 20. Module - 3 : Dictionaries  Dictionary • A dictionary is like a list, but more general. • In a list, the index positions have to be integers; in a dictionary, the indices can be (almost) any type. • dictionary is as mapping between a set of indices (which are called keys) and a set of values. • Each key maps to a value. • The association of a key and a value is called a key-value pair or sometimes an item. • the keys and the values are all strings.
  • 21. Module - 3 : Dictionaries  Dictionary The function dict() creates a new dictionary with no items. Because dict is the name of a built-in function, we should avoid using it as a variable name. >>> city_capital = dict() >>> print(city_capital) { } # The curly brackets, { }, represent an empty dictionary. To add items to the dictionary, use square brackets: >>> city_capital[‘KAR'] = ‘Bangalore‘ This line creates an item that maps from the key ’KAR’ to the value “Bangalore”. If we print the dictionary again, we see a key-value pair with a colon between the key and value: >>> print(city_capital) {‘KAR': ‘Bangalore'}
  • 22. Module - 3 : Dictionaries  Dictionary >>> city_capital={'KAR':'Bangalore','TN':'Chennai','AP':'Hyderabad'} >>> print(city_capital) {'KAR': 'Bangalore', 'TN': 'Chennai', 'AP': 'Hyderabad'} The order of the key-value pairs is not the same. In general, the order of items in a dictionary is unpredictable. Use the keys to look up the corresponding values: >>> print(city_capital['TN']) Chennai If the key isn’t in the dictionary, we get an exception: >>> print(city_capital[‘KN']) KeyError: ‘KN'
  • 23. Module - 3 : Dictionaries  Dictionary >>> city_capital={'KAR':'Bangalore','TN':'Chennai','AP':'Hyderabad'} >>> print(city_capital) {'KAR': 'Bangalore', 'TN': 'Chennai', 'AP': 'Hyderabad'} The len function works on dictionaries; it returns the number of key-value pairs: >>> len(city_capital) 3
  • 24. Module - 3 : Dictionaries  Dictionary >>> city_capital={'KAR':'Bangalore','TN':'Chennai','AP':'Hyderabad'} >>> print(city_capital) {'KAR': 'Bangalore', 'TN': 'Chennai', 'AP': 'Hyderabad'} The in operator works on dictionaries; it tells whether something appears as a key in the dictionary. >>> ‘KAR' in city_capital True >>> ‘KAN' in city_capital False To see whether something appears as a value in a dictionary, use the method values, which returns the values as a list, and then use the in operator: >>> city = list(city_capital.values()) >>> ‘Bangalore' in city True
  • 25. Module - 3 : Dictionaries  Dictionary • The in operator uses different algorithms for lists and dictionaries. • For lists, it uses a linear search algorithm. As the list gets longer, the search time gets longer in direct proportion to the length of the list. • For dictionaries, Python uses an algorithm called a hash table that has a remarkable property: the in operator takes about the same amount of time no matter how many items there are in a dictionary.
  • 26. Module - 3 : Dictionaries  Dictionary as a set of counters str = 'Good Morning God Mother' d = dict() for ch in str: if ch not in d: d[ch] = 1 else: d[ch] = d[ch] + 1 print(d) {'G': 2, 'o': 5, 'd': 2, ' ': 3, 'M': 2, 'r': 2, 'n': 2, 'i': 1, 'g': 1, 't': 1, 'h': 1, 'e': 1} We are effectively computing a histogram, which is a statistical term for a set of counters (or frequencies).
  • 27. Module - 3 : Dictionaries  Dictionary as a set of counters • Dictionaries have a method called get that takes a key and a default value. • If the key appears in the dictionary, get returns the corresponding value; otherwise it returns the default value. For example: >>> counts = { ‘Python' : 1 , ‘PCD' : 42, ‘Rupee': 100} >>> print(counts.get(‘Rupee', 0)) 100 >>> print(counts.get(‘doller', 0)) 0
  • 28. Module - 3 : Dictionaries  Dictionary as a set of counters str = 'Good Morning God Mother' d = dict( ) for ch in str: d[ch] = d.get(ch,0) + 1 print(d) {'G': 2, 'o': 5, 'd': 2, ' ': 3, 'M': 2, 'r': 2, 'n': 2, 'i': 1, 'g': 1, 't': 1, 'h': 1, 'e': 1} We can use get to write our histogram loop more concisely. Because the get method automatically handles the case where a key is not in a dictionary, we can reduce four lines down to one and eliminate the if statement.
  • 29. Module - 3 : Dictionaries  Dictionaries and files  common uses of a dictionary is to count the occurrence of words in a file with some written text. Write a Python program to read through the lines of the file, break each line into a list of words, and then loop through each of the words in the line and count each word using a dictionary. We will see that we have two for loops. The outer loop is reading the lines of the file and the inner loop is iterating through each of the words on that particular line. This is an example of a pattern called nested loops because one of the loops is the outer loop and the other loop is the inner loop
  • 30. Module - 3 : Dictionaries  Dictionaries and files fname = input('Enter the file name: ') try: fhand = open(fname) except: print('File cannot be opened:', fname) exit() counts = dict() for line in fhand: words = line.split() for word in words: if word not in counts: counts[word] = 1 else: counts[word] += 1 print(counts) Enter the file name: hkbk.txt {'HKBK': 2, 'College': 1, 'of': 2, 'Engineering': 1, 'was': 1, 'established': 1, 'in': 2, '1997.': 1, 'Teaching': 1, 'is': 2, 'more': 1, 'than': 1, 'a': 2, 'profession,': 1, 'for': 1, 'the': 1, 'faculty': 1, 'members': 1, 'HKBKCE': 2, 'situated': 1, 'Bangalore': 1, 'We': 1, 'are': 1, 'proud': 1, 'to': 1, 'be': 1, 'Students.': 1} HKBK.txt HKBK College of Engineering was established in 1997. Teaching is more than a profession, for the faculty members of HKBKCE HKBKCE is situated in Bangalore We are proud to be a HKBK Students.
  • 31. Module - 3 : Dictionaries  Looping and dictionaries If we use a dictionary as the sequence in a for statement, it traverses the keys of the dictionary. This loop prints each key and the corresponding value: counts = { 'BNG' : 1 , 'MYS' : 42, 'SMG': 100} for key in counts: print(key, counts[key]) Output: BNG 1 MYS 42 SMG 100
  • 32. Module - 3 : Dictionaries  Looping and dictionaries If we want to print the keys in alphabetical order, 1. make a list of the keys in the dictionary using the keys method available in dictionary objects 2. sort that list and loop through the sorted list, looking up each key Program for Printing out key-value pairs in sorted order as follows: Output: ['SMG', 'MYS', 'BNG'] BNG 100 MYS 42 SMG 1 counts = {'SMG' : 1 , 'MYS' : 42, 'BNG' : 100} lst = list(counts.keys()) print(lst) lst.sort() for key in lst: print(key, counts[key])
  • 33. Module - 3 : Dictionaries  Advanced text parsing Python split function looks for spaces and treats words as tokens separated by spaces. We can solve both Punctuation and case sensitive problems by using the string methods lower, punctuation, and translate. The translate is the most subtle of the methods. line.translate(str.maketrans(fromstr, tostr, deletestr)) Replace the characters in fromstr with the character in the same position in tostr and delete all characters that are in deletestr. The fromstr and tostr can be empty strings and the deletestr parameter can be omitted.
  • 34. Module - 3 : Dictionaries  Advanced text parsing >>> import string >>> string.punctuation '!"#$%&'()*+,-./:;<=>?@[]^_`{|}~‘ HKBKpunch.txt Greetings from HKBKCE! Hello, How are You? HKBK College of Engineering was established in 1997. Teaching is more than a profession, for the faculty members of HKBKCE HKBKCE is situated in Bangalore We are proud to be a HKBK Students.
  • 35. Module - 3 : Dictionaries  Advanced text parsingimport string fname = input('Enter the file name: ') #counting words program try: fhand = open(fname) except: print('File cannot be opened:', fname) exit() counts = dict() for line in fhand: line = line.rstrip() line = line.translate(line.maketrans('', '', string.punctuation)) line = line.lower() words = line.split() for word in words: if word not in counts: counts[word] = 1 else: counts[word] += 1 print(counts) Output: Enter the file name: HKBKpunch.txt {'greetings': 1, 'from': 1, 'hkbkce': 3, 'hello': 1, 'how': 1, 'are': 2, 'you': 1, 'hkbk': 2, 'college': 1, 'of': 2, 'engineering': 1, 'was': 1, 'established': 1, 'in': 2, '1997': 1, 'teaching': 1, 'is': 2, 'more': 1, 'than': 1, 'a': 2, 'profession': 1, 'for': 1, 'the': 1, 'faculty': 1, 'members': 1, 'situated': 1, 'bangalore': 1, 'we': 1, 'proud': 1, 'to': 1, 'be': 1, 'students': 1}
  • 36. Module - 3 : Tuples  Tuples are immutable  A tuple is a sequence of values much like a list.  The values stored in a tuple can be any type, and they are indexed by integers.  The important difference is that tuples are immutable.  Tuples are also comparable and hashable so we can sort lists of them and use tuples as key values in Python dictionaries.  Syntactically, a tuple is a comma-separated list of values: t = 'a', 'b', 'c', 'd', 'e' or t = ('a', 'b', 'c', 'd', 'e') >>> t1 = ('a',) >>> type(t1) <type 'tuple'> >>> t2 = ('a') >>> type(t2) <type 'str'>
  • 37. Module - 3 : Tuples  Tuples are immutable Another way to construct a tuple is the built-in function tuple. With no argument, it creates an empty tuple: >>> t = tuple() >>> print(t) () If the argument is a sequence (string, list, or tuple), the result of the call to tuple is a tuple with the elements of the sequence: >>> t = tuple('lupins') >>> print(t) ('l', 'u', 'p', 'i', 'n', 's') Because tuple is the name of a constructor, avoid using it as a variable name.
  • 38. Module - 3 : Tuples  Tuples are immutable Most list operators also work on tuples. The bracket operator indexes an element: >>> t = ('a', 'b', 'c', 'd', 'e') >>> print(t[0]) 'a' slice operator selects a range of elements: >>> print(t[1:3]) ('b', 'c')
  • 39. Module - 3 : Tuples  Tuples are immutable But if try to modify one of the elements of the tuple, will get an error: >>> t[0] = 'A' TypeError: object doesn't support item assignment We can’t modify the elements of a tuple, but We can replace one tuple with another: >>> t = ('A',) + t[1:] >>> print(t) ('A', 'b', 'c', 'd', 'e')
  • 40. Module - 3 : Tuples  Comparing tuples  The comparison operators work with tuples and other sequences.  Python starts by comparing the first element from each sequence.  If they are equal, it goes on to the next element, and so on, until it finds elements that differ.  Subsequent elements are not considered (even if they are really big). >>> (0, 1, 2) < (0, 3, 4) True >>> (0, 1, 2000000) < (0, 3, 4) True
  • 41. Module - 3 : Tuples  Comparing tuples  The sort function works the same way.  It sorts primarily by first element, but in the case of a tie, it sorts by second element, and so on.  This feature lends itself to a pattern called DSU for Decorate a sequence by building a list of tuples with one or more sort keys preceding the elements from the sequence, Sort the list of tuples using the Python built-in sort, and Undecorate by extracting the sorted elements of the sequence. [DSU]
  • 42. Module - 3 : Tuples  Comparing tuples #Program to sort list of words from shortest to longest txt = 'HKBK College of Engineering was established in 1997' words = txt.split() t = list() for word in words: t.append((len(word), word)) print(t) t.sort() print(t) res = list() for length, word in t: res.append(word) print(res) Output: [(4, 'HKBK'), (7, 'College'), (2, 'of'), (11, 'Engineering'), (3, 'was'), (11, 'established'), (2, 'in'), (4, '1997')] [(2, 'in'), (2, 'of'), (3, 'was'), (4, '1997'), (4, 'HKBK'), (7, 'College'), (11, 'Engineering'), (11, 'established')] ['in', 'of', 'was', '1997', 'HKBK', 'College', 'Engineering', 'established']
  • 43. Module - 3 : Tuples  Tuple assignment  One of the unique syntactic features of the Python language is the ability to have a tuple on the left side of an assignment statement.  This allows to assign more than one variable at a time when the left side is a sequence.  Two-element list (which is a sequence) and assign the first and second elements of the sequence to the variables x and y in a single statement. >>> m = [ 'have', 'fun' ] >>> x, y = m >>> x 'have' >>> y 'fun' >>> >>> m = [ 'have', 'fun' ] >>> x = m[0] >>> y = m[1] >>> x 'have' >>> y 'fun' >>> >>> m = [ 'have', 'fun' ] >>> (x, y) = m >>> x 'have' >>> y 'fun' >>>
  • 44. Module - 3 : Tuples  Tuple assignment Tuple assignment allows us to swap the values of two variables in a single statement: >>> a, b = b, a The number of variables on the left and the number of values on the right must be the same: >>> a, b = 1, 2, 3 ValueError: too many values to unpack >>> addr = 'monty@python.org' >>> uname, domain = addr.split('@') The return value from split is a list with two elements; the first element is assigned to uname, the second to domain. >>> print(uname) monty >>> print(domain) python.org
  • 45. Module - 3 : Tuples  Dictionaries and tuples Dictionaries have a method called items. Item() returns a list of tuples, where each tuple is a key-value pair: >>> d = {'a':10, 'b':1, 'c':22} >>> t = list(d.items()) >>> print(t) [('b', 1), ('a', 10), ('c', 22)] As we should expect from a dictionary, the items are in no particular order.
  • 46. Module - 3 : Tuples  Dictionaries and tuples sort the list of tuples. Converting a dictionary to a list of tuples is a way for us to output the contents of a dictionary sorted by key: >>> d = {'a':10, 'b':1, 'c':22} >>> t = list(d.items()) >>> t [('b', 1), ('a', 10), ('c', 22)] >>> t.sort() >>> t [('a', 10), ('b', 1), ('c', 22)] The new list is sorted in ascending alphabetical order by the key value.
  • 47. Module - 3 : Tuples  Multiple assignment with dictionaries Combining items, tuple assignment, and for will give code pattern for traversing the keys and values of a dictionary in a single loop: d = {'a':10, 'b':1, 'c':22} for key, val in list(d.items()): print(val, key) This loop has two iteration variables because items returns a list of tuples and key, val is a tuple assignment that successively iterates through each of the key-value pairs in the dictionary. For each iteration through the loop, both key and value are advanced to the next key-value pair in the dictionary (still in hash order). The output of this loop is: 10 a 22 c 1 b
  • 48. Module - 3 : Tuples  The most common words #program to count words import string fhand = open('HKBKpunch.txt') counts = dict() for line in fhand: line = line.translate(str.maketrans('', '', string.punctuation)) line = line.lower() words = line.split() for word in words: if word not in counts: counts[word] = 1 else: counts[word] += 1 # Sort the dictionary by value lst = list() for key, val in list(counts.items()): lst.append((val, key)) lst.sort(reverse=True) for key, val in lst[:10]: print(key, val) Output: 3 hkbkce 2 of 2 is 2 in 2 hkbk 2 are 2 a 1 you 1 we 1 was The fact that this complex data parsing and analysis can be done with an easy-to understand Python program is one reason why Python is a good choice as a language for exploring information
  • 49. Module - 3 : Tuples  Using tuples as keys in dictionaries Define the variables last, first, and number, we could write a dictionary assignment statement as follows: directory[last,first] = number The expression in brackets is a tuple. We could use tuple assignment in a for loop to traverse this dictionary. for last, first in directory: print(first, last, directory[last,first]) #Using tuples as keys in dictionaries phone=dict() phone['mustafa‘,'syed']=22223333 for lname, fname in phone: print(fname, lname, phone[lname,fname]) Output: syed mustafa 22223333