TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to write X in both Python 3 and JavaScript

178 pointsby chibicodeover 6 years ago

23 comments

alyandonover 6 years ago
Sort example doesn&#x27;t take into account Javascript does lexicographical sorting?<p>javascript:<p><pre><code> someList = [ 40, 2, 1, 3, 7, 99] someList.sort() Array(6) [ 1, 2, 3, 40, 7, 99 ] </code></pre> python:<p><pre><code> someList = [ 40, 2, 1, 3, 7, 99] sorted(someList) [1, 2, 3, 7, 40, 99]</code></pre>
评论 #17990564 未加载
评论 #17989006 未加载
评论 #17989321 未加载
评论 #17992744 未加载
评论 #17988069 未加载
评论 #17992567 未加载
ChrisSDover 6 years ago
As someone who is often switching languages, I find these sorts of cheatsheets useful.<p>I know all the syntax in them but I&#x27;ll be damned if I can ever remember which language uses which until I&#x27;ve settled back in to things.
评论 #17992268 未加载
评论 #17988017 未加载
评论 #17990196 未加载
anintegerover 6 years ago
How to write using X in both languages:<p>Python: <a href="https:&#x2F;&#x2F;github.com&#x2F;python-xlib&#x2F;python-xlib" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;python-xlib&#x2F;python-xlib</a><p>Node.js: <a href="https:&#x2F;&#x2F;github.com&#x2F;sidorares&#x2F;node-x11" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sidorares&#x2F;node-x11</a>
评论 #17987847 未加载
评论 #17987626 未加载
评论 #17988983 未加载
评论 #17987628 未加载
marsroverover 6 years ago
When I read the headline I was expecting the X windowing system. When I clicked the article and saw “junior programmer” I thought this is about to be impressive.<p>Cool site :P
fabiomaiaover 6 years ago
Very cool! Reminds me of <a href="http:&#x2F;&#x2F;youmightnotneedjquery.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;youmightnotneedjquery.com&#x2F;</a><p>I particularly enjoyed seeing that you used snake case in Python and camel case in JavaScript. Great attention to detail.
sayazamuraiover 6 years ago
Creator here! Let me know if you have any suggestions.
评论 #17988888 未加载
评论 #17987554 未加载
评论 #17987536 未加载
评论 #17988731 未加载
评论 #17987979 未加载
评论 #17988915 未加载
评论 #17987864 未加载
评论 #17987896 未加载
评论 #17987550 未加载
评论 #17987968 未加载
评论 #17987482 未加载
评论 #17987488 未加载
mvilimover 6 years ago
<a href="http:&#x2F;&#x2F;hyperpolyglot.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;hyperpolyglot.org&#x2F;</a> is a great website with a similar idea.
评论 #17987618 未加载
ramses0over 6 years ago
No mention of <a href="http:&#x2F;&#x2F;rosettacode.org" rel="nofollow">http:&#x2F;&#x2F;rosettacode.org</a>, tsk tsk. (specifically: <a href="http:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Category:Programming_Tasks" rel="nofollow">http:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Category:Programming_Tasks</a>)
评论 #17989494 未加载
thomasfedbover 6 years ago
A weird reference imo. Perhaps useful to build as a learning experience but I wouldn&#x27;t expect who needs if&#x2F;else included in a cheat sheet to be ready to learn to languages.
评论 #17987586 未加载
dkonieczekover 6 years ago
Do people actually use cheat sheets like this? IMO, the first stackoverflow result in google is generally what I&#x27;m looking for and quicker - especially for common things and common languages such as the things on this page. Even if you have the page bookmarked, you still need to find&#x2F;search&#x2F;scroll for the specific thing you&#x27;re looking for. Also, with Alfred you can google anything even quicker by not having to cmd+tab to the browser.
评论 #17989252 未加载
评论 #17989270 未加载
评论 #17989293 未加载
fenivover 6 years ago
Reminds me of this OneLang HN post from several months ago - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=16415051" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=16415051</a><p>It&#x27;s an IDE that lets you code simultaneously in several different languages <a href="https:&#x2F;&#x2F;ide.onelang.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ide.onelang.io&#x2F;</a>
tobiasz-cudnikover 6 years ago
Reminds me of PLEAC - Perl Cookbook translated to &gt;10 langs <a href="http:&#x2F;&#x2F;pleac.sourceforge.net" rel="nofollow">http:&#x2F;&#x2F;pleac.sourceforge.net</a>
nayukiover 6 years ago
When I publish code about algorithms and data structures to my web site, I usually offer multiple language versions. Why? Because understanding the computer science theory and math proofs is a big effort. Writing and debugging my first implementation in any language is a big effort. But porting that code to a bunch of languages is comparatively easy and is almost a thoughtless mechanical process.
basilgoharover 6 years ago
I thought this was going to be a polyglot[1] demonstration of writing code for X Windows. However, I was not disappointed in what I found!<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Polyglot_(computing)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Polyglot_(computing)</a>
anticensorover 6 years ago
I expected a Python&#x2F;JS polyglot :)
评论 #17990157 未加载
Tooover 6 years ago
Impressive to see almost all JS examples being as short as the python ones. Python is normally valued for being short and concise but modern JS is really catching up here.
aavotinsover 6 years ago
I had such high hopes when I opened the arsenal. I anticipated it would an article of how to write code that&#x27;s both JavaScript and Python syntactically correct.
another-cuppaover 6 years ago
What&#x27;s the point of having print or console.log around everything? Just have one box with &quot;print to standard output&quot; and those two at the top.
sheikheddyover 6 years ago
I love it! Reminds me of <a href="https:&#x2F;&#x2F;www.interviewbit.com" rel="nofollow">https:&#x2F;&#x2F;www.interviewbit.com</a>
ingen0sover 6 years ago
Excellent educational tool - will be passing this around to colleagues who need it. Thanks!
评论 #17987664 未加载
评论 #17987603 未加载
undershirtover 6 years ago
this is very good. i had it in my head that there was no &quot;extend&quot; function in JS, and didn&#x27;t realize &quot;push(...array)&quot; was possible. thank you for the super detailed guide
tracker1over 6 years ago
FizzBuzz example isn&#x27;t correct
enitihasover 6 years ago
I was expecting to see a leftpad comparison too :D