0

I've been working through the problems on LeetCode in Python and occasionally I'll see comments saying that someone's solution is "Pythonic". I guess it means that your code embodies the spirit of the language of Python, but what specific aspects and conventions does that refer to?

code_relic
  • 39
  • 8
  • for example, `for i in range(len(lst))` is c style, `for item in lst` is Pythonic. and list comprehension is also Pythonic. – Lei Yang Mar 21 '22 at 02:22
  • using the for clause is probably the most pythonic thing. Ima dditionseapping values as such a,b = b,a is considered pythonic – Fishball Nooodles Mar 21 '22 at 02:27
  • @FishballNooodles yes, that is a good example, using the old temporary variable construct *does work*, e.g. `temp = a; a = b; b = a` *works*, but it is more idiomatic to simply use `a, b = b, a` – juanpa.arrivillaga Mar 21 '22 at 02:36

1 Answers1

0

Well answered here

But I would add that being pythonic is more than just to "Look like" python. Languages are designed in ways so that being some-language-ic makes the compiler/interpreter more efficient and less error-prone.

Gawain
  • 71
  • 6