Pythonic & Non-Pythonic Way In Python

Non-Pythonic :-


Suppose you wanted to collect the names in the above list that have 8 letters or more. In other programming languages, the typical approach is to create an index variable(i), use I to iterate over a list, and use an if statement to collect the names with 5 letters or more : 

# Print The list created using the non-pythonic approach...

non- pythonic

Inside the names, whose length more than 5 his name is returned.

This whole process is non-pythonic.


Pythonic :-

# Print the list created by using list comprehension :--


In this list 'lakhan', 'herry', 'arjun', 'kapil' length is greater than or equal to 5 
so this name is returned.


This is a pythonic approach. 
  • The important thing to notice here is that following some of Python's guiding principles allows you to write cleaner and more efficient code.

Remember, Pythonic code == efficient code


Efficient :- 

Writing efficient python code        

  • Minimal completion time ( fast  runtime)
  • Minimal resource consumption (small memory footprint)                           
          

 








Comments