More on list comp and generators - Intermediate Python Programming p.5

preview_player
Показать описание
Welcome to part 5 of the intermediate Python programming tutorial series. In this part, we're going to talk more about list comprehension and generators.

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

One of the beautiful things about the internet, is that a great course like this is available years after it was published on YouTube. Thank you so much, I'm having a lot of fun!

smebird
Автор

The most awesome part of this video happened in the last 30 seconds. Other people, don't make the mistake of skipping ahead to the next videos.

maxlee
Автор

I'm sitting here, drinking a glass of red wine, waiting patiently for the full release of the nnfs book, brushing up on my coding, and I'm very happy about it.

ConorFenlon
Автор

i think this is one of the most elegant parts of Python. Syntax is so clean!

iVandal
Автор

n=int(input("enter a number "))

[print(i) for i in (item for item in range(n) if item % 2==0)]
printing values of generator series in single line

krishnasrujan
Автор

Quick tip if you want build a list or tuple out of generator
x = (i for i in range(20)) # A generator
y = [*x] # unpack generator or y = (*x, ) # to build a tuple

mohisolanki
Автор

15:05 - This also works! :

for i in (print(i) for i in range(5)):
pass

MultiSokom
Автор

This intermediate Python course is awesome, it's exactly what I've been looking for. Thanks!

esclavosoy
Автор

At 15:05, you don't need to state 'i' in the for loop, right? You may as well

for i in xyz:
pass

And you still get the prints, since the five prints are called upon iteration.

On a somehow related note,

xyz = [print(i) for i in range(3)]
#1
#2
#2

print(xyz)
# [None, None, None]

for i in xyz:
print(i)
# None
# None
# None

right?

And youtube needs markdown.

_adaldo
Автор

Thank you, this is the very series I am looking for

rotrose
Автор

(print(i) for i in x)
In the above case what will be stored in memory. I am getting the following output if I am trying to execute the following set of instructions

Program::
input_list = [2, 4, 6, 8, 9, 23, 45, 78, 90, 6576, 75, 8797, 980]

def div_by_two(num):
if num % 2 == 0:
return True
else:
return False

x = [i for i in input_list if div_by_two(i)]
z = (print(i) for i in x)
for i in z:
print (i)

## Output comes this. What is the meaning of None here?
2
None
4
None
6
None
8
None
78
None
90
None
6576
None
980
None

gautamkumargupta
Автор

Although this tutorial does what it was intended for, I feel like map and filter should've been mentioned from the start.

I really like the intermediate Python tutorials,
keep up the good work!

theJUSTICEof
Автор

SELECT column FROM table WHERE condition 1 <logic operation> condition 2. Quite similar. In python 3 I will try if works the second condition. Interesting. That is just a query not a hole comparison computation.

andreisima
Автор

you can shorten the body of div_by_five() to return num % 5 == 0

serhiy
Автор

u can just use

def div_by_5(num):
return num%5==0

Nemonamir
Автор

the generator "xyz = (print(i) for i in range(5))", and "for i in xyz: i"...

I got the same result using "for i in xyz: pass" instead of "for i in xyz: i", and I did "for i in xyz: print(i)" then it shows "0; none; 1; none; 2; none and so on".

Maybe each "i" did not meaning print(i) but the return value of print(i), I think.

eunsolhong
Автор

i don't understand first time i do myself and see the video again and again until i understand completely #this is just my opinion for learning

tkdevlop
Автор

The last was mind blowing where you just used i instead of print(i) cause "i" it self was an object of print() that was like so logical and mind blowing just loving your videos a great explanation Thank you so much.

I would so much like to add you as a friend on fb please let me know if I can add you ^_^

abhi-musicma
Автор

I started out understanding, got confused as you stumbled, and then understood again once you understood what you were trying to say. This was a longer but better explanation than the one I looked at earlier today. Do you put a lot of planning into what you are going to say?
The nesting is a bit mad though. Seems like it could be more human readable, which I thought was the point of python, if it were a different syntax. If I ever get deep enough in this I might write a generator creation function.

finfan
Автор

Running the code (xyz = (i for i in input_list if div_by_five(i)) and then printing the elements of xyz also prints a list of None at the end on idle. Any idea why?

NitinChauhan-vhyk
join shbcf.ru