[Python Programming Basics to Advanced] : Sets in Python | Lab 23

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

In this lesson we will learn about Sets in Python. The data structure Set in Python follows the same rules as we see in Set Theory. A set does not have any order and it can not have the repeated elements.
We will see how we can use sets efficiently in different cases.

Following Tasks are completed:
Strong Password 10:23
Grid Paths 15:31
Finding the second largest number in a List 18:24
Set Comprehension 19:22

Mutable vs Immutable is discussed here:

List Comprehension is Discussed here:

Complete Playlist:

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

Lab Manual 23 can be downloaded from here:

Review Questions:
Suppose you have two lists names as a and b containing some numbers. You need another list as common elements between the lists a and b except the first and the last number of the list a.

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

a=[22, 56, 89, 98, 9, 34]
x=a[1:-1]
e=set(x)
b=[2, 5, 4, 22, 45, 98, 34]
f=set(b)
print(f"the common element is {e.intersection(f)}")

shahwarsadaqat
Автор

Assalam-o-Alaikum Sir!
Review question:
a=[12, 25, 38, 45, 56]
b=[9, 25, 33, 54, 67]
print(f'a:{a}')
print(f'b:{b}')
x=a[1:-1]
c=set(x).intersection(set(b))
print(c)

zainzakir
Автор

a=[10, 11, 12, 13, 14, 15, 16, 17]
b=[7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
c=list(set(a[1:-1])&set(b))
print(f'Common Elements of both lists except first and last element of list a: {c}')

usman_tariq
Автор

a={1, 2, 3, 4, 5, 6, 7}
b={1, 2, 3, 7, 6, 4}
c=list(a)
c.remove(c[0])
c.remove(c[-1])
x=b.intersection(c)
print(x)

AliHamza-zwvt
Автор

a=[1, 3, 5, 7, 9, 11]
x=a[1:-1]
b=[1, 2, 3, 4, 5, 6, 11, 8, 7]
c=list(set(x)&set(b))
print(f"Common elements except first and last element of list a :{c}")

yusrakashif
Автор

a=[1, 2, 3, 4, 5, 6, 7, 8, 9, 13, 17]
b=[1, 2, 13, 11, 17, 23, 14, 15, 6, 8]
(y))
print(f' Common elements are: {common}')

abdulrehmankhalid
Автор

a=[0, 1, 2, 3, 4, 5, 6]
b=[4, 5, 6, 8, 10, 15]
c=list(set(a[1:-1])&set(b))
print(f"the required set is: {c}")

waleedraza
Автор

a=[4, 55, 43, 80, 27, 9, 2]
b=[19, 55, 3, 80, 27, 96, 2]

print(c)

shaheerahmadkhan
Автор

A=[0, 1, 2, 3, 4, 5, 6, 7]
B=[5, 6, 7, 11, 12, 13, 14]
c=list(set(A[1:-1])&set(B))
print(f"Required list is: {c}")

dawood
Автор

x=[1, 2, 3, 4, 5, 6, 7, 8]
y=[1, 2, 13, 14, 15, 6, 17, 19, 8]
(y))
print(f'Common Elements are: {com}')

dawoodimtiaz
Автор

q1:
a = [1, 3, 5, 7, 9, 11, 13]
b = [1, 2, 3, 4, 5, 6, 8, 10]

hamidiftikhar
Автор

a=[1, 2, 4, 5, 6, 77]
b=[1, 6, 7, 8, 9, 5, 77]

print(c)

usmantariq
Автор

#Review question:
a=[12, 25, 38, 45, 56]
b=[9, 25, 33, 54, 67]
print(f'a:{a}')
print(f'b:{b}')
x=a[1:-1]

print(c)

SafiUllah-kgku
Автор

x=[1, 3, 5, 7, 9, 10]
y=[1, 2, 4, 6, 8, 10, 12]

print(z)

laveezayasin
Автор

REVIEW QUESTION:
a=[1, 3, 4, 5]
b=[5, 4, 6, 8, 9]
common=set(a[1:-1])&set(b)
print(f'THE NEW COMMON ELEMENT IS {list(common)}')

MuhammadQasim-kwer
Автор

#review Question
a=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
c=a.copy()
b=[0, 1, 2, 3, 4, 5, 10]
del a[0]
del a[-1]
print(f'First list {c} ')
print(f'Second list {b} ')
print(f'Third list ')

huzaifasarwar
Автор

a=[1, 2, 3, 4, 5]
b=[1, 3, 5, 7, 9]
x=a[1:-1]

print(f'The New list is:{c}')

Fishy_gamedev_and_art
Автор

#Review Question:
a=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b=[0, 1, 2, 3, 4, 5, 10]

print(f"The Newlist: {c}")

rajahaseebahmad
Автор

## REVIEW QUESTION ##
a=[1, 2, 5, 7, 9, 12, 14]
b=[1, 3, 4, 8, 11, 12, 14]
x=a[1:-1]

print('List of common elements (except first and last number of the list a) is:')
print(c)

habibaasif
Автор

#review que#
a=[13, 21, 4, 2, 19, 17, 14]
b=[1, 3, 4, 8, 11, 12, 14]
x=a[1:-1]

print(f'The New list is:{c}')

ahmadlatif