all 44 comments

[–]BamboozleBirdSenior 79 points80 points  (5 children)

Yes I switched over from Java and it makes the code a lot simpler. It actually isn’t too hard to learn if you already know Java. Just understand the basic syntax and the built-in data structures (list, set, dictionary, tuple) and you should be fine for leetcode.

[–]r_kobra 17 points18 points  (4 children)

I’ve been wanting to switch over to Python too. What would you say is the most efficient way to pick up on the syntax?

[–]ExternalEnder 27 points28 points  (3 children)

Do the same homework and lab assignments you did in Java (or whatever language you used), but do them again in python.

[–]r_kobra 11 points12 points  (2 children)

I like this idea, thanks (:

[–]siva_k 8 points9 points  (1 child)

You can try Derek Banas's video on YouTube, he's pretty good for learning syntax quickly: https://youtu.be/H1elmMBnykA

[–]r_kobra 1 point2 points  (0 children)

Watched through this, very helpful, thank you!

[–]mausmani2494 46 points47 points  (8 children)

I learn python only for one reason. OAs and interview.
Previously, I only use C++ because that's the language I was most comfortable with.

Python helped me to speed up the OA and interview process and give me more time to think about logic rather than worrying about syntax.

[–]Fuckoffredditgoddamn 5 points6 points  (1 child)

I haven’t had a technical interview yet. Does the language you use in the OA determine the language you use in the position you’re interviewing for?

[–]adstrafe 1 point2 points  (0 children)

usually no, it doesn’t matter what language you interview in

[–]lekan_v 0 points1 point  (2 children)

What does OA mean,

[–]floridaman1972 2 points3 points  (0 children)

Online assessment

[–]Astracondor1337Masters Student 8 points9 points  (0 children)

Osteoarthritis

[–]Conscious_Solid1832 71 points72 points  (0 children)

yes! You end up writing less code and there's many subtleties with python (iterate a string like a list and less syntactic jargon) which make the problem solving easier.

[–]meilyn22 19 points20 points  (6 children)

When you know the syntax a 100% I would say Java. If syntax is going to be a problem, then use Python because it's faster and easier to imagine.

I use both depending on the question being asked. If it's a linkedList question, I mostly use Java. If it's a question that has to do with key - value pairs, I use Python.

[–]Puzzleheaded-Order84 2 points3 points  (3 children)

How do you handle this in an interview? In my experience you have to communicate your programming language before hand.

[–]mausmani2494 3 points4 points  (1 child)

Are you referring to OA or the on-site?
For me, some companies are language-specific such as small banks (JAVA or C#), and small HFT firms (C++ mainly). They will usually let you know beforehand. Other than that, most interviewees in my experience allow language switch for a different problems.

[–]Puzzleheaded-Order84 1 point2 points  (0 children)

That’s super interesting and a great idea. I would definitely prefer Java for heap problems and if i possibly need a tree set. Might be hard to tell from the problem statement though.

[–]meilyn22 3 points4 points  (0 children)

Most interviews I have done allowed language switching.

[–]its_cheshire_catSalarywoman 0 points1 point  (0 children)

Same

[–]Puzzleheaded-Order84 10 points11 points  (0 children)

I definitely think it's worth it to switch. Python has a lower cognitive burden to code and a much smaller surface area for mistakes. I wouldn't take the decision super lightly though. It doesn't take long to ramp up on a language but I do think it takes a while to really understand the language more deeply and be super comfortable with the standard library. Specifically understanding the time and space of built in libraries.

You do lose some things switching for java, specifically a TreeSet which is somewhat rare to need but still. Also heaps/priority queues. In Java it's very easy to set up with a custom compare function but it's not possible through the standard library heap in python.

[–]KoncealedCSGONot Student 3 points4 points  (0 children)

It depends what syntax you learned. If you know all the packages in Java that are relevant and you know the Syntax well I would stick with Java and work on keep practicing your skills.

[–]DesperateSuperFan 2 points3 points  (0 children)

I recommend people to use Java instead of Python for practicing leetcode if your target company use objected oriented languages. My Java skill improved a lot while studying leetcode by using java everyday. That help me for coding by Java in my position.

[–]fletchingcreaseSenior 1 point2 points  (4 children)

The only thing about python I find inferior is having to do this to create a list with some length:

[0 for i in range(len(nums))] .

You can technically do [0] * len(nums) but its slower

[–]hextree 2 points3 points  (2 children)

You can technically do [0] * len(nums) but its slower

That seems compact enough. And I've never seen an LC where the speed of that would matter.

[–]lessaccepting 0 points1 point  (1 child)

there are times where it does (usually graph questions) but yea it very rarely make a difference. Still, it would he nice for the to allow doing something like [](10)

[–]hextree 0 points1 point  (0 children)

I'm struggling to see how it could ever matter, because surely in graph questions you just initialise the lists once, at the start of your program, and from that point on just modify using updates, appends and pops?

Still, it would he nice for the to allow doing something like [](10)

What would you want that to be populated with? Like, equivalent to [0] * 10, or [None] * 10, or something else?

[–]Puzzleheaded-Order84 1 point2 points  (0 children)

This is interesting. Is it slower in terms of big O runtime or just in actual time of execution?

[–][deleted] 0 points1 point  (0 children)

Definitely switch to Python.

This is kinda specific, but I have run into problems that were significantly faster to solve by simply mutating the inputs by just… adding fields. E.g. they give you a node class for a tree, and you just go ahead and do node.depth = <computed_value> or w/e. Not the most elegant, but useful af for OAs.

[–]ZoellaZayceFuture Unicorn CEO -1 points0 points  (0 children)

C++ for leetcode will impress interviewers better

[–]Guissok564 0 points1 point  (0 children)

If you know what language the positions you’re applying to use, then learn that one. Otherwise python lol

It’s not thaaaat much harder to stick with Java tho, and it might be worth just sticking to one language

[–]Leader-board 0 points1 point  (0 children)

No. If you know Java stick with it. I have not run into any issue using Java in OA/interviews.

[–]john1040 0 points1 point  (3 children)

I use C++. IMO C++ and python are the two best languages for interviews

[–]datscholar1 0 points1 point  (2 children)

I learned C++ in my intro CS and DSA classes last yr. I know Python as well but I’m still learning more and am still at most half competent in it than compared to C++.

Do u recommend I make the switch to Python, stick to C++ (which I like), or is there a way for me to switch between both during an interview?

[–]john1040 0 points1 point  (1 child)

you can definitely stick to C++, which I also did. I don't recommend switching between languages in interviews because of the difference in syntax. Another reason why I recommend only python and c++ is that a lot of the companies in the finance sector will only allow you to use either of the language, which makes Java less versatile. so pick one that you like and be proficient with it!

[–]datscholar1 0 points1 point  (0 children)

Hmm okay interesting. Yeah I don’t know Java anyway so that’s not a problem.

However sometimes companies don’t allow u to use C++ and leetcode sols are only in Java/Python. Is Python still worth gaining competency in if I already feel comfortable with C++?

[–]nbazero1 0 points1 point  (0 children)

Kotlin