KEMBAR78
ML-LAB 01.ipynb - Colab | PDF | Chess Theory | Chess
0% found this document useful (0 votes)
23 views3 pages

ML-LAB 01.ipynb - Colab

Uploaded by

Saptarshi Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

ML-LAB 01.ipynb - Colab

Uploaded by

Saptarshi Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

8/28/25, 1:19 ML-LAB 01.

ipynb -
PM Colab

1. perform

insert,remove,append,len,pop,clear in a list

saptarshi das - 2447028

arr = [1,2,3]
arr.insert(1,1000)
arr.remove(2)
arr.append(12
) len =
len(arr)
arr.pop()
print(arr)
arr.clear()
print(arr)

[1, 1000, 3]
[]

2. dictionary

Double-click (or enter) to edit

hash =
{1:"shubham",2:"ashish",3:"saptrishi",4:"saurabh",5:"tanay"}
for name in hash:
print(f"{name} : {hash[name]}")

hash.get(1)
hash[2] =
"changed"
print(hash)
# length =
len(hash) #
print(length)

1 : shubham
2 : ashish
3 : saptrishi
4 : saurabh
5 : tanay
{1: 'shubham', 2: 'changed', 3: 'saptrishi', 4: 'saurabh', 5: 'tanay'}

3. tupple

tup = (1,2,3)
print(tup[1])
for item in
tup: if item
== 2:
print(True)
break
print(tup)

2
True
(1, 2, 3)

4. largest in n numbers

import sys
def
largest(*numbers):
max = -
sys.maxsize-1
https://colab.research.google.com/drive/ 1/
1f_fDU2c_twBGJ9NIGSMYbR2jPtfNP1Es#scrollTo=BY1WP8Hq0hWm&printMode=true 3
8/28/25, 1:19 ML-LAB 01.ipynb -
PM Colab

for num in
numbers: if num
> max:
max = num
return max
largest(1,2,5,4)

https://colab.research.google.com/drive/ 2/
1f_fDU2c_twBGJ9NIGSMYbR2jPtfNP1Es#scrollTo=BY1WP8Hq0hWm&printMode=true 3
8/28/25, 1:19 ML-LAB 01.ipynb -
PM Colab
5. compare list

def compareList(list1,list2):
return
list1==list2 list1 =
[1,2,3,4]
list2 = [1,2,5,4]
compareList(list1,list2)

False

6. filter()

numbers = [x for x in
range(21)] def is_even(num):
return num % 2 == 0
even_numbers_iterator = filter(is_even, numbers)
even_numbers_list = list(even_numbers_iterator)
print(even_numbers_list)

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

numbers = [x for x in
range(10)] def double(num):
return num*2
double = map(double,numbers)
new_list = list(double)
print(new_list)

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]

7. reduce()

from functools import reduce


numbers = [x for x in range(3)]
l = reduce(lambda
x,y:x+y,numbers) print(l)

https://colab.research.google.com/drive/ 3/
1f_fDU2c_twBGJ9NIGSMYbR2jPtfNP1Es#scrollTo=BY1WP8Hq0hWm&printMode=true 3

You might also like