FINAL Revised LIST in Python
FINAL Revised LIST in Python
w w w. k n o w p y t h o n b y te s . b l o g s p o t . c o m
Mrs. Payal Bhattacharjee, PGT(C.Sc.)
K V No.1 Kanchrapara
KVS-RO(Kolkata)
CONTENTS
( Learning Outcomes )
LIST in Python
XI CS 2020-21
Lists Introduction: Definition, Creation of a list, Traversal of a list.
Operations on a list – concatenation/joining, repetition/replication,
membership, Comparison of Lists;
Functions/methods–len(), list(),append(), extend(), insert(), count(),
index(), remove(), pop(), reverse(), sort(),min(), max(), sum()
Lists Slicing;
Nested lists;
finding the maximum, minimum, mean of numeric values stored in a list
linear search on list of numbers
counting the frequency of elements in a list
XI IP 2020-21
Lists: list operations - creating, initializing, traversing and manipulating
What is a LIST ?
CONTENTS
• A list is a collections of items which are
Lists Intro: formed by placing a comma-separated-
List Definition list of expressions in square brackets.
Indexing in a List
• Each item/element has its own index
Creation of a list
Traversal of a list. number.
Operations on a list - • Index of first item is 0 and the last item
Functions/methods
Lists Slicing;
is n-1. Here n is number of items in a
Nested lists; list.
finding the maximum, • Lists are mutable sequences i.e. we can
minimum, mean
linear search on list change elements of a list in place.
counting the frequency • Lists can contain values of mixed data
types.
INDEXING in a LIST
CONTENTS FORWARD INDEX DIRECTION
0 1 2 3 4 5
Lists Intro:
List Definition 10 20 30 40 50 60
Indexing in a List -6 -5 -4 -3 -2 -1
Creation of a list BACKWARD INDEX DIRECTION
Traversal of a list
Operations on a list
Functions/methods
Lists Slicing; NOTE:-
Nested lists; The index (also called subscript) is the numbered
finding the maximum, position of a letter in the LIST. In python, indices begin
minimum, mean
from
linear search on list
counting the frequency 0,1,2,…. upto (length-1) in the forward
direction and
-1,-2,-3,….. (-length) in the backward direction.
where length is the length of the List.
CREATION of LIST
CONTENTS
Lists Intro:
List of numbers created without name
Lists Intro:
List Definition
Indexing in a List
Creation of a list Creating list by taking input from the keyboard(user)
from string,tuple,
list(input()),
eval(input())
Traversal of a list **Note: All the elements are considered as string
Assign/change values in List
Operations on a list Creating list by taking input from the keyboard [using eval()]
Functions/methods ]method]
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list **Note: eval( ) identifies the type by looking at the given
counting the frequency expression
TRAVERSAL of a LIST
CONTENTS
Lists Intro:
List Definition
Indexing in a List
Creation of a list
Traversal of a list
Assign /change values in List
Operations on a list
Functions/methods
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
TRAVERSAL of NESTED LIST
CONTENTS
Enclosing List
Lists Intro:
List Definition
Indexing in a List Nested List 1 Nested List 2
Creation of a list
Traversal of a list
Assign /change values in List
Lists Intro:
List Definition Assigning
/ Changing
Indexing in a List values of
Creation of a list elements
Traversal of a list of a List
Assign /change
values in List
Operations on a list
Functions/methods
Lists Slicing; Assigning /
Nested lists; Changing
finding the maximum, values of
elements of
minimum, mean a List
linear search on list
counting the frequency
OPERATIONS on LIST Concatenation
CONTENTS List CAN be concatenated or
joined with another List
Lists Introduction:
List CANNOT be concatenated with a number
OPERATIONS
ON List
Concatenation/Joining
Repetition/Replication
Membership List CANNOT be concatenated with a string
Comparison of Lists
Functions/methods
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean List CANNOT be joined with a complex nos.
linear search on list
counting the frequency
Concatenation refers
to Joining of two List CAN be concatenated or
objects joined with another List
OPERATIONS on LIST Replication
CONTENTS Replication refers to Repetition of objects as it
Lists Introduction:
is. Here, in LIST we can see NON-VECTORISED
operation with a list where the entire list as a
OPERATIONS whole is replicated.
ON List
Concatenation/Joining
NOTE: Vectorised operation, refers to the
replication of individual elements of the object.
Repetition/
Replication Replicating the unnamed List two times
Membership
Comparison of Lists
Functions/methods
Lists Slicing;
Nested lists;
finding the maximum, Replicating the named List RL four times
minimum, mean
linear search on list
counting the frequency
OPERATIONS on LIST Membership
Membership operator tests for Membership in a sequence.
CONTENTS Returns Boolean True or False
Lists Introduction: OPERATOR DESCRIPTION
OPERATIONS
in Results to True value if it finds a variable at the LHS of in
ON List operator in the sequence mentioned in the RHS of the in
operator, else it returns False
Concatenation/Joining
Repetition/ not in Results to True value if it does not find a variable at the
Replication LHS of in operator in the sequence mentioned in the RHS
of the in operator, else it returns False
Membership
in List
Comparison of Lists
Functions/methods
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
OPERATIONS on Comparison of LIST
CONTENTS Comparison of list returns Boolean True or False.
len(), list(),append(),
extend(), insert(),
count(),index(), remove(),
pop(), reverse(), sort(),
min(), max(), sum(),clear()
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list NOTE: Python language is case-sensitive.
counting the frequency Here, Z is the List object , so, z in small letters gives an error.
Functions / Methods on LIST-append()
CONTENTS The append() function takes one single parameter
and adds exactly one element at the end of the List.
Lists Introduction: It takes exactly one element and returns no value.
Operations on a list
Functions/
methods Here, append() function takes one single
parameter . In this example, 30.
len(), list(),append(),
extend(), insert(),
count(),index(), remove(),
pop(), reverse(),
sort(),min(), max(),
sum(),clear()
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
Functions / Methods on LIST-extend()
CONTENTS The extend() function adds iterable (Eg. Another List/
Lists Introduction:
Tuple/String) at the end of the List.
Operations on a list
Functions/methods Here, trying to extend list A , with another
len(), list(),append(), unnamed List containing one element [30].
extend(), insert(), Here, trying to extend list A , with
count(),index(), remove(),
another unnamed List containing
pop(), reverse(), sort(),
three elements [4,50,77].
min(), max(), sum(),clear()
Lists Slicing; Here, trying to extend list A , with
Nested lists; another named List B containing
finding the max,min, mean three elements
linear search on list *‘know’,’python’,’bytes’+
counting the frequency
Here, trying to extend list A , with a number 10. Hence error !!!
Here, trying to extend list A , with an unnamed tuple with two values
remove(), pop(),
reverse(), sort(),min(), max(),
sum() , clear()
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
Functions / Methods on LIST- pop()
CONTENTS pop( ) method is used to remove the item from the list.
It takes one optional argument . The element being deleted
is returned by the method
Lists Introduction:
Operations on a list
DIFFERENCE between pop() and
Functions/ remove()
methods The pop( ) method removes an
len(), list(),append(), individual item (from the right most
extend(), end by default) or the
insert(),count(),index(), value/element present at the index
number mentioned in the parameter
remove(), pop() , and returns it. Whereas remove( )
reverse(), sort(),min(), searches the first occurrence of the
max(), sum() , clear() item and removes it from the list
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
Functions / Methods on LIST- reverse()
CONTENTS
Lists Introduction:
Operations on a list reverse( ) method,
Functions/ reverses the items of the list.
This doesn’t create a new list.
methods It takes no argument and return no list.
len(), list(),append(), extend(),
insert(),count(),index(), Reverses the list ‘in place’ and does not
remove(), pop(), return anything.
reverse(), sort(),min(),
max(), sum(),clear()
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
Functions / Methods on LIST- sort()
CONTENTS sort( ) method,
Lists Introduction: sort( ) method and sort(reverse=True ) sorts or
Operations on a list orders the items of the list, by default in increasing order.
methods
len(), list(),append(),
extend(),
insert(),count(),index(),
remove(), pop(), reverse(),
sort(),min(), max(),
sum() , clear() NOTE: The sort( ) method
Lists Slicing; won’t be able to sort the
Nested lists; values of a list if it contains
finding the maximum, complex numbers/tuple
/ mixed datatype as its
minimum, mean elements.
linear search on list
counting the frequency
Functions / Methods on LIST- min(),max(),sum()
CONTENTS min( ) method,
Lists Introduction: Returns the minimum out of the elements/values/items of
Operations on a list the given List
Functions/
max( ) method,
methods Returns the maximum out of the elements/values/items of
len(), list(),append(), the given List
extend(),
insert(),count(),index(), sum( ) method,
remove(), pop(), reverse(),
Returns the sum of all the values/elements/items of the
min(),
sort(), given List.
max(), sum() ,
clear()
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
Functions / Methods on LIST- min(),max(),sum() contd..
List of string . Maximum
and Minimum is done on
the basis of the ASCII
values of the characters
from the beginning.
Eg. ‘A’=65, ‘a’ = 97, ‘b’=98
and so on
A List with
mixed data
type cannot
return values
for the min,
max and
sum
functions.
Functions / Methods on LIST- clear()
CONTENTS
Lists Introduction:
Operations on a list clear( ) method,
Functions/ removes all the items from the list and
methods the list becomes empty after executing
len(), list(),append(), this function.
extend(),
insert(),count(),index(),
remove(), pop(), reverse(),
sort(),min(), max(), sum() ,
clear()
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
LIST slicing
L[start:stop] creates a list slice out of list L with elements falling between
indexes start and stop, not including value at the stop index.
Start index 5, stop index is 50 which is beyond the last index in forward
direction. Hence, it will stop at the last index
Start index -10(which is ‘Y’ as per the backward index,) stop index is 12-1=11
(forward indexing). Hence, it will stop at the (stop index-1)., ‘Y’ is at 11 index no.
LIST SLICING contd.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
K N O W P Y T H O N B Y T E S
-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
Start index -3(backward), stop index is -12(backward). Here, it is not getting
any value in the range as no step value mentioned in reverse. Hence empty.
Default start and stop is beginning and end index of the list. Here, step is 3.
NESTED LISTS
CONTENTS Enclosing List
Lists Intro
Operations on a list
Functions/methods
Nested List 1 Nested List 2
Lists Slicing;
Nested lists;
finding the maximum,
minimum, mean
linear search on list
counting the frequency
CONTENTS
Lists Intro
Operations on
a list
Functions/
methods
Lists Slicing;
Nested lists;
finding
the
maximum
, minimum, mean
linear search
on list OUTPUT
counting the
frequency
Program to find the MINIMUM element from a list of element along
with its index in the list without using min() library function
CONTENTS
Lists Intro
Operations on a
list
Functions/
methods
Lists Slicing;
Nested lists;
finding
the
minimum,
maximum , mean
linear search
on list OUTPUT
counting the
frequency
Program to find the MEAN (AVERAGE) of all the elements of
the list
CONTENTS
Lists Intro
Operations on a
list
Functions/
methods
Lists Slicing;
Nested lists;
finding
the mean,
maximum,
minimum
linear search
on list
counting the OUTPUT
frequency
Program to search an element in the List (LINEAR SEARCH)
CONTENTS
Lists Intro
Operations on a
list
Functions/
methods
Lists Slicing;
Nested lists;
finding the
mean, maximum,
minimum
linear
search on
list
counting the
frequency OUTPUT
Program to count frequency (/no. of times of occurrence) of an element in the List
(FREQUENCY COUNT)
CONTENTS
Lists Intro
Operations on a
list
Functions/
methods
Lists Slicing;
Nested lists;
finding the
mean, maximum,
minimum
linear search
on list
counting
the OUTPUT
frequency
Bibliograhy and References
• Google
• Wikipedia
• XI Computer Science , By Sumita Arora,
Dhanpat Rai Publication 2020 Edition
• XI Informatics Practices , By Sumita Arora,
Dhanpat Rai Publication 2020 Edition
Programming is an ART….
Add your colours to it and make your own