Python reduce ♻️
HTML-код
- Опубликовано: 10 сен 2024
- Python reduce function tutorial example explained
#python #reduce #function
reduce() = apply a function to an iterable and reduce it to a single cumulative value.
performs function on first two elements and repeats process until 1 value remains
# reduce(function, iterable)
import functools
letters = ["H","E","L","L","O"]
word = functools.reduce(lambda x, y,:x + y,letters)
print(word)
factorial = [5,4,3,2,1]
result = functools.reduce(lambda x, y,:x * y,factorial)
print(result)
Bro Code merch store 👟 :
===========================================================
teespring.com/...
===========================================================
# reduce() = apply a function to an iterable and reduce it to a single cumulative value.
# performs function on first two elements and repeats process until 1 value remains
#
# reduce(function, iterable)
import functools
letters = ["H","E","L","L","O"]
word = functools.reduce(lambda x, y,:x + y,letters)
print(word)
# factorial = [5,4,3,2,1]
# result = functools.reduce(lambda x, y,:x * y,factorial)
# print(result)
Man, you explained it so simply. I spent a whole week trying to understand what it does until I found this video. Thank you so much, bro ❤👊
Hello sir, thanks for this kind of content it really helps specially we are now in online class. Im newly subscriber of you're youtube channel Godbls and more power ❤🙏
From zambonga philippines🥰
thanks Erwin! Hello from the USA!
This guy is awesome!
I agree
🐐
I know this is a big thing to ask but could you maybe create a video thats around 1 hour long explaining all the features of functool? (the things we would want to use would do too) You can get views with that video too i believe. :)
not a bad idea!
To the point so easy to understand. Thank you.
Thanks Bro, pretty sure I will be able to use reduce function at some point
Wow now i can use one line of code to find factorial of a number
Bro code you are my favorite mentor
great as always !!
Спасибо!
excellent. you made it easy to understand
VERY NICE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Simple and to the point
wow it's very helpful, Thanks bro
Thanks bro, You saved me.
thanks
thanks a lot , this was helpful
good video, thank you
nice explanation, man! Thank you so much!
Wow!
meow~!
Thank you!
Cool story
yo!
yooooo
Is there a way to reset the accumulator in the reduce function? for example when ur tryna get the sublist of a list
I have some questions for this video. How does comma(,) work and what is its duty ? Can I remove it ?
(lambda x, y--> ,
that's a typo
good video
You upload a lot of videos in a batch, why not one video per day or something like that?
I was losing subscribers :(
I think that people we're getting annoyed by the daily uploads if it wasn't their preferred language
@@BroCodez but for the algorithm is it not better to have several videos in several days instead of several videos in one day?, that would make more people watch your channel and you could have more subscribers than you are losing or what you think?
@@BroCodez u make good videos!
Would love a video on proper architecture/layout of folders and files of an app
MY Random comment ❤
comment
commenrt
We can simply use join()
# Mad libs game
adjective1 = input("Enter an adjective : ")
noun = input("Enter a noun :")
adjective2 = input("Enter another adjective : ")
verb = input("Enter a verb :")
adjective3 = input("Enter an adjective: ")
print("---------------MAD LIB GAME IS------------")
print(f"Today I went to a {adjective1} zoo.")
print(f"In an exhibit I saw {noun}")
print(f"{noun} was {adjective2} and {verb}ing")
print(f"I was {adjective3}")
Enter an adjective : suspicious
Enter a noun :Mark Zuckerberg
Enter another adjective : scary
Enter a verb :meow
Enter an adjective: amazed
--------------- MAD LIB GAME IS ------------
Today I went to a suspicious zoo.
In an exhibit I saw Mark Zuckerberg
Mark Zuckerberg was scary and meowing
I was amazed
reduce: "E","A","S","Y"
Wow!