Python Standard Library: Functools

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

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

  • @JakeCallahan
    @JakeCallahan  11 месяцев назад +1

    What do you use most from functools? For me, it has to be caching, followed by partials.

  • @flynnoconnell2260
    @flynnoconnell2260 11 месяцев назад +1

    This channel is an absolute gem

  • @iwswordpress
    @iwswordpress 21 день назад

    Professional quality tuition and production - as ever!

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

    Had a use for reduce recently at work. My tester wanted to combine some nested dictionaries, so I wrote a function for him to do it, which took two dictionaries and returned a new dictionary that was the combination of the two.
    Two days later he said "can we do this with a list of dictionaries" and reduce was the perfect way to do that.
    I probably wouldn't use this for production code, but for test suite code it ended up being a great solution

    • @JakeCallahan
      @JakeCallahan  11 месяцев назад +1

      Oh nice! If you don't mind sharing, will you put an example in a GitHub gist and link it here?

    • @Deemo_codes
      @Deemo_codes 10 месяцев назад

      @JakeCallahan
      Apologies I've only just seen this. I did another one recently
      # iterate over a list of directories and read in a parquet file to a spark dataframe
      # add a filename column to each dataframe
      duplicates = (
      reduce(Dataframe.union, list_of_dataframes).groupby("uniqueid").agg(sf.collect_list("filename").alias("filenames").filter(sf.size(sf.col("filenames")) >1).collect()
      )
      Might need some formatting on that one. Typing on a phone.
      I'll find the recursive dictionary merge later and post that too

    • @Deemo_codes
      @Deemo_codes 10 месяцев назад

      The thing to remember, is that when you call a method from an instance, self is the instance. When you call the same method from a class, you can pass an instance of the class in as self.
      For example
      ", ".join(list_of_strings)
      Or
      str.join(", ", list_of_strings)

    • @Deemo_codes
      @Deemo_codes 10 месяцев назад

      @JakeCallahan
      def merge_dictionaries(dict1, dict2):
      all_keys = set(dict1.keys()).union(dict2.keys())
      new_dict ={}
      for key in all_keys():
      value = dict1.get(key, dict2.get(key))
      If isinstance(value, dict):
      new_dict[key] = merge_dictionaries(dict1.get(key, {}), dict2.get(key, {}))
      elif isinstance(value, list):
      new_dict[key] = [*dict1.get(key, []), *dict2.get(key, [])]
      return new_dict
      reduce(merge_dictionaries, list_of_dicts)

    • @Deemo_codes
      @Deemo_codes 10 месяцев назад

      It relies on the dictionaries having the same datatype for the same key, and isn't exhaustive. But works for my testers usecase

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

    20:00 💡 moment you have created factorial using partial reduce ..that's interesting .

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

    Nice, thanks!

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

    woooooooooooooo

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

    can you do django plz

    • @JakeCallahan
      @JakeCallahan  11 месяцев назад +1

      I have very little exposure to Django, so would not be a good teacher for a course on that. In the past I've tended to favor Flask, but today would also be inclined to try out FastAPI.
      Django might be something I revisit in the future, but that won't be anytime soon unfortunately.

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

      @@JakeCallahan ah🥲, it's ok.

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

      can you give me a good resource to learn django , like the theory of it plz

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

      Since I haven't personally gone through any available Django courses, I wouldn't want to mislead you with a poor recommendation. I'd hate to waste your time.
      However, if you do find a Django course you like, please link it here so others can follow your lead!

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

      @@JakeCallahan I think this channel is good if you want to learn about the "theory" of Django, but i really wanted another resource to learn from.
      Very Academy:youtube.com/@veryacademy?si=7mF2rSqa3QVkivGK

  • @halfbakedthoughts4150
    @halfbakedthoughts4150 11 месяцев назад +2

    Man i discovered your channel a week back and i am so glad... Great job with these videos🫡