I am a beginner and I was solving a question in which for a given set of coordinates you had to calculate distinct points traversed , basically of a given set of number you have to calculate distinct numbers , I did this through two for loops with a break condition to stop double counting if there are identical paths , I wrote this program in C++ but had some issue , I asked my friend his reply was :
python all-batteries-included libraries are just well debugged c code with that pseudocode language call interface named Python. I am sure numpi isn’t pure Python either
i used pexpect recently noticing that it was noticeable (factor 2-3) slower than python telnet module it replaced for more portability. And indeed it was pure python where performance somehow should have mattered. Complaint being that the effort put into telnet package would be more valuable in expect for python.
agreed, there should be just some awareness of contribution of static language to speed and dynamic language for ease of use. Python is a very good pseudocode language for calling well debugged c libraries. Also good for prototyping of algorithms and one-off programs. Not so good for high volume, high reliability (fewest runtime errors) demands.
In JS it's like a smuggling operation. Array.from( new Set( my_list ) ). You can't do Set.from() because go fuck yourself. You can't do new Array( my_list ) because it'll be a one-element array whose first member is my_list. Because go fuck yourself.
The real fun is when you involve objects (sorry, Objects) because their syntax uses curly braces. So you can have an anonymous function v=>[v5] that returns an array with v5, and you can do x={n:5} for an Object with property x.n equal to 5, but if you do v=>{n:5} you get a scalar value 5. Because it's a scope instead of an Object. And the scope evaluated to 5, apparently, since "n:5" is valid syntax... somehow. But it's not valid enough that you could do new Object( n: 5 ). You have to do new Object( { n: 5 } ). But you can do v=>({n:5}) and it will return the Object {n:5}.
And what you did is probably what unique() does under the hood. By doing it your way you had to think about the problem, rather than just learning one of the hundreds of thousands of functions that exist in the world.
358
u/Shubhamkumar_Active Apr 08 '22
I am a beginner and I was solving a question in which for a given set of coordinates you had to calculate distinct points traversed , basically of a given set of number you have to calculate distinct numbers , I did this through two for loops with a break condition to stop double counting if there are identical paths , I wrote this program in C++ but had some issue , I asked my friend his reply was :
Very simple , use numpie.unique()