[Python Programming Basics to Advanced] : List Operations and List Methods | Lab 17

preview_player
Показать описание
This Python programming playlist is designed to take beginners with zero programming experience to an expert level. The course covers installation, basic syntax, practical scenarios, and efficient logic building. The course material includes PDF handouts, review questions, and covers a wide range of topics, from data types to advanced functions like Lambda and Recursive functions, Generators, and JSON data parsing.

We started discussion on List in the last video. In this lesson we will explore different list operations and different list methods available in the List Class or as built-in functions of Python.
We will see many examples to use these operations.

Complete Playlist:

If you have the basic programming knowledge and interested to learn Object-Oriented Programming in Python, check out this playlist:

Lab Manual 17 can be downloaded from here:

Review Questions:
1- Given at 39:08
2- Create a list with different numbers and include 7 in it 3 or 4 times. Then write the logic that will give the index of last 7 inside the list. You have to use list methods and not the loop in this question.

#PythonProgramming #python #pythontutorial
Рекомендации по теме
Комментарии
Автор

#Review Q1:
a=[]
x=[]
y=[]
z=[]
while True:
b=eval(input("Enter a no.(-1 to exit):"))
if b==-1:
break
a.append(b)
print(a)
avg=sum(a)/len(a)


for i in a:
if i>avg:
x.append(i)
if i<avg:
y.append(i)
if i==avg:
z.append(i)
print(f" Numbers greater than average in the list={x}")
print(f" Numbers smaller than average in the list={y}")
print(f" Numbers equal to the average in the list={z}")


#Review Q2:

x=[7, 6, 4, 5, 6, 7, 7, 5, 3, 2, 0, 9]
y=x[::-1]
print((y.index(7)-1)+len(x))

asmaabhatti
Автор

Assalam-o-Alaikum Sir,
Task no 1:
a=[]
b=[]
c=[]
d=[]
while(True):
x=eval(input('Enter a number(-1 to exist): '))
if x==-1:
break
a.append(a)
print (a)
average=sum(a)/len(a)

for i in a:
if(i>=average):
b.append(i)
if(i<=average):
c.append(i)
if(i==average):
d.append(i)
print(f'Greater numbers are:{b}')
print(f'Smaller numbers are:{c}')
print(f'Equal numbers are:{d}')
Task no 2:
a=[2, 3, 6, 7, 5, 7, 3, 7, 0]
a.reverse()
print(len(a)-a.index(7)-1)

zainzakir
Автор

line=[2, 4, 6, 8, 3]
line.reverse()
print (line)
print (len(line) - line.index(7)-1)

zainulhassan
Автор

Ans 2:

test_list=[4, 89, 2, 3, 7, 5, 6, 7, 65, 86, 7, 36, 7, 0, 56]
print(f"The original list is: {test_list}")
test_list.reverse()
print(f"The reverse list is: {test_list}")

print(f'The index of last seven is: {y}')

abdurrehmansarwar
Автор

2nd Question :
SS=[1, 2, 4, 7, 8, 9, 7, 11, 7, 13, 7, 3, 15]
SS.reverse()
x=SS.index(7)
y=(len(SS)-x)
print(f'The index of last 7 is = {y-1}')

AliHamza-zwvt
Автор

Asslamualikum Respected sir.
I hope you are in good health and doing well.
I want to know one thing regarding to the function all() of the list. This function only checks the list if its all values are true or false. But my question is that whether there is any function of the list or python built-in-function which checks the certain value inside the list and if it exists then it returns true?

abdurrehmansarwar
Автор

lis= [7, 2, 7, 4, 7, 8, 4, 7, 7, 2, 9]
lis.reverse()
print(lis)

MuhammadQasim-kwer
Автор

det= [2, 6, 8, 7, 5, 6, 7, 4, 7, 2, 4]
det.reverse()
print(det)

waleedraza
Автор

Q2:
mat= [1, 7, 8, 7, 5, 6, 7, 7, 7, 2, 3]
mat.reverse()
print(mat)

dawood
Автор

exm= [7, 2, 7, 4, 7, 8, 4, 7, 7, 2, 9]
exm.reverse()
print(exm)

talhakamboh
Автор

#Review Q1:
a=[]
x=[]
y=[]
z=[]
while True:
b=eval(input("Enter a no.(-1 to exit):"))
if b==-1:
break
a.append(b)
print(a)
avg=sum(a)/len(a)


for i in a:
if i>avg:
x.append(i)
if i<avg:
y.append(i)
if i==avg:
z.append(i)
print(f" Numbers greater than average in the list={x}")
print(f" Numbers smaller than average in the list={y}")
print(f" Numbers equal to the average in the list={z}")


#Review Q2:

x=[7, 6, 4, 5, 6, 7, 7, 5, 3, 2, 0, 9]
y=x[::-1]
print((y.index(7)-1)+len(x))

#with loop q2
"""
## 2nd Review Question ##
x=[4, 6, 7, 8, 2, 7, 5, 1, 4, 7, 7, 8]
a=[]
for i in range(len(x)):
if(x[i]==7):
a.append(i)
print(f'Index of last (7) inside the list is: {max(a)}')
"""

zohaibkhalid
Автор

line=[2, 4, 6, 8, 3]
line.reverse()
print (line)
print (len(line) - line.index(7)-1)

abdullahmughal
Автор

#Review Q1:
a=[]
x=[]
y=[]
z=[]
while True:
b=eval(input("Enter a no.(-1 to exit):"))
if b==-1:
break
a.append(b)
print(a)
avg=sum(a)/len(a)


for i in a:
if i>avg:
x.append(i)
if i<avg:
y.append(i)
if i==avg:
z.append(i)
print(f" Numbers greater than average in the list={x}")
print(f" Numbers smaller than average in the list={y}")
print(f" Numbers equal to the average in the list={z}")


#Review Q2:

x=[7, 6, 4, 5, 6, 7, 7, 5, 3, 2, 0, 9]
y=x[::-1]
print((y.index(7)-1)+len(x))

#with loop q2
"""
## 2nd Review Question ##
x=[4, 6, 7, 8, 2, 7, 5, 1, 4, 7, 7, 8]
a=[]
for i in range(len(x)):
if(x[i]==7):
a.append(i)
print(f'Index of last (7) inside the list is: {max(a)}')
"""

abdulrehmansajid
Автор

#Review Q1:
a=[]
x=[]
y=[]
z=[]
while True:
b=eval(input("Enter a no.(-1 to exit):"))
if b==-1:
break
a.append(b)
print(a)
avg=sum(a)/len(a)


for i in a:
if i>avg:
x.append(i)
if i<avg:
y.append(i)
if i==avg:
z.append(i)
print(f" Numbers greater than average in the list={x}")
print(f" Numbers smaller than average in the list={y}")
print(f" Numbers equal to the average in the list={z}")


#Review Q2:

x=[7, 6, 4, 5, 6, 7, 7, 5, 3, 2, 0, 9]
y=x[::-1]
print((y.index(7)-1)+len(x))

#with loop q2
"""
## 2nd Review Question ##
x=[4, 6, 7, 8, 2, 7, 5, 1, 4, 7, 7, 8]
a=[]
for i in range(len(x)):
if(x[i]==7):
a.append(i)
print(f'Index of last (7) inside the list is: {max(a)}')
"""

mukarmarashid
Автор

#Review Q1:
a=[]
x=[]
y=[]
z=[]
while True:
b=eval(input("Enter a no.(-1 to exit):"))
if b==-1:
break
a.append(b)
print(a)
avg=sum(a)/len(a)


for i in a:
if i>avg:
x.append(i)
if i<avg:
y.append(i)
if i==avg:
z.append(i)
print(f" Numbers greater than average in the list={x}")
print(f" Numbers smaller than average in the list={y}")
print(f" Numbers equal to the average in the list={z}")


#Review Q2:

x=[7, 6, 4, 5, 6, 7, 7, 5, 3, 2, 0, 9]
y=x[::-1]
print((y.index(7)-1)+len(x))

#with loop q2
"""
## 2nd Review Question ##
x=[4, 6, 7, 8, 2, 7, 5, 1, 4, 7, 7, 8]
a=[]
for i in range(len(x)):
if(x[i]==7):
a.append(i)
print(f'Index of last (7) inside the list is: {max(a)}')
"""

wallisheikh