Professional Documents
Culture Documents
Day’s Split up
Evaluation Criteria
Topics
list.remove(value): remove() removes the first matching value/object. It does not do anything with the indexing.
myList.remove(2)
o/p: [1, 3, 2]
o/p: [1, 3, 2]
list.pop(index): And pop removes the item at a specific index and returns it.
a = myList.pop(2)
print(a)
o/p: 3, [1,2,2]
Python Lists
● reverse() method: It reverses a list
● any() method: It checks if any Element of an Iterable is True
● sorted() method: sorted() returns sorted list from a given iterable
>>> a = [1, 2, 3, 4, 5, 6, 7, 8]
>>> a[1:4:2]
[2, 4]
>>> a[::2] (every second element from start to end)
[2,4,6,8]
>>> a[::-1]
[8, 7, 6, 5, 4, 3, 2, 1, 0]
Set Operations (union, intersection,
difference and symmetric difference)
● INPUT:
A= {0,2,4,6,8}
B= {1,2,3,4,5}
1. UNION: print(“Union : ”, A | B)
2. INTERSECTION: print(“Intersection : ”, A & B)
3. DIFFERENCE: print(“Difference : ”, A - B)
4. SET DIFFERENCE: print(“Set Difference : ”, A ^ B)
● OUTPUT:
if x % 2 == 1:
odd_square.append(x**2) Condition
print odd_square Expression
O/P: [1, 3, 5, 7, 9]
LIST , SET and TUPLES
LIST TUPLES SET
Heterogeneous, Can hold Heterogeneous,Can hold Does not hold duplicate values
duplicate values. duplicate values. and is unordered: there is no
way we can use indexing to
access or delete its elements
List is slower than tuple: Set are faster than list in terms
because list are mutable , with of accessing or removing an
any changes done a new element(hash table)
object space is made
Python Dictionary
●get() method : It returns Value of The Key
dic = {"A":1, "B":2}
print(dic.get("A"))
o/p: 1
●update() method : Update method is used to modify the value of any existing
element
d = {1: "one", 2: "three"}
d1 = {2: "two"}
# updates the value of key 2
d.update(d1)
print(d)
O/P: {1: 'one', 2: 'two'}
Lambda Function
● In Python, anonymous function is a function that is defined without a name
● Normal functions are defined using the def keyword, in Python anonymous
functions are defined using the lambda keyword
Reduce: is a really useful function for performing some computation on a list and returning the result.
from functools import reduce
product = reduce((lambda x, y: x * y), [1, 2, 3, 4]) # Output: 24
np.linspace, np.arange, np.Random
np.arange(start, stop,step size) np.linspace(start, stop,number of sample)