Skip to content

Pikayy/Better-Python-Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Better-Python-Code

Best practices that improve your code by making your code much cleaner and more Pythonic. Idea comes from https://www.youtube.com/watch?v=8OKTAedgFYg&t=184s&ab_channel=PythonEngineer

11 tricks to make your code more pythonic.

  1. Iterate with enumerate() instead of range(len())
  2. Use list comprehension instead of raw for-loops
  3. Sort complex iterables with the built-in sorted() method
  4. Store unique values with Sets
  5. Save Memory With Generators
  6. Define default values in Dictionaries with .get() and .setdefault()
  7. Count hashable objects with collections.Counter
  8. Format Strings with f-Strings (Python 3.6+)
  9. Concatenate Strings with .join()
  10. Merge dictionaries with the double asterisk syntax ** (Python 3.5+)
  11. Simplify if-statements with if x in list instead of checking each item separately ttt

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published