@NeetCode i need a suggestion from you , i know python & c++ very well . so which one i should choose for interview purpose ? i mean which one is better ? please reply it really helps a lot
for queue I'd have mentioned something like ``` from collections import deque q = deque([1,2,3],maxlen=3) print(q) q.append(-1) print(q) q.appendleft(-2) print(q) ``` better than random op like here that does not show the queue essence :)
This video came out less than 12 hours after I failed to pass a coding assessment question that I did using Python. I never wrote Python code, but JS wasn’t an option for the assessment. I somehow managed to make it to the next step of the interview and I am not taking this video for granted. Thank you so much! 🎉
I started to learn Python before I did a web-dev bootcamp that was just JS. I have an interview assessment where JS isn’t available and I have to use Python, and making the switch back has been…difficult lol. So I’m with you as far as not taking this video for granted lol.
small note: it may be mentioned in the video but really the points on "arrays" are really discussing "lists". Arrays are distinct in python and available as part of the numpy package but generally only used for situations where memory is a consideration. Also true numpy arrays cannot be resized. For a nit picking interviewer this may be important. Video is excellent , great way to cram for an interview!
This video is everything I've learned about Python in the last 3 months and more! Thanks for such on-point crisp content, and for putting it all in one single video unlike other TH-camrs who make multiple never-ending clips with repetitive content
You are a true genius. The way you display the output is so easy to see. The comments on the code are so visual. By watching your videos I started to like practicing interview questions and algorithms in general and feel sorry that I was not learning algorithms in school in the clear way that you demonstrate to us. All in all, I am grateful that I found your channel.
At 7:09, The answer which is round off to -1 is definitely correct as -1.5 has been round to a bigger value to -1. It shows the value greater than or equal to 0.5 can be rounded off to correct value to its next greater integer value (1.5 can be rounded off to greater value 2 in positive no., and (-1.5) will be rounded off to greater value (-1) in negative no.) Yep, the explanation for it is awesome. Sometimes, its bit tricky for someone to find the particular negative value and might stuck over it. Thanks.!
Thanks, I am using python at work for more than 6 years and heaps and nested functions was new and very useful info for me. 1:23 Short addition to printing that can save you time if you do a lot of prints print(f'{n=}') is the same as print('n = ',n)
I started learning DSA with Python today and I wanted a Python refresher. as I had lost touch with it. Luckily, I came across this video and I can't believe this 26 min covered all topics. Thank you so much!
This is just amazing! I always look to refresh my python syntaxes after I stop coding in this language and waste time again and again. This video is so crisp and to the point.
Used to solve most LeetCode problems using Java but thanks to you I picked up Python and agreed that it's much easier to use for interview problems where ideas are more important. This video is really helpful for me to perfect my Python skills
this was so good, I was like 50% confident with my python collection skills and now I am alot more confident. I can simply google what I know that exists even if i forgot the syntax. This is what I truly need content that can show me that something exists to know what to search. We don't know what we don't know
I just want to point out that -x % y = z is mathmatically correct. Having the remainder be a negative number is incorrect. This is because it is based on the division theorem where Divident = (Divisor x Quotient) + remainder
This video was so good! Took a ton of notes to prepare for my upcoming interview. Actually learned some very cool tricks! Didn't know that nonlocal trick, I've been just returning my data structures out of my functions and passing them around that way my whole life!
10:48 not including index 3 means value 4 13:04 if u want to reverse the custom sort since default is asc but u can do? arr.sort(key=lambda x:len(x) reverse='true')
Great video! But, regarding the code shown at 6:30 of the video, I must clarify that the correct mathematical result of "-3 // 2" is "-2". This is because in the representation “Dividend = (divisor x quotient) + remainder”, the remainder must be non-negative. This is a widely accepted mathematical convention, and is useful in many applications. Thus, with the values in the example, the representation would be "-3 = (2 * -2) + 1". That said, be careful with "most languages" which are not consistent with mathematics. : )) Seriously, this may cause some error when coding some mathematical solution.
There is a way to generate the max heaps in Python. The heapq's module has "_heapify_max" and "_heappop_max" methods. You can test it with this code: "import heapq test = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] max_heap = heap._heapify_max(test) while test: print(heapq._heappop_max(test))" I'm not sure why they created them as a protected member of the module, but this is absolutely working fine.
Thanks for the great and concise video! One suggestion I would have is to leave some of the printouts from the examples on the screen for longer so we have time to inspect and easily pause if need be. Some of the results are on the screen for so briefly before switching to new subject that have to be ready and quick with the pause button to press. Pressing run earlier would have helped greatly while you talked instead of talking about the expected result and leaving us in unnecessary anticipation.
Great video as usual, loved how concise and straight to the point it is. You've convinced me to switch from Java to Python for interviews and programming puzzles 😁
I needed this. Ive been coding but as a game dev, and my mentor who want me to enter software development say i have to learn the Logic of Python. Thanks for this...even though im still making games on the side 😂😂
@NeetCode I really appreciate the quick refresher on python. I used it back in grad school and never touched it again. Would it be possible to break down every topic into an individual video that can be maintained as a playlist ? I may not be the sharpest tool in the box, however, it feels like certain sections of the current video are little fast.
BEST video of all!! I'm also deep learning python for code interviews and this has made my life so much easier!!! Thanks so much. Your videos are the bests!
Great video I've been trying to get around to learning python and this is a great brief on what's different from other coding languages saved me so much time.
7:13 int isnt really "rounding" the value. For -0,7 you would still get 0 if you make int() around it, yet the round should be -1 since its closer. Therefore int() is just deleting the values right after the dot, that in this case will be same as using math.ceil() for negative values.
Im Not preparing for coding Interviews as im already a Software Developer in Germany. But I wan't to increase my ability To solve algorithm based Problems and my Problem solving skills in general and your Videos are absolute Gold! I'll definately will take a look into Python as im currently only working with c# which ist Kind of noisy for those Problems.
Hi friend, love your channel, thank you so much for your efforts! I do have one suggestion, since you're teaching people to interview with Python, it might be helpful to follow PEP8 standards. Only interviewers with a background in Python will notice, however for experienced Python devs, not following the accepted style guidelines screams n00b which isn't ideal for interviewees trying to make a good impression. I know its a tiny detail which doesn't matter that much in the grand scheme because your channel is awesome and super helpful, however having more "Pythonic" style will definitely help junior devs put their best foot forward with more experienced Python folks.
You just need to be honest with the interviewer that you use python only for coding interviews. They will understand. One only needs to learn just enough python to pass coding interviews.
Really, really appreciate you my man! This video is exactly what I needed. Your hard work does not go unnoticed. You deserve all the recognition and praise for putting together an incredibly thoughtful and well presented Python for coding interviews video.
Great video! Still seems unreal that there's no native way to support a max-heap without that awkward workaround. I was expecting better from Python :)
Thanks a lot for this video. Please make a video on how you learnt Java development and what resources you referred to and what was your strategy to learn and work in it.
Yo just want to let you know that I can't afford the paid version now. But someday in the future when I have a better job imma buy a few and gift others as a token of appreciation.
Please also make a video regarding bisect function of py, it is also very useful. And also I have a question regarding heapq, what we should do if we want to have customized sorting?
Can someone help me with 15:12 from my understanding, using "x = [0] * 3" creates [0, 0, 0], but all 0's are same object but its okay since we usually do "x[0] = 1", creating a NEW object. It is now [1, 0, 0]. But still, 0's are same object so, use the "=" sign to make NEW object. Now 2D array makes it harder. x = [[0] * 2] * 2 x[0][0] = 1 We could think that since using "=", it will only update [0][0]. But no. We are using "*" TWICE. (x = [[0] * 2] * 2). X is an object inside of an object. meaning, it will give [[1,0],[1,0]] To make a NEW object, we change the highest object. In this case, x[0] = [1, 0] thats why it sucks to use (x = [[0] * 2] * 2) in 2D array. You need to make a brand new one from scratch like x[0] = [1, 0].
Great video! I definitely learnt new stuff too 🙂. I'll like to just note a couple of things here. In Python, the actual constructor is __new__(cls, *args, **kwargs) while the initialiser function is __init__(self, *args, **kwargs). And you can totally do else if: in one line as it's equivalent to elif: Regardless, amazing as always! Thanks neetCode!
Hi NeetCode, I'm wondering why your video about your internship experience at Capital One is not available now? That video was very interesting and wanted to see again since I got an offer from Capital One for TIP! Hope I can see that video again :)
🚀 All of the code is available at: neetcode.io/courses/lessons/python-for-coding-interviews
Timestamps:
1:13 - variables
2:40 - if-statements
4:00 - loops
6:06 - math
8:40 - arrays
12:38 - sorting
13:40 - list comprehension
14:20 - 2-d arrays
15:25 - strings
16:50 - queues
17:30 - hash sets
18:25 - hash maps
20:15 - tuples
20:55 - heaps
22:30 - functions
22:55 - nested functions
24:20 - classes
What is the theme you are using brother?
thanks
@NeetCode graph theory course pls.
@NeetCode i need a suggestion from you , i know python & c++ very well . so which one i should choose for interview purpose ? i mean which one is better ? please reply it really helps a lot
for queue I'd have mentioned something like
```
from collections import deque
q = deque([1,2,3],maxlen=3)
print(q)
q.append(-1)
print(q)
q.appendleft(-2)
print(q)
```
better than random op like here that does not show the queue essence :)
This video gives me life. If this video would ever cease to exist, I’d cry.
This video came out less than 12 hours after I failed to pass a coding assessment question that I did using Python. I never wrote Python code, but JS wasn’t an option for the assessment. I somehow managed to make it to the next step of the interview and I am not taking this video for granted. Thank you so much! 🎉
I started to learn Python before I did a web-dev bootcamp that was just JS. I have an interview assessment where JS isn’t available and I have to use Python, and making the switch back has been…difficult lol. So I’m with you as far as not taking this video for granted lol.
Bro how's that even possible ? What kindof questions they asked? Would be helpful to know
I have interview in 15 minutes 😬
What was the coding problem you were provided?
small note: it may be mentioned in the video but really the points on "arrays" are really discussing "lists". Arrays are distinct in python and available as part of the numpy package but generally only used for situations where memory is a consideration. Also true numpy arrays cannot be resized. For a nit picking interviewer this may be important. Video is excellent , great way to cram for an interview!
This video is everything I've learned about Python in the last 3 months and more! Thanks for such on-point crisp content, and for putting it all in one single video unlike other TH-camrs who make multiple never-ending clips with repetitive content
This is probably the best tutorial for someone who knows another programming language and wants to learn python. Thank you for the tutorial :)
This is the best video I have seen on using Python for anything
You are a true genius. The way you display the output is so easy to see. The comments on the code are so visual. By watching your videos I started to like practicing interview questions and algorithms in general and feel sorry that I was not learning algorithms in school in the clear way that you demonstrate to us. All in all, I am grateful that I found your channel.
This isn't the python helper video for the interviews. This is the best recap/crash course video ever published on Python in the world.
you convinced me to change from javascript to python for coding interviews
Broooo same….
At 7:09,
The answer which is round off to -1 is definitely correct as -1.5 has been round to a bigger value to -1.
It shows the value greater than or equal to 0.5 can be rounded off to correct value to its next greater integer value
(1.5 can be rounded off to greater value 2 in positive no., and (-1.5) will be rounded off to greater value (-1) in negative no.)
Yep, the explanation for it is awesome. Sometimes, its bit tricky for someone to find the particular negative value and might stuck over it.
Thanks.!
Thanks, I am using python at work for more than 6 years and heaps and nested functions was new and very useful info for me. 1:23 Short addition to printing that can save you time if you do a lot of prints print(f'{n=}') is the same as print('n = ',n)
This is the best cheatsheet for python syntax ever. Got a coding interview tomorrow, thank god you posted. ❤
I found this tutorial to be the most precise yet packed with fascinating details! For kicks, I totally get all the Java lingo!
This video is insane for people who've already been programming but not in python, thank you neetcode god
I started to learn Python about two months ago, and this is the best training video for Python.
I started learning DSA with Python today and I wanted a Python refresher. as I had lost touch with it. Luckily, I came across this video and I can't believe this 26 min covered all topics. Thank you so much!
how is it going ??
The best tutorial for someone who knows another programming language and wants to learn python
Not sure if it was mentioned or not, but for problems like path sum II it can be useful to understand deep copy vs shallow copy.
This is just amazing! I always look to refresh my python syntaxes after I stop coding in this language and waste time again and again. This video is so crisp and to the point.
Used to solve most LeetCode problems using Java but thanks to you I picked up Python and agreed that it's much easier to use for interview problems where ideas are more important. This video is really helpful for me to perfect my Python skills
Heyy as indian can i solve dsa in python n gove job intevriew with python
I think the world rests on people like you.
Thank you so much!!
Np 🙂
The most recent version of python released updated syntax allowing the use of increment ++ and decrement -
this was so good, I was like 50% confident with my python collection skills and now I am alot more confident. I can simply google what I know that exists even if i forgot the syntax. This is what I truly need content that can show me that something exists to know what to search. We don't know what we don't know
Thanks NeetCode! can't wait for your system design videos :)
This is where I can get everything I need for coding part of my interview. Thanks Neetcode. You have given us enought
I just want to point out that -x % y = z is mathmatically correct. Having the remainder be a negative number is incorrect. This is because it is based on the division theorem where Divident = (Divisor x Quotient) + remainder
thank you. I refreshed everything in python in 26 mins
This video was so good! Took a ton of notes to prepare for my upcoming interview. Actually learned some very cool tricks! Didn't know that nonlocal trick, I've been just returning my data structures out of my functions and passing them around that way my whole life!
This is such a brilliantly constructed video! Thank you so much. Could not have learned all this python I need for interviews without your help!
For guys like me who are switching from Java to Python for LeetCoding, this is really helpful!
why you're shifting?
@@harshivam Python syntax is much shorter and easier to write. I am NEVER EVER going back to Java for coding interviews
@@sarthakgupta290 is it good go in coding interview with python??????
@@hritikroshanmishra3630 Absolutely
But in some companies they don't even mention python as an option to write code.
10:48 not including index 3 means value 4
13:04 if u want to reverse the custom sort since default is asc but u can do?
arr.sort(key=lambda x:len(x) reverse='true')
this was exactly what i was looking for, thank you! Perfect timing
Great video! But, regarding the code shown at 6:30 of the video, I must clarify that the correct mathematical result of "-3 // 2" is "-2". This is because in the representation “Dividend = (divisor x quotient) + remainder”, the remainder must be non-negative. This is a widely accepted mathematical convention, and is useful in many applications. Thus, with the values in the example, the representation would be "-3 = (2 * -2) + 1". That said, be careful with "most languages" which are not consistent with mathematics. : )) Seriously, this may cause some error when coding some mathematical solution.
Very helpful! I studied Python a few years ago, but I didn't remember many things in this video. Thanks!
There is a way to generate the max heaps in Python. The heapq's module has "_heapify_max" and "_heappop_max" methods. You can test it with this code:
"import heapq
test = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
max_heap = heap._heapify_max(test)
while test:
print(heapq._heappop_max(test))"
I'm not sure why they created them as a protected member of the module, but this is absolutely working fine.
an array is a list? and a hashmap a dictionary? yes?
Array is not a list because array stores homogeneous data type while list stores heterogeneous data type
the most helpful video I've ever watched for python code interviews
Python is also a good intro to more complex languages since it uses a lot of coding conventions that can be found in other popular languages
12:33
Shortest way to reverse
x = [1, 2, 3, 4]
print(x[::-1])
will print
[4, 3, 2, 1]
Thanks for the great and concise video! One suggestion I would have is to leave some of the printouts from the examples on the screen for longer so we have time to inspect and easily pause if need be. Some of the results are on the screen for so briefly before switching to new subject that have to be ready and quick with the pause button to press. Pressing run earlier would have helped greatly while you talked instead of talking about the expected result and leaving us in unnecessary anticipation.
16:20 Ord() for ascii value! Nice intuitive function name, easy to remember. /s
6:30 - that's why, we can better say it as *floor division*
7:48 - can also be done with abs(), just in case, importing math isn't possible
WOW 🥺 I love you ❤️
I am new to programming now I am programmer. Thanks
All good. I use python at work. When it comes to Object oriented design interviews Java/C++ works the best. Python falls short there.
Great video as usual, loved how concise and straight to the point it is. You've convinced me to switch from Java to Python for interviews and programming puzzles 😁
Wonderfully typed! Love the comments in the code! Thank you for this video!
Thank you for providing this, need to get back in the saddle and things like this really help
I needed this. Ive been coding but as a game dev, and my mentor who want me to enter software development say i have to learn the Logic of Python. Thanks for this...even though im still making games on the side 😂😂
@NeetCode I really appreciate the quick refresher on python. I used it back in grad school and never touched it again. Would it be possible to break down every topic into an individual video that can be maintained as a playlist ? I may not be the sharpest tool in the box, however, it feels like certain sections of the current video are little fast.
From Java to Python here! Love the concise of Python and hate we must complete 2 DSA problems in 45 min interviews.
Why hate?
@@andiuptown1711 probably because due to the time restriction
This is a great concise yet informative summary! Thank you!
BEST video of all!! I'm also deep learning python for code interviews and this has made my life so much easier!!! Thanks so much. Your videos are the bests!
Thanks you. This was so damn helpful ! I have been putting thiss off too long but what looked like gibberish a year ago makes a ton of sense now. 🎉
This video cleared alot of my small problems in for loops and lambda function. Good work brother.
Great video I've been trying to get around to learning python and this is a great brief on what's different from other coding languages saved me so much time.
7:13 int isnt really "rounding" the value. For -0,7 you would still get 0 if you make int() around it, yet the round should be -1 since its closer.
Therefore int() is just deleting the values right after the dot, that in this case will be same as using math.ceil() for negative values.
Thank you so much! Loved how concise and clear your examples are!
Doing an interview for a role that will primarily use python tomorrow, if I get the job, I'll subscribe to NeetCode's only fans
Good luck, you got this!!!
Update
they took forever to get back to me buy\t, yes I'm starting on Monday! @@andiuptown1711
Technically speaking, self is not a keyword in Python. You can replace it with anything else you wish.
good point!
Amazing
I find it hard to shift from java to python due to these kind of differences
this is great. Thanks for your time and effort bro.
Personally for me, you talk really fast, so I suggest 0.75 speed in 'runtime;. lol
Im Not preparing for coding Interviews as im already a Software Developer in Germany. But I wan't to increase my ability To solve algorithm based Problems and my Problem solving skills in general and your Videos are absolute Gold!
I'll definately will take a look into Python as im currently only working with c# which ist Kind of noisy for those Problems.
Hi friend, love your channel, thank you so much for your efforts! I do have one suggestion, since you're teaching people to interview with Python, it might be helpful to follow PEP8 standards. Only interviewers with a background in Python will notice, however for experienced Python devs, not following the accepted style guidelines screams n00b which isn't ideal for interviewees trying to make a good impression. I know its a tiny detail which doesn't matter that much in the grand scheme because your channel is awesome and super helpful, however having more "Pythonic" style will definitely help junior devs put their best foot forward with more experienced Python folks.
You just need to be honest with the interviewer that you use python only for coding interviews. They will understand. One only needs to learn just enough python to pass coding interviews.
The best video you've ever made is this one
Thanks. Thanks a lot for this. I exactly looking for whether I can use python at big tech companies. You're really awesome.
New fan here. I gonna watch every single video and thumb up any of them!
Thank you 🙏
arr.sort(key=lambda x:len(x)) == arr.sort(key=len)
its same
Really, really appreciate you my man! This video is exactly what I needed. Your hard work does not go unnoticed. You deserve all the recognition and praise for putting together an incredibly thoughtful and well presented Python for coding interviews video.
Amazing video very crisp content . Thanks for making this !!
Отличное видео, большое спасибо! Очень удобно, что все чётко и посуществу, без длительных пауз и рассусоливаний
collections can be of dynamic type , note how elements are integer , string
```
from collections import deque
queue = deque()
queue.append(1)
queue.append("ab")
queue.append(1)
print(queue)
mySet = set(queue)
print(mySet)
myMap = {}
myMap["abc"] = 1
myMap[1] = "abc"
print(myMap)
```
output
```
deque([1, 'ab', 1])
{1, 'ab'}
{'abc': 1, 1: 'abc'}
```
if you dont want end line
```
print("Hello", end="")
print("World")
```
output :
```
HelloWorld
```
u can add any string to end = "" ,
so print("Hello") is same as print("Hello", end="
")
Great video! Still seems unreal that there's no native way to support a max-heap without that awkward workaround. I was expecting better from Python :)
Thanks a lot for this video.
Please make a video on how you learnt Java development and what resources you referred to and what was your strategy to learn and work in it.
Yo just want to let you know that I can't afford the paid version now. But someday in the future when I have a better job imma buy a few and gift others as a token of appreciation.
it'd better call [1, 2, 3] as list, as oppposed to an array. I think array refers to numpy array
Coming from Java this syntax is so bizarre to me ahaha, great video btw !
This is super useful!!!! Thank you so much NeetCode!!!
A great video for people who are already comfortable coding in other programming languages and want to learn python! Thanks man!
Great video. Good for refreshing python concepts
the modulo and minus modulo is because of how its mathematically written
Hi!
15:13 - can this part be explained in detail?
By the way, thanks much for the amazing content you share!
Python: Use and instead of &&, but use str() instead of string()
Great video. Did you touch on linked lists? I might've missed it.
perfect video for a longtime java user like me
Excellent! Hope to see more on System Design. ^_^
Very helpful. Thanks for the organization!
Please also make a video regarding bisect function of py, it is also very useful. And also I have a question regarding heapq, what we should do if we want to have customized sorting?
Thanks!
nice content ! will you make it for advance questions.
BIG thank you! ❤
Really good list. Love how concise it is.
You missed something important though: taking input from file and from console
Thank you so much. This video helps me a lot.
Thanks man, you helped me a lot! Damn useful!
Doing God's work right here
Can someone help me with 15:12
from my understanding, using "x = [0] * 3" creates [0, 0, 0], but all 0's are same object
but its okay since we usually do "x[0] = 1", creating a NEW object. It is now [1, 0, 0]. But still, 0's are same object
so, use the "=" sign to make NEW object.
Now 2D array makes it harder.
x = [[0] * 2] * 2
x[0][0] = 1
We could think that since using "=", it will only update [0][0]. But no.
We are using "*" TWICE. (x = [[0] * 2] * 2).
X is an object inside of an object.
meaning, it will give [[1,0],[1,0]]
To make a NEW object, we change the highest object.
In this case, x[0] = [1, 0]
thats why it sucks to use (x = [[0] * 2] * 2) in 2D array.
You need to make a brand new one from scratch like x[0] = [1, 0].
this has screwed me so many times. Such weird thing to keep in back of your mind
I think by “appending” strings together you mean “concatenate”.
This video helped a lot, thank you.
Can you please make more videos similar to this for Python , thanks
Great video! I definitely learnt new stuff too 🙂. I'll like to just note a couple of things here.
In Python, the actual constructor is __new__(cls, *args, **kwargs) while the initialiser function is __init__(self, *args, **kwargs). And you can totally do else if: in one line as it's equivalent to elif:
Regardless, amazing as always! Thanks neetCode!
Hi NeetCode, I'm wondering why your video about your internship experience at Capital One is not available now? That video was very interesting and wanted to see again since I got an offer from Capital One for TIP! Hope I can see that video again :)