Python Comprehensions | Python Tutorials For Absolute Beginners In Hindi #73

preview_player
Показать описание

This video talks about list comprehensions,

Best Hindi Videos For Learning Programming:

Follow Me On Social Media
Рекомендации по теме
Комментарии
Автор

no_of_list = int(input("How many items add in a list: "))
input_string = input("Enter a list element separated by space ")
list = input_string.split()
t = int(input("Which type of comprehension you use 1. List Comprehension 2.Dictionary Comprehension 3. Set Comprehension "))
if t==1:
ls = [i for i in list]
print(ls)
print(type(ls))
elif t==2:
dict1 = {f'item{i}': i for i in list}
print(dict1)
print(type(dict1))
elif t==3:
s ={i for i in list}
print(s)
print(type(s))

hamadshigri
Автор

num = int(input("How many elements you want to add: "))
input_elements = input("Enter elements separated by space: ")
List = input_elements.split()

choice = input('''
Which type of Comprehension you want to create?
A. For List Comprehension
B. For Dictionary Comprehension
C. For Set Comprehension
D. For Generator Comprehension

-->
''')
if choice == 'A':
list1 = [a for a in List]
print(list1)
print(type(list1))

elif choice == 'B':
Dict1 = {a : f" Item{a} " for a in List}
print(Dict1)
print(type(Dict1))

elif choice == 'C':
Set1 = {a for a in List}
print(Set1)
print(type(Set1))

elif choice == 'D':
Generator1 = (a for a in List)
print(Generator1)
print(type(Generator1))
else:
print("Invalid Input!")

hariomsinghrajput
Автор

Sir YOU ARE doing a great job
I started watching YOUR video's
I am learning it in a sequence
Thank you
Keep posting and help us

abdqnews
Автор

Awesome work! I completed my python course with you Harry Bhai! I wanted to revise list comprehensions and hence watching the video second time :) . Thanks a lot for these awesome stuff !

Easy
Автор

This is my code

print("what do you want to put in the comprehension")
comp = str(input())



print("what kind of comprehension do you want to make ")
print("press 1 for list comprehension ")
print("press 2 for set comprehension ")
print("press 3 for dictionary comprehension ")
comp2 = int(input())

if comp2 == 1:
list2 = [i for i in comp]
print(list2)
print(type(list2))


if comp2 == 2:
set3 = {item for item in [comp]}
print(set3)
print(type(set3))

if comp2 == 3:
dict23 = {item: f"this is dict object {comp}"for item in range(1)}
print(dict23)
print(type(dict23))

Cinemindhub
Автор

n = int(input("How many items do you want to add to your inventory: "))
i = 0
l = []
while(i<n):
a = input("Enter the item: ")
l.append(a)
i += 1

choice = int(input("Press '1' for generating a list comprehension\nPress '2' for generating a set comprehension\nPress '3' for generating a generator comprehension: "))

if choice == 1:
list = [item for item in l]
print(list)

elif choice == 2:
set = {item for item in l}
print(set)

elif choice == 3:
gen = (item for item in l)
for c in gen:
print(c)

insightful
Автор

num = int(input("Enter number of items do you want to add to your inventory: "))
i = 0
ls = []
while(i<num):
a = input(f"Enter the item {i}: ")
ls.append(a)
i += 1

choice = int(input("Enter '1' for generating a list comprehension\n"
"Enter '2' for generating a set comprehension\n"
"Enter '3' for generating a generator comprehension: "))

if choice == 1:
list = [item for item in l]
print(list)

elif choice == 2:
set = {item for item in l}
print(set)

elif choice == 3:
gen = (item for item in l)
for c in gen:
print(c)

-sanjaybalam
Автор

your videos are great and you also of course
btw quiz is sloved :-
list1 = []
a = int(input("How many element do you want: "))
for i in range(a):
var = input(f"Enter element {i+1}: ")
list1.append(var)
print("Which comprehension you want make")
print( "Enter 1 for list comprehensions\
2 for set comprehensions\
3 for dictonary comprehensions"
)
ch = int(input(": "))
if ch==1:
L1 = [x for x in list1]
print(L1)
elif ch==2:
L2 = {y for y in list1}
print(L2)
elif ch==3:
L3 = {f"{item+1} item":index for item, index in enumerate(list1)}
print(L3)

sumittiwari
Автор

a=[]
num=int(input("how many items you wants to add:"))
str=input("enter name you want to add separated by comma ")
a=str.split(", ")
if num==len(a):
com_type=int(input("Which type of comprehension you use 1. List Comprehension 2. Dictionary Comprehension 3. Set Comprehension "))
if com_type ==1:
b=[item for item in a]
print(b)
elif com_type==2:
b={f"item{i+1}":a[i] for i in range(0, len(a))}
print(b)
elif com_type==3:
b={item for item in a}
print(b)
else:
print("enter a valid com_type ")
else:
print("learn counting then run the code")

hsxzfih
Автор

val = int(input("how many items you want to take input"))
p = []
for i in range(val):
l = input(f"enter {i}st/th string : ")
p.append(l)

inp = int(input("for list enter 1 \n for dict enter 2 \n for set enter 3 : "))

if inp == 1:
print(type(p))
elif inp == 2:
p = dict.fromkeys(p)
print(type(p))
elif inp == 3:
p = (i for i in p)
for i in range(inp):
print(p.__next__())
else:
print("error")

SahilKumar-nisu
Автор

print("What do you want to comprehenson? 'list', 'dict', 'set' :")
x = input()
if x == "list":
n = int(input("Enter no. of item:"))
print("Enter your list value:")
b =[input() for i in range(n) if i<n ]
print(b)
elif x == "dict":
n = int(input("Enter no. of item:"))
b = { input("Enter key:") : input("Enter Value:")for i in range(n) if i <n}
print(b)
else:
n = int(input("Enter no. of item:"))
print("Enter your set value:")
b = {input() for i in range(n) if i <n}
print(b)

KNOWLEDGE_ISS_EVERYTHING
Автор

n=int(input("enter the number of input elements"))
i=1
l2=[]
while i<=n:
inp=input(f"enter element no. {i}")
l2.append(inp)
i+=1
com=input("enter which comprehension you want to use: list or dict or set")
if com=="list":
l2=[i for i in l2]
print(l2)
elif com=="dict":
l2={i:"value" for i in l2}
print(l2)
else:
l2={i for i in l2}
print(l2)

shivanshutyagi
Автор

num_item = int(input("Enter the number item you want to add-"))
lst_item = []
for i in range(num_item):
lst_item.append(input())

print("Which type of comprehension you want to make-")
print("1. List Comprehension")
print("2. Set Comprehension")
print("3. Dictionary Comprehension")

user_choice = int(input())

if user_choice not in [1, 2, 3]:
print('Invalid choice')

elif user_choice == 1:
lst = [i for i in lst_item]
print(lst)
elif user_choice == 2:
sett = {i for i in lst_item}
print(sett)
elif user_choice == 3:
dicct = {k: f'item{lst_item.index(k)}' for k in lst_item}
print(dicct)
else:
print("You can not make anything other than this")

souravmallik
Автор

noi = int(input("no of items you want to enter \n"))
list1 = input("enter the elements of list separated by ', ' \n")
list0 = list1.split(", ")
list0 = list0[:noi]
cpre = int(input("Which Comprehension do you want : \n"
"1 : List \n"
"2 : Dictionary \n"
"3 : Set \n"))
if cpre == 1:
lss = [items for items in list0]
print(lss)
elif cpre == 2:
res = dict(zip(range(1, noi+1), list0))
print(res)
elif cpre == 3:
lss = {items for items in list0}
print(lss)

sewp
Автор

#ye lo harry bhai aur aapka bohot bohot dhanyawad

print("how many items do you want in your list")
inp = int(input())
list1 = []
for i in range(inp):
a = input(f"Enter{i+1} item")
list1.append(a)
print("Enter the comprehension to be converted")

choose = int(input("enter your choise\n"))
if choose == 1:
print(list1)
elif choose == 2:
dict1 = {i:j for i, j in enumerate(list1)}
print (dict1)
elif choose == 3:
set1 = {i for i in list1}
print(set1)
else:
print("Wrong Choice")

Swarnimshow
Автор

no_of_inputs = int(input(print("How many inputs do you want to give?\n")))

for i in range(no_of_inputs):

while i>-1:
i = i - 1
inputs = int(input(print("Enter your input here!")))

break

comprehension = int(input(print("Press 1 for list comprehension.\nPress 2 for dictionary comprehension.\nPress 3 for set comprehension.")))
if comprehension == 1:
list = [i for i in range(inputs)]
print(list)

if comprehension == 2:
dic = {i:f"item{i}" for i in range(inputs)}
print(dic)

if comprehension == 3:
set = {i for i in [inputs]}
print(set)

ManjotSingh-sfqn
Автор

lst = []
size = int(input("How many items u want to enter? "))
for i in range(size):
n=input("Enter elements saperated by space :")
lst.append(n)

choice = int(input("Which type of comprehensions u want ? /n1. List comprehension /n2. Dictonary comprehension /n3. Set comprehension"))
if choice==1:
l=[i for i in lst]
print(l)
elif choice==2:
dict = {f"item{i} ":i for i in lst}
print(dict)
elif choice==3:
set = {i for i in lst}
print(set)

anukumari
Автор

num=[]
ask=int(input("HOW MANY NAME YOU WANT TO ENTER..?=>"))
i=1
while(i<=ask):

i=i+1
print(num)
comp=input("which type of comprehension you want? \ns=>set \nl=>list \nd=>dictionary \n-->")
if comp=="s":
Clas1={c for c in num}
print(type(Clas1))
print(Clas1)
elif comp=="l":
clas2=[c for c in num]
print(type(clas2))
print(clas2)
elif comp=="d":
clas3={x:c for c in num for x in range(ask)}
print(type(clas3))
print(clas3)
else:
print("ENTER CLASS NAME CORRECTLY")

asjadrizvi
Автор

n=int(input("How many items do you wanna input"))
l=[]
for i in range(1, n+1):
a=input(f"Enter input no {i}")
l.append(a)
print("Press L for list comprehension D for dictionary comprehension S for set comprehension")
inp=input()
if inp=="L":
li=[i for i in l]
print("List comprehension is", li)
elif inp=="D":
di={f"item {j}":j for j in l}
print("Dictionary comprehension is", di)
elif inp=="D":
se={j for j in l}
print("Set comprehension is", se)
else:
print("Invalid input")

Rud
Автор

a=int(input("enter your number"))
b=int(input("enter waht do you want to perform 1 2 3"))


list =[j for j in range(a) if b==1]
set=[j for j in range(a) if b==2]
dict={j:f"item" for j in range(a) if b==3}
if b==1:
print(list)
elif b==2:
print(set)
else:
print(dict)

deepakmehta