# Learn Languages (Python!) Idiomatically

The aim of this pageđź“ťis to provide a commentary on the solution of a puzzle from Leetcode â€” 1299. Replace Elements with Greatest Element on Right Side â€” LeetCode

Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array.

`<!-- EXAMPLE -->Input: arr = [17,18,5,4,6,1]Output: [18,6,6,6,1,-1]`

## 2. LESSON: LEARNING LANGUAGES IDIOMATICALLY

• The lesson seems to be that you must know pythons idiomatically, where it combines the pythonic backward traversal with `range(len(arr) -1,-1,-1)` and value swapping via tuple unpacking
• Even though Paul Graham suggests (rightly?) that

When people say that in their experience all programming languages are equivalent, theyâ€™re making a statement not about languages but about the kind of programming theyâ€™ve done. 99.5% of programming consists of gluing together calls to library functions. All popular languages are equally good at this. So one can easily spend oneâ€™s whole career operating in the intersection of popular programming languages.

• I counter â€śequivalence of languagesâ€ť with the example above, boosted with prof. Sussmanâ€™s observation that essential to learning a language is not just to learn about its primitives, collections, and syntax, but â€” essentially â€” about its idioms

If you think about this, what youâ€™ve learned so far is the rules of some language, some primitive, some means of combination, almost all of them, the means of abstraction, almost all of them. But what you havenâ€™t learned is common patterns of usage. Now, most of the time, you learn idioms when learning a language, which is a common pattern that means things that are useful to know in a flash. And if you build a great number of them, if youâ€™re a FORTRAN programmer, of course, everybody knows how to â€” what do you do, for example, to get an integer which is the biggest integer in something. Itâ€™s a classic thing. Every FORTRAN programmer knows how to do that. And if you donâ€™t know that, youâ€™re in real hot water because it takes a long time to think it out.

--

--

## More from Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Love podcasts or audiobooks? Learn on the go with our new app.

## Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com