Nested list comprehension : Python tutorial 135

preview_player
Показать описание
8Guys please help this channel to reach 20,000 subscribers. I'll keep uploading quality content for you.

Python is easy programming language to learn and anyone can learn it, and these tutorials are 100% free in hindi.

You can share this playlist with your brother, sisters and friends. This will surely add some values to their life.

If you follow this complete playlist of python tutorial surely you will learn everything about python programming language.

This video is all about nested list comprehension.

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

Simply do like this:
print([list(range(1, 4)) for i in range(3)])

RaviKumar-dong
Автор

Sir after completing please make full complete video series on Web developer in python.. Flask, Django..

chinmaydas
Автор

Bhai aap bahut acha video banate ho.
Thank you.

AniketKumar-bmgi
Автор

good job buddies 👍 salute for your hard work

OmJoshi_
Автор

your lectures are really amazing please R programming ki playlist bhi bna do

tanishalakhotia
Автор

# Normal method
myList1=[]
tempList=[]
for i in range(3):
tempList.clear()
for j in range(1, 4):
tempList.append(j)
myList1.append(tempList)
print(myList1)

manishverma
Автор

Their must be some more exercises on list comprehension
and mainly on nested list...

_VaibhavBaranwal
Автор

Can we use elif statement in list comprehension?

_itz.ricky._
Автор

Can you compare or match a nested list with a flatten

Dopeboyz
Автор

a = [[1, 2, 3] for i in range(3)]
print(a)

srikanthnaik
Автор

Let me tell ya an easy way :-
a = [[ i for i in range(1, 4) ]]*3
Output :- [[1, 2, 3], [1, 2, 3], [1, 2, 3]]


Try to put that *3 between square brackets and see the output... Always try something new...

kunalsingh-ppgp
Автор

if we are using 'i' in place of' j ' then how is it working correctly ..it should be wrng ... i mean how the nested loop working if both the variables are same

joydeepbhandary
Автор

Sir I have a question that if we want to make a list like
example=[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
is it possible to make a list like this with nested comprehension?

naumanhaider
Автор

# elif statement using list comprehenssion

numbers = [10, -5, 0, 3, -1, 8]
categories = ['positive' if num > 0 else 'negative' if num < 0 else 'zero' for num in numbers]
print(categories)

# output
['positive', 'negative', 'zero', 'positive', 'negative', 'positive']

# Explaination:
# 'positive' if num > 0: This is the if condition. If num > 0, it returns 'positive'.

# else 'negative' if num < 0: This part is the elif condition. If the first condition (num > 0) is False, then it checks whether num < 0. If num < 0 is True, it returns 'negative'.

# else 'zero': This is the else condition. If neither num > 0 nor num < 0 are True (meaning num == 0), it returns 'zero'.

Shubham-djk
Автор

Is this list comprehension code work for all versions of python
Or
Only for 3.6

rojapolaki
Автор

what if I want to put different items in the list?

sanjeevtudu
Автор

is se to list k ander sub lists sb aik hi tarah ki hon gi

m.mubashar
Автор

Newlist=[[1, 2, 3]] for i in range (3)
Print(newlist)

nirock
Автор

sir what about make a list from user defined value, in list all values is integer. not string..


i tried to many time about this,
but i always got string value in list

give me solution about this..

tipsstudio
Автор

how to acheieve with the below code matrix=[[1, 2, 32], 43, 4, [3, 7], [8]]

new_matrix=[]
for sublist in matrix:
if type(sublist) is list:
for j in sublist:
print(j)
new_matrix.append(j)
else:
new_matrix.append(sublist)


print(new_matrix) this is by simple way but cant do with comprehnsio help me here pls

johnmartin
join shbcf.ru