Transforming Code into Beautiful, Idiomatic Python

Поделиться
HTML-код
  • Опубликовано: 15 янв 2025

Комментарии • 661

  • @rafehqazi8539
    @rafehqazi8539 9 лет назад +1482

    Note to Python 3 Users:
    - izip is just zip
    - d.iteritems() is just d.items()
    - To use defaultdict: You have to do the following --> from collections import defaultdict

    • @suburbanmoscow9067
      @suburbanmoscow9067 8 лет назад +12

      Rafeh Qazi thx for the additional info

    • @CleverProgrammer
      @CleverProgrammer 8 лет назад +19

      Woah, did not notice my comment was sitting at 65 likes haha. I now have my own computer programming RUclips channel! Thanks for commenting Suburban and making me see this!

    • @suburbanmoscow9067
      @suburbanmoscow9067 8 лет назад +5

      You are welcome. I will check out your channel as well! Cheers

    • @javierRC82857
      @javierRC82857 8 лет назад

      Rafeh Qazi but in Python 2.7 zip is an iterator? izip,zip or range,xrange why not use iterator for everything and let the programmer choose if he want expand the list?

    • @nmertsch8725
      @nmertsch8725 7 лет назад +6

      Javier I'm not sure if this is what you asked for, but you can use "list(range(x))" or "list(zip(x,y))", if you really want to have a list instead of an iterable object.

  • @jeffkirchoff14
    @jeffkirchoff14 3 года назад +8

    Man YT recommended it after 8 yrs
    In search of gold I found diamond

  • @PedroTeixeira
    @PedroTeixeira 5 лет назад +34

    I’ve been using Python for over a decade (informally trained) and haven’t learned so many great tidbits so quickly in a long time. Awesome talk!

  • @juliushinze5177
    @juliushinze5177 7 лет назад +170

    10:20 Beautiful syntax highlighting

    • @jonty3551
      @jonty3551 4 года назад

      Lol

    • @frankieteardrop666
      @frankieteardrop666 4 года назад +6

      I remember my prof for C++ and OOP had every other word/letter in his notes/code highlighted with no common theme whatsoever.

  • @qg4091
    @qg4091 8 лет назад +543

    This guy is seriously amazing, love his style of teaching

    • @johncherry108
      @johncherry108 6 лет назад +23

      Pity his ego needs to be continuously stroked with applause.

    • @Pulsar77
      @Pulsar77 6 лет назад +43

      John Cherry Oh FFS, it's a joke. First rule of becoming a Python programmer: have a sense of humor.

    • @heinzguderian9980
      @heinzguderian9980 6 лет назад +10

      He reminds me a bit too much of a pastor for me to be completely comfortable, (like from a Pentecostal church or something). Or an unctuous salesman telling us about his schemes. Material was great, though.

    • @DimitrisK5
      @DimitrisK5 5 лет назад +14

      @@johncherry108 It's one of his techniques to keep the audience engaged. He is an excellent speaker and he obviously does that on purpose. You might also notice that he asks the audience all the time if they learnt something new, or how many knew that, or what's the problem with this piece of code, etc..
      On top of that, he makes me (and I assume other people, too) feel like we are part of the Python family; the core team seems close and approachable and I get a feeling of belonging to this line of developers who transformed the way we think about human programming forever.

    • @KurzedMetal
      @KurzedMetal 5 лет назад +1

      No wonder why Python is awesome, they have awesome devs :)

  • @brotherlui5956
    @brotherlui5956 5 лет назад +55

    6 years old but still good advice. Raymond is a great teacher.

    • @anon_genz
      @anon_genz Год назад +1

      @@kolterdyx 10 years old, your statement of his statement still stands.

    • @stijnvandensande3579
      @stijnvandensande3579 Год назад

      @@anon_genz almost 11 now

    • @anon_genz
      @anon_genz 11 месяцев назад

      @@stijnvandensande3579 • and still holds up

  • @gromilla1990
    @gromilla1990 7 лет назад +131

    "If you are mutating something while you are iterating over it, you are living in a state of sin and you deserve whatever happens to you" :D loled so hard on this one! 20:20

    • @Michael-jq1hl
      @Michael-jq1hl 5 лет назад

      Hi I have recently started studying python, what is that arrow in print i,'-->',color?

    • @burakozdamar
      @burakozdamar 4 года назад +3

      ​@@Michael-jq1hl it's not a special character or something. he just wanted to print an arrow, that's it. the characters in single or double quotation marks are interpreted as string. so this statement prints 1 --> greens for example.

    • @Michael-jq1hl
      @Michael-jq1hl 4 года назад

      @@burakozdamar I see, many thanks, I never found the answer to that and now that I see the quotes makes more sense :)

    • @godfather7339
      @godfather7339 3 года назад

      @@Michael-jq1hl it's been a year, hope you are doing with python.

    • @Michael-jq1hl
      @Michael-jq1hl 3 года назад

      @@godfather7339 hey, kind of. I decided that instead of developing I could recruit Python Devs, so that is how I am using the little skill I have acquired.
      Unfortunately, most Devs think I am like any other recruiter and ignore me xD

  • @thatguy1000001
    @thatguy1000001 11 лет назад +16

    I literally just watched this a second time for the entertainment value! Raymond Hettinger is hilarious! Not only was watching this a lot of fun, but super-informative and efficient.
    I'm going to go check out some of his other talks. If I'm gonna learn python, it might as well be from this dude!

    • @tdao9741
      @tdao9741 3 года назад +1

      And how’s yours python 7 years later?

  • @Decessus117
    @Decessus117 9 лет назад +246

    "There's two kinds of people in the world: people who've mastered dictionaries and total goobers." - Raymond Hettinger

  • @merlin2600
    @merlin2600 6 лет назад +32

    At 44:00, The `with ignored(OSError)` has been renamed to `with suppress(OSError)` and is from the contextlib package.

  • @torgeirlaurvik8195
    @torgeirlaurvik8195 4 года назад +1

    This video was the video that got me interested in writing ideomatic Python and iterators. I've revisited it now and then ever since 1. year at uni. Amazing lecturer.

  • @stasbovanenko
    @stasbovanenko 5 лет назад +1

    Amazing talk ! Probably best I've heard in all 26 year I'm coding. A handful of smiles and headful of HQ knowledge. Thank you, Raymond !

  • @shushens
    @shushens 10 лет назад +19

    Love this guy. I was quite disappointed when it ended. I was so expecting a much much longer video :D

    • @ceestimmerman9785
      @ceestimmerman9785 7 лет назад

      You could read the "What's New" articles instead: docs.python.org/3/whatsnew/index.html

    • @jacobschmidt
      @jacobschmidt 4 года назад +1

      @@ceestimmerman9785 it's not quite the same!

  • @77aHeB
    @77aHeB 2 года назад +2

    First - this is an awesome piece, I didn't knew Raymond Hettinger was to be blamed for so many iterators in python, and I truthfully love this guy now that I know what he did for most of my days! :)
    There is a small bug in 15:58 onwards due to the missing tgt variable, but the more important thing is that it can get even more beautiful (IMHO) from:
    def find(seq, target):
    for i, value in enumerate(seq):
    if value == target:
    break
    else:
    return -1
    return i
    to this:
    def find(seq, target):
    for i, value in enumerate(seq):
    if value == target:
    return i
    return -1
    not that the for/else is not nice in some other cases, this was probably just not the right example for it.

  • @Achrononmaster
    @Achrononmaster 5 лет назад +104

    The ignored() idiom exists in Python 3.4+ but is called suppress():
    # NEW WAY in Python 3.4+:
    from contextlib import suppress
    with suppress(OSError):
    os.remove('foo.txt')

    • @locanix
      @locanix 4 года назад

      Thanks! I was wondering why I couldn't find it

    • @rusca8
      @rusca8 3 года назад

      +

  • @MrCoolnamehuh
    @MrCoolnamehuh 11 лет назад +1

    Found this to be one of the most useful python talks thus yet on youtube.

  • @matthewwatts9693
    @matthewwatts9693 10 лет назад +11

    This is a must see video for an python developer. Fantastic!

  • @JamesSKim
    @JamesSKim 11 лет назад +3

    This lecture is very nice to learn advanced Python programming. After I watched this video, I realize that I have used Python almost like using C. I have used C and C++ as well as Matlab. Hence, I thought that many approaches in Python will be not much different from the conventional languages except specialized keywords. However, I realize that grammars in Python can be different from that in C.

  • @kumarc634
    @kumarc634 9 лет назад +427

    at 7:22 it should not
    for i, color in enumerate(colors):
    print i,'--->',color[i]
    but
    for i, color in enumerate(colors):
    print i,'--->',color
    may be printing mistake

    • @mByyurt
      @mByyurt 7 лет назад +45

      I was here to write that. Nice catch.

    • @a8lg6p
      @a8lg6p 7 лет назад +37

      I was about to make that comment. Either way works the same, but it's exactly what he's been telling us not to do, so clearly a mistake.

    • @adelkhafizova
      @adelkhafizova 7 лет назад +30

      Also stopped the video to see if someone has pointed this out already)

    • @aikimark1955
      @aikimark1955 7 лет назад +1

      Do you think that Raymond is reading these comments?

    • @EyeIn_The_Sky
      @EyeIn_The_Sky 7 лет назад

      I think you do have to have the: print(i,'-->', color [i]) otherwise you will just get all the colours beside each index in a row repeated 4 times. Unless this is just in Python 3?

  • @guhkunpatata3150
    @guhkunpatata3150 2 года назад

    Where have I been All this time only to find this GEM right now ??? This video is very great and a MUST WATCH for any pythonista

  • @toomuchtruth
    @toomuchtruth 7 лет назад +1

    "Start open source contributions to project by going in and placing doc strings". This is a brilliant idea! I've wanted to start contributing for so long but didn't feel I have the skills, I'm gonna do this!!!

    • @bonbonpony
      @bonbonpony 6 лет назад

      Yes, do it. There's a lot of extremely crappy documentation for Python modules :q

  • @Krazness
    @Krazness 7 лет назад +2

    this may be the best python video I've seen online

    • @bonbonpony
      @bonbonpony 6 лет назад

      Yeah, there should be a video like this one for every language out there.
      One can learn much more about how to write clean code from such videos than from any crappy tutorial.

  • @richieKostenko
    @richieKostenko 10 лет назад +4

    This is probably the best presented programming video I've ever seen. Thanks!

  • @CraigPerry
    @CraigPerry 11 лет назад +1

    Raymond's an entertaining, engaging presenter. Good mix of material here, definitely came away richer for the experience.

  • @MrTigerstyle80
    @MrTigerstyle80 6 лет назад +3

    Dude’s kind of a colossal badass. Not even mad at the Casey Kasem vibe at all. He’s a beast.

  • @sandeshgowdru8869
    @sandeshgowdru8869 Год назад +1

    10 years old video, and it is gold.

    • @chrstfer2452
      @chrstfer2452 Год назад

      Some minor differences, izip is just zip now i guess

  • @DmitriiGlandarius
    @DmitriiGlandarius 8 лет назад +16

    Very nice. In just 50 minutes I learned moe then in the last month.

  • @borgonzalezusach9263
    @borgonzalezusach9263 10 лет назад

    This man is technically brilliant and hilarious. Not something you see everyday. Thanks for the nice speech!!

  • @MrTigerstyle80
    @MrTigerstyle80 9 лет назад +10

    This dude is off the hook smart.

  • @VladimirSanchez
    @VladimirSanchez 11 лет назад +2

    I can listen to Mr Hettinger all the time!!!
    Thanks for the presentation and your contributions.

  • @joedempseysr.3376
    @joedempseysr.3376 6 лет назад

    I thoroughly enjoyed your presentation! Take the old-fashioned, ugly, slow way of doing things and instead do the new-fangled, beautiful, fast way. I love it!

  • @yuli3873
    @yuli3873 3 года назад +1

    So this man made enumerate()? I love him from now on!

  • @hoanghaipham4318
    @hoanghaipham4318 4 года назад +1

    What amazing techniques! Why I haven't seen this sooner. Thank you a lots

  • @snowblindu
    @snowblindu 9 лет назад +279

    I wish this guy was my teacher

    • @hdggoyo7423
      @hdggoyo7423 9 лет назад +2

      +snowblindu he's cocky and not interesting at all

    • @PhilGerb93
      @PhilGerb93 9 лет назад +17

      +hd ggoyo pffft, hater. I wish he was my teacher too!

    • @jfolz
      @jfolz 8 лет назад +42

      +hd ggoyo He added a lot of the cool stuff to Python so he gets to be cocky.

    • @hdggoyo7423
      @hdggoyo7423 8 лет назад +6

      +riDDimann i was just joking, he looks like a cool dude, chill guys

    • @AlfredEssa
      @AlfredEssa 7 лет назад +7

      He is cocky, but he knows his shit. If you are going to be a hater, prove your chops.

  • @mpgovinda
    @mpgovinda 5 лет назад

    Just one video and learned more things worth years... great tips!

  • @VibeWithSingh
    @VibeWithSingh 8 лет назад +6

    This presentation is simply awesome !! hands down !!

  • @mountainhobo
    @mountainhobo 11 лет назад +11

    Love Raymond's presentation style.

  • @anAlokDubey
    @anAlokDubey 4 года назад

    I m watching 7 years old video and leaning lots of amazing things.... :-) you are really great.

  • @derekeden1163
    @derekeden1163 5 лет назад

    probably best python video ive ever seen

  • @jnuxadrian
    @jnuxadrian 10 лет назад +39

    I think that 'return newfunc(*args)' on line 6 must be replaced by 'return saved[args]' at 41:12

  • @mingosutu
    @mingosutu 4 года назад +8

    In python you make your video with audience, clapping, laughing and commenting. Python is fantastic.

  • @orkoxy
    @orkoxy 11 лет назад +19

    At 7:26, it should be
    for i, color in enumerate(colors):
    print i, '-->', color

    • @Michael-jq1hl
      @Michael-jq1hl 5 лет назад +2

      Hi I have recently started studying python, what is that arrow in print i,'-->',color?

    • @2adamast
      @2adamast 4 года назад

      Michael the arrow is a string

  • @darkopz
    @darkopz 6 лет назад +2

    Initially I refuse to believe any developer wouldn’t know what “in” semantically means, but then I’m reminded of all the code I’ve seen.

    • @bonbonpony
      @bonbonpony 6 лет назад +3

      Most programmers nowadays have just learnt to parrot other people's code without any actual in-depth understanding of what it does or why is its syntax the way it is. Mostly "thanks to" online tutorials, like those on Udemy or alike where blind lead the blind :q I still have people giving me weird looks when I write C++ code like this:
      if (a == b) do_something();
      else do_something_else();
      instead of wrapping the functions into braces, because they think that those braces are part of the syntaxt and have to be there. Or if I write something like this:
      cout

  • @wabalrarrt9374
    @wabalrarrt9374 2 месяца назад

    I want to see new updated version of this video

  • @MacroAggressor
    @MacroAggressor 5 лет назад +1

    This is great! I have a *much* better understanding of iterators and their purpose now. Thanks, Mr. Hettinger.
    edit: How did I not know about dictionary comprehensions?!? (21:05) That is AWESOME!!

    • @dgh25
      @dgh25 Год назад

      idk, kinda standard stuff in CS

  • @BillTubbs
    @BillTubbs 9 лет назад +25

    There's an error on the slide at 7:13 titled 'Looping over a collection and indices'. Last line should be:
    print i, '-->', color

    • @vanshdeep91
      @vanshdeep91 8 лет назад

      Bill Tubbs both have the same meaning brother be it color or colors [i]

    • @BillTubbs
      @BillTubbs 8 лет назад +4

      Both have the same result but using the color iterator that enumerate creates is 'faster and beautiful' as he points out.

  • @PramodL
    @PramodL 11 лет назад

    Can't recommend this talk enough. Must watch to take your python chops to the next level.

  • @anubhav9476
    @anubhav9476 4 года назад +1

    Man even though this is not quite as relevant to me today, I really love his presentation style

  • @toms169
    @toms169 Год назад +1

    07:25 Replace colors[i] by color in the lowest line! I am sure that‘s what he meant to write.

  • @espeon91
    @espeon91 9 лет назад

    Really insightful video. Didn't even notice the time fly by. Already feel better as a Python programmer.

  • @SvenSiegmund
    @SvenSiegmund 10 лет назад +1

    I love the people who make Python! Thanks for this most enlightening talk.

    • @wasikhan7741
      @wasikhan7741 2 года назад

      are you a python ninja by now?

    • @SvenSiegmund
      @SvenSiegmund 2 года назад

      @@wasikhan7741 I sure am 😏

  • @manojbisht7018
    @manojbisht7018 8 лет назад +49

    Documented version gist.github.com/JeffPaine/6213790

  • @mattralston4969
    @mattralston4969 4 года назад +1

    Thank you for the lecture, sir. I appreciate the review of some critical "dos and don'ts" for beginners.

  • @DeMurker
    @DeMurker 9 лет назад +5

    Great explanations. And even 3 years late still very useful.
    One thing though, he says that generator expressions make things faster but when I timeit I get this:
    ~$ python -m timeit "sum(i**2 for i in xrange(10))"
    100000 loops, best of 3: 1.74 usec per loop
    ~$ python -m timeit "sum([i**2 for i in xrange(10)])"
    1000000 loops, best of 3: 1.39 usec per loop

    • @benburrill
      @benburrill 9 лет назад +5

      +DeMurker Not reproducible: I got 2.57 for generator and 2.77 for list. But in any case, as you go beyond a 10 element list, you are going to get increasingly large memory and speed problems.

    • @Shaddycls
      @Shaddycls 8 лет назад +1

      The reason beyond containers over generators affects only at memory level: using zip(iterator1, iterator2) produces a single big object which contains the sum of both containers, since when you use a generator, it only produces an element on each iteration, so you will never have the entire sum of both containers in memory, which is an optimization and faster.

    • @deidyomega
      @deidyomega 7 лет назад +1

      Do it again, but xrange(1000000) ;-)

  • @jakykong
    @jakykong 4 года назад +4

    He even said I would fight him on this, but haha, oh man, the comparison functions are something I absolutely *miss*, even if I really agree with almost everything else he said and have been writing idiomatic Python for ages. I ran into a real problem the other day where comparisons were a much cleaner solution than the less obvious and potentially much slower multi-pass sorting: Sorting on multiple keys with independent ascending or descending orders.
    You can sort a plain tuple without any fuss if you don't mind that every key is ascending or every key is descending. But if you want to mix those, you have to do it in multiple passes, starting from the least significant key to the most significant key, and rely on timsort's stability to get the job done -- or, IMO, cleaner -- if this were Python 2, I could have expressed the comparison function with appropriate ascending/descending signs in a simple if/elif/else return 0 chain, and rapidly expressed both the intent and the functional result quickly.
    Python 3 even provides a conversion utility that creates wrapper objects on the fly to facilitate this need, which is a bizarrely convoluted way to accomplish what simply allowing either key function or comparison function would have.

  • @eduardoherrera3696
    @eduardoherrera3696 5 лет назад

    Thank you so much for this wonderful lecture. I think this insight might be helpful . As a Novice programer I had a few issues understanding how some of core functions in Python worked and what was because the people who taught me where using derived language examples. Phrases like "if you've code an another language....". But I haven't well time passed I learned the hard way later got to this video and inevitably think that things would been a lot easier for me if this lecture was around.

  • @bloody_albatross
    @bloody_albatross 10 лет назад +1

    27:50 I think doing this is so common, there should be a group_by(sequence, keyfunc). You could then call it with group_by(names, len). There should also be an index_by(sequence, keyfunc). These functions would be trivial to implement, but nevertheless they are common and useful enough to be put in some standard lib (collections?).

  • @caballerofelipe00
    @caballerofelipe00 4 года назад

    I didn't read all comments but I fount that in 29:12 there is an error, 'namespace = parser.parse_args([])' should not contain an empty array as argument, that way it doesn't take into consideration CLI arguments.

  • @uthoshantm
    @uthoshantm 5 лет назад +1

    Note that these functional constructs are now in every mainstream language such as C# and Java. So, it's not that Python has a specific capability, but experienced Python programmers do encourage the use functional constructs. This video is an example.

  • @Algoritmik
    @Algoritmik Год назад +1

    At 07:30, the 2nd line of the 2nd for loop should be:
    print i, '->', color # not colors[i] !

  • @purplecrayon7281
    @purplecrayon7281 2 года назад

    I love this man! He should write a book on clean Python code, if he hasn't already.

  • @jasonstapley6822
    @jasonstapley6822 6 лет назад

    That talk was amazing. Will need to watch this video a few times.

  • @miguelvasquez9849
    @miguelvasquez9849 Год назад

    this is why i love python, the ways to write clean code.

  • @gibbostooth
    @gibbostooth 6 лет назад

    43:47 "ignored" is now called "suppress" and it's part of "contextlib" library.

  • @RichardGrigonis
    @RichardGrigonis 2 года назад

    I'm so glad that he said we should rename For as ForEach. I suggested that online some years ago, and boy did I get lambasted by everybody!

  • @RomanDryndik
    @RomanDryndik 7 лет назад +16

    At 41:09 when he explains self-defined defined decorator for LRU cache it has an error. His implementation leads to infinite recursion.
    Instead of this:
    def cache(func):
    saved = {}
    def newfunc(*args):
    if args in saved:
    return newfunc(*args)
    result = func(*args)
    saved[args] = result
    return result
    return newfunc
    It should've been:
    def cache(func):
    saved = {}
    def newfunc(*args):
    if args in saved:
    return saved[args]
    result = func(*args)
    saved[args] = result
    return result
    return newfunc

    • @TheAnimystro
      @TheAnimystro 5 лет назад

      Thanks, I was staring at the code confused as to how that could possibly work, because I assumed he was right and I was missing something!

    • @mikhaill244
      @mikhaill244 2 года назад

      Also pointed out that something wrong with the code. Ran it, and yes, infinite recursion.

  • @movax20h
    @movax20h 5 лет назад +1

    "with ignored(OSError)". So cool. TIL. In Python 3, it is called "with suppress(...)". You can list multiple exception types too.

  • @bleachfan48
    @bleachfan48 11 лет назад

    This is beautiful, just finished teaching myself Python on Codecademy and this was by far the best tips for a rookie like me

  • @EdwardBriggler
    @EdwardBriggler 11 лет назад

    brilliant talk, thanks for sharing!

  • @eos_rf
    @eos_rf 4 года назад +2

    15:59
    *if value == tgt*
    is undefined, maybe "target"?

  • @BryanChance
    @BryanChance 3 года назад +1

    Amazing talk..more professors like him. :) I'm starting to appreciate Python now.
    EDIT: Wow

  • @martinborus9531
    @martinborus9531 Год назад

    This talk is great even after 10 years.
    Some of the syntax has changed, for example in 2023:
    at 44:05 the "with ignored" is now
    from contextlib import suppress
    with suppress(OSERROR):
    and the "izip" command is gone, zip now creates a generator.

  • @nishankbani3257
    @nishankbani3257 7 лет назад

    Excellent presentation on Python code writing.

  • @anonvigil628
    @anonvigil628 5 лет назад +1

    This needs updated for Python 3 - I have to go hunting for which of his recommendations are still valid. The video could at least have footnotes that say which still applies in Py3.

  • @FreakyCheeseMan
    @FreakyCheeseMan 11 лет назад +11

    Okay, something gets me here, that I've seen in other Python presentations as well - they describe some clunky, numeric way to do something (like loop backwards, or loop across a list when you need the index), and then say that that's bad because it's uglier, then the "Right" way - but the "Right" was involves a whole new dedicated code word, one you may have to look up, one the people reading your code may not be familiar with. Meanwhile, the clunky numeric way uses only the basic set of tools.

    • @disculpa
      @disculpa 2 месяца назад

      It's called abstraction or chunking. It helps you think more efficiently.

  • @johncongerton7046
    @johncongerton7046 Год назад

    Most enlightening talk

  • @dpo357
    @dpo357 9 лет назад

    I learned a LOT with this video, Kudos Raymond Hettinger
    15:52 for/else, I've always wanted this. For a long time now, I've replicated this behavior in Java enclosing the for inside try/catch and throwing a custom exception of the kind 'BrokenLoop', which looks waaay better, despite feeling forced and inappropriate. Huge like.

  • @rdoetjes
    @rdoetjes 11 лет назад +9

    I learned a lot! Then again I don't use Py3 because I use Jython which only 2.7 is stable and a compositing suite that has 2.7 also.
    The problem with functional programming is (and this video proves it) is that you need to know the function names and what to look for. This means actually bothering to read lots of papers and documentation and then you need to remember them. People aren't very good in remembering things especially non-descriptive.
    So only people who really dedicated in a language will know these things but Python is an awesome language but it's not a core programming language for most. Which is Java, C# or C++ and there you don't have a lot of functional functions.
    I love C because it has very few keywords, STL is great but I ALWAYS need to to reread who it works. Functionally very powerful but it's even less descriptive than these functions.
    So now that I know these situations explained by Raymond I will look them back here and read the docs apply them several times and probably by the 7th or 9th time I will remember it. That is until I don't use Python for 2 years again and forgotten all about them :D

    • @palpytine
      @palpytine 6 лет назад +1

      Many (if not most) FP languages offer some sort of modules or namespaces to handle this exact problem of discovery, it's definitely not an issue with the paradigm in general.

  • @SanteeRocks
    @SanteeRocks 4 года назад +1

    This guy is a legend

  • @sudiptochatterjee
    @sudiptochatterjee 7 лет назад

    Thanks a lot for this video. Raymond is an awesome guy.

  • @isilanes
    @isilanes 10 лет назад

    24:20, about the use of get() when counting appearances of color within a list. I am probably not saying anything new, but I did some tests and actually using get() is slower than the naïve "if color not in d". More concise, sure, but more efficient... it doesn't seem so. The defaultdict he mentions later is actually quite faster, even including the time to convert the defaultdict back into a regular dict.
    Of the alternative ways of doing the counting, I sometimes use a fourth one he doesn't mention, and is almost as fast as the defaultdict. The code would go like this:
    d = {}
    for color in colors:
    try:
    d[color] += 1
    except:
    d[color] = 1
    Of course the relative speed of different methods depends on how many different "color" items we have within the list "colors". The try/except method is more efficient the less distinct colors there are (so less except blocks executed).

  • @rishabhbohra
    @rishabhbohra 4 года назад

    Give this man a Python Salute!

  • @GraficaObscura
    @GraficaObscura 11 лет назад

    Wow - amazing talk - informative, concise, immediately useful. Thank you.

  • @TheGIXL
    @TheGIXL 6 лет назад +7

    41:16 it should be "return saved[args]" instead of "return newfunc(*args)"

  • @defined_user
    @defined_user 4 года назад

    Such a great video! Many thanks!

  • @AliSattarBarani
    @AliSattarBarani 4 года назад

    Amazing Slideshow

  • @_ree_
    @_ree_ 4 года назад

    It was refreshing to see someone raise their hand at 44:06

  • @cygil1
    @cygil1 5 лет назад +1

    @14:21 lambda: f.read(32) is a lot clearer to me than "partial(f.read, 32)" since all we're actually doing is suppressing evaluation of f.read until it's called by iter, the equivalent of quoting in lisp. It threw me for a loop because I think of partial as being used for partial evaluation, something to do with the name I think.

  • @eskays9840
    @eskays9840 8 лет назад

    very much required for a beginner like and why would someone dislike this ....

    • @bonbonpony
      @bonbonpony 6 лет назад

      Maybe they code in C ;)

  • @lordtejas9659
    @lordtejas9659 4 года назад +1

    40:26 that one guy is really enjoying it:)

  • @matiasherranz86
    @matiasherranz86 3 года назад

    After over 10 years as a working professionally with Python, Hettinger can still blow my mind and renew my passion towards the language. Anyone knows if the deck of slides is still available anywhere?

    • @youliyav
      @youliyav 3 года назад +1

      Slides: speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger-1

    • @matiasherranz86
      @matiasherranz86 3 года назад

      @@youliyav Nice!! Thanks!

  • @jeddak
    @jeddak 3 года назад

    13:45 realizing this was a milestone in my Python journey

  • @MrDevZero
    @MrDevZero 6 лет назад

    Great. This presentation is awesome. To make it awesomer slides should also be available somewhere.

  • @AGT0M
    @AGT0M 5 лет назад +1

    Thanks for sharing.
    I'm new to Python, but I wonder if all the presented snippets of code have been tested. For example, at around 16:00 the code would most likely blow up with an undefined error for tgt, as the input argument named different - target, but all-in-all - good stuff.

    • @ewerybody
      @ewerybody 4 года назад

      yeah not many people found that one! 👏

  • @AhmedBalfaqih
    @AhmedBalfaqih 10 лет назад +1

    I kept smiling. Thank you.

  • @RiptheJacker
    @RiptheJacker 10 лет назад

    Really good video. Starts off as a video for python beginners but is insightful for experienced developers as well.

  • @Achrononmaster
    @Achrononmaster 5 лет назад +1

    izip() in Python2 is zip() in Python3. Also, you can loop over the longer of the lists. So,
    import itertools
    colors = ['red','green,'blue','purple']; shapes =['circle,'triangle','square']
    for col, shp in zip_longest(colors,shapes):
    print( col, '--->', shp)
    >>>
    red ---> circle
    green ---> triangle
    blue ---> square

  • @3ombieautopilot
    @3ombieautopilot 11 лет назад

    This is priceless! Thanks for the upload.

  • @ireallyhatemakingupnamesfo1758
    @ireallyhatemakingupnamesfo1758 4 года назад

    Sophomore CS student here, spent a year in Java and C and been trying to learn python. Currently, my brain is melting

  • @t0919766755
    @t0919766755 6 лет назад

    @41:14 cache function should return saved[args] when args is in saved dict