Skip to content

Instantly share code, notes, and snippets.

@oC-n
Created June 25, 2021 17:30
Show Gist options
  • Save oC-n/29b0e1ab3a96bcdeef8f6fadd9159861 to your computer and use it in GitHub Desktop.
Save oC-n/29b0e1ab3a96bcdeef8f6fadd9159861 to your computer and use it in GitHub Desktop.
Python for Data Science, AI & Development - Week 3 Hands-On Lab: Objects and Classes
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@oC-n
Copy link
Author

oC-n commented Jun 25, 2021

Note efficiencies possible in final exercise!

  • Each string method updates the string it's applied to, so can string them together in series: aString = aString.replace('.', '').replace(',', '')...
  • By casting a list to a set, duplicates are removed, e.g. keys = set(words)
  • By thus removing duplicates, each unique word can be counted in the original text and assigned a dictionary entry.
  • Having the frequency dictionary method available lets us avoid duplicating the tast in freqOf. We can call freqOf to pass us the frequency dictionary, check the word is in it, and if so, return its value. If not, we should return 0, for robustness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment