I'd also appreciate knowing whether you thought those challenges accurately accessed the coding skills you needed to do your job.
I’m sorry if this is a repeated question but I’m really anxious. I’m a rising senior with interviews this semester.
Here’s the situation: I need to focus on a language to ace the technical interviews. I have learnt all the data structures (tree, hash maps,heap,etc) on C, but from the past year I have been using python really heavily and I’m super familiar with it.
However, no way I’m using C in interviews. My friends are learning C++ because they believe that it gives an advantage over python. So my question is if that’s true for DSA and algorithms?
I feel that I should stick to python and learn the dsa and algorithms there. There shouldn’t be a major difference in the approach to solving the problem right? Only the syntax will differ.
Is it worth learning C++ because it’s almost like C or stick to python and learn it’s syntax?
Also is there any material that has every dsa and algorithm? And for interview syllabus like computer network, operating systems, etc?
Edit: Thank you everyone for your replies. Looks like I will stick with python for the interviews for now. But I will definitely learn C++ in the future. Also thank you for letting me know that the algorithms text book is more than enough.
I'm a data analyst with a fair understanding of Python. I was interviewed for a Data QA Engineer position, and the coding round is tomorrow. I'm getting extremely anxious about making a fool out of myself tomorrow and need any last-minute tips and tricks to help myself even a little bit.
UPDATE: There was no live coding or any coding at all. It's weird because the email said there would be live coding in Python, but instead, they asked me probability and logical reasoning questions. IMO, that is a better assessment of my intellectual ability, so I'm happy! Thank you for your kind words and encouragement; they helped me immensely. I will post another update if I receive an offer or not.
I'm about to go to my first Python interview and I'm compiling a list of all possible interview questions. Based on resources that I've found here, here and here I noted down the following common questions, what else should I add?
easy/intermediate
-
What are Python decorators and how would you use them?
-
How would you setup many projects where each one uses different versions of Python and third party libraries?
-
What is PEP8 and do you follow its guidelines when you're coding?
-
How are arguments passed – by reference of by value? (easy, but not that easy, I'm not sure if I can answer this clearly)
-
Do you know what list and dict comprehensions are? Can you give an example?
-
Show me three different ways of fetching every third item in the list
-
Do you know what is the difference between lists and tuples? Can you give me an example for their usage?
-
Do you know the difference between range and xrange?
-
Tell me a few differences between Python 2.x and 3.x?
-
The with statement and its usage.
-
How to avoid cyclical imports without having to resort to imports in functions?
-
what's wrong with import all?
-
Why is the GIL important? (This actually puzzles me, don't know the answer)
-
What are "special" methods (<foo>), how they work, etc
-
can you manipulate functions as first-class objects?
-
the difference between "class Foo" and "class Foo(object)"
tricky, smart ones
-
how to read a 8GB file in python?
-
what don't you like about Python?
-
can you convert ascii characters to an integer without using built in methods like string.atoi or int()? curious one
subjective ones
-
do you use tabs or spaces, which ones are better?
Ok, so should I add something else or is the list comprehensive?
I'll try my hand at a few:
What are Python decorators and how would you use them?
They extend past python, and are functions that take a function as an argument and return functions. A simple example might be a decorator that takes a function, prints its args to stdout, prints the return value to stdout, then returns that return value. The syntax in Python is usually done with the @decorator_name above a function definition.
How would you setup many projects where each one uses different versions of Python and third party libraries?
virtualenv
What is PEP8 and do you follow its guidelines when you're coding?
A coding standard, and I try to. pylint is a great help.
How are arguments passed – by reference of by value?
Probably all through reference, but I'm not sure about primitives under the hood. Anyone know this? If you pass f(12, 81), are those by value?
Do you know what list and dict comprehensions are? Can you give an example?
ways to construct a list or dict through an expression and an iterable.
>>> x = [(a, a+1) for a in range(5)]
>>> y = dict((a,b) for a,b in x)
>>> x
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)]
>>> y
{0: 1, 1: 2, 2: 3, 3: 4, 4: 5}
Show me three different ways of fetching every third item in the list
[x for i, x in enumerate(thelist) if i%3 == 0]
for i, x in enumerate(thelist):
if i % 3: continue
yield x
a = 0
for x in thelist:
if a%3: continue
yield x
a += 1
Do you know what is the difference between lists and tuples? Can you give me an example for their usage?
Tuples are immutable. A tuple might be a good type for a coordinate inst var in some class. Lists are ordered collections, but with a tuple, each index generally has a certain meaning, so coord[0] is the x coordinate and coord[1] is y.
Do you know the difference between range and xrange?
Range returns a list of the full sequence while xrange generates each element iteratively like you would with the "yield" keyword. This changes in python3, and the default behavior is to yield like xrange. I think xrange is out.
Tell me a few differences between Python 2.x and 3.x?
The previous answer. print is no longer a statement and is just a function ("print 5" won't work anymore and you need parens), they added the Ellipse object (...). That's all I know off hand.
The with statement and its usage.
It's for context management, and you can define your own that implement enter init and exit if it might help. This is very useful for opening and closing files automatically (with open(foo) as bar:)
How to avoid cyclical imports without having to resort to imports in functions?
Refactoring your code? Not sure. When I've ran into this I generally have restructured functions into different modules which ended up cleaning everything anyway.
what's wrong with import all?
You can overwrite functions and this can be dangerous especially if you don't maintain that module.
-
rewrite.py def open(foo): print('aint happening!')
-
test.py from rewrite import * z = open('test.txt')
prints aint happening!
Why is the GIL important?
It has to do with preventing true multithreaded bytecode, and has been an issue forever. I think python bytecode execution is protected with the Global Interpreter Lock so every bc execution is atomic. Explained best here: http://wiki.python.org/moin/GlobalInterpreterLock
You might want to consider writing a multithreaded module or program in C and wrapping it with Python if this is an issue for you.
What are "special" methods (<foo>), how they work, etc
These are methods like str and gt, which override behavior of other global functions like str() and operators like >. enter and exit will be used with the with keyword, and there are many more like getattr. Overriding getattr can result in some very unpredictable behavior with a dynamic language like Python, and you should be very careful when you use magic like that.
can you manipulate functions as first-class objects?
Yes. eg. they can be passed as args to functions.
the difference between "class Foo" and "class Foo(object)"
class Foo(object) inherits from the new-style object. I don't know the specifics, but here's stack overflow: http://stackoverflow.com/questions/4015417/python-class-inherits-object
how to read a 8GB file in python?
Operate on chunks, and not one byte at a time. Be wary about the RAM of the host machine. What is the nature of the data such that it is so large? How are you operating on it? What are you returning? Are you accessing it sequentially or randomly? There's a lot more to ask than to answer here.
what don't you like about Python?
It's slow, and it can be too dynamic for certain tasks in my opinion. It is not compiled. It can be very unpredictable. People abuse the flexibility of it sometimes.
can you convert ascii characters to an integer without using built in methods like string.atoi or int()? curious one
struct.unpack("<I", foo)[0]
ord, chr
do you use tabs or spaces, which ones are better?
Spaces. Stick to PEP8 when possible.
Ok, so should I add something else or is the list comprehensive?
-
generators/yield keyword
-
what is multiple inheritance / does python have multiple inheritance
-
is Python compiled, interpreted and/or emulated
-
What differentiates Python from Ruby
-
How do you debug your Python? What's pdb and how do you use it?
-
How do you modify global variables in a function? Why should you avoid this?
-
Use of the re module... what is it, give an example, etc.
Would be very good if you added the brief answers for the questions above :)
I’m beginner to intermediate in python. I work in quality assurance and have an interview coming up for python with robot framework job. I know robot framework well but not confident enough in python. I’m 100% sure they’ll ask me to code so please help me on where can I practice ? Thank you in advance.
Recently my workplace has started hiring python developers and since I'm one of the python guy I am asked to take python interviews starting today.
Now in my 4-5 years of learning and working with python I have accumulated a lot python challenges in my head as I'd constantly trying to come up questions that an interviewer might ask me.
Yesterday I made some samples questions and share with my senior who found the questions little too deep for a 3 YOE Python full stack developer role.
Please give me few questions to get some idea that I can use or be inspired from to make new set of questions.
Also is this question really too much for such interview: Given a file containing very large string (around a gb), devise an optimal solution to get the first non repeating Character.
Never learned it, never programmed in it, how can I go about learning just enough for interviews? I obviously don't want to go through a dense Python textbook and learn all the intricacies of it.
I was just wondering how often Python is acceptable for coding interviews in general. At my last internship interview the interviewer asked me what I was comfortable in, and I said "Python and C++", and tested my knowledge in both.
However, I feel much much more confident in Python overall. To the point where when I practice Leetcode, I almost always choose to do the questions in Python. When it comes time to begin the search for actual FT positions, how often would I be able to use Python for the interview?
Title.
I've never been though it before and don't know what to expect.
What is it usually about? OOP? Dicts, lists, loops, basic stuff? Algorithms?
If you have any leetcode question or if you remember some from your exeperience, please share!
Thanks
I'm a java guy but seems like Python is the way to go for coding interviews according to this sub as well as my friends.
Do you guys just use simple language constructs like for loops and methods, or do you also use the weird Python-exclusive list and dictionary comprehension in interviews and leetcode?
Is it feasible if I use python for coding interviews/leetcode but code in the same style I write my Java code? Or are list/dictionary comprehensions a necessary evil if I want to use Python?
A post about a job interview for Python started me a-googling. I searched the phrase "python interview questions" and up popped a variety of Python interview question lists. Reading through them has really helped me to solidify details of the language. Other learners might benefit too. Here's a good one:
https://www.interviewbit.com/python-interview-questions/
Role: Automation Test Developer.
Questions asked:
1: Basics of Linux, few tricky commands, what are inodes, setting up networking etc etc.
2: Python:
Given a file, write a function which accepts a version number, date and returns pass or fail. EDIT: the file structure is basically a test result log file which contains lines of information. Each line has a version and date, tests run and results. I was supposed to return results which are pass fail based on the version number and date given.:) Reverse a sentence without using slicing. List comprehension basics.
What I did right: I wrote enough code solving pythonic interview problems, and I was comfortable writing the code in the interview.
what I did wrong: Focused too much on interview type problems, like Coin change, linked list etc etc. Should have also focused on some real use cases of python. For example, how to test a code with different inputs, how to parse few lines from a file, how to schedule a cron job etc etc.
TLDR; Don't just bust your head trying to solve interview challenges from cracking the coding interview. Also learn to make some real world programs.
Hi,
I learned web application development by myself, two years ago. Since then, I worked on Django, Bootstrap, Python, Javascript. I have an interview lined for a Python Engineer role. Can somebody suggest me the questions can be asked from a two years experienced guy in Python. Thanks!
Hey so I passed a couple of rounds of interviews for a business analyst role that involves working with data and now I have technical interview and I would be given data sets and etc that would involve python as well and I would have to provide my findings to them. For my background I come from the Java/software development role and I was wondering which way to learn python is the fastest and efficient. Really appreciate it
Folks choose to write in Python in interviews, even if it's not their primary language at work. The problem is they code in Python but think in other languages, failing to leverage the full potential of idiomatic Python.
I've gathered the top mistakes non-Pythonist candidates make when writing code during interviews, along with how to improve them:
____________________________________________
Before we dive into the list, let me introduce myself: My name is Nurbo and I'm an ex-FAANG Senior Software Engineer currently on sabbatical. I have a newsletter where I send tips like this every day straight to your inbox: blog.faangshui.com. Let's connect on Linkedin! Now let's get back to the list...
____________________________________________
1. Inefficient Looping Over Indices Instead of Elements
How People Write It:
nums = [1, 2, 3, 4, 5]
for i in range(len(nums)):
print(nums[i])How It Can Be Better Written:
nums = [1, 2, 3, 4, 5]
for num in nums:
print(num)Explanation:
Issue: Using
range(len(nums))to iterate over list indices is unnecessary and less readable.Improvement: Directly iterate over the elements using
for num in nums, which is more Pythonic and efficient.
2. Manually Managing Loop Indices When Enumerate Exists
How People Write It:
words = ["apple", "banana", "cherry"]
index = 0
for word in words:
print(f"{index}: {word}")
index += 1How It Can Be Better Written:
words = ["apple", "banana", "cherry"]
for index, word in enumerate(words):
print(f"{index}: {word}")Explanation:
Issue: Manually incrementing an index variable is error-prone and verbose.
Improvement: Use
enumerate()to get both the index and the element in each iteration.
3. Using Traditional Swapping Instead of Tuple Unpacking
How People Write It:
temp = a a = b b = temp
How It Can Be Better Written:
a, b = b, a
Explanation:
Issue: The traditional method requires an extra variable and more lines of code.
Improvement: Python's tuple unpacking allows swapping variables in a single, clear statement.
4. Not Utilizing defaultdict for Counting
How People Write It:
counts = {}
for item in items:
if item in counts:
counts[item] += 1
else:
counts[item] = 1How It Can Be Better Written:
from collections import defaultdict
counts = defaultdict(int)
for item in items:
counts[item] += 1Explanation:
Issue: Manually checking for key existence leads to verbose code.
Improvement: Use
defaultdict(int)to automatically initialize counts to zero.
5. Not Utilizing Counter from collections for Counting Elements
How People Write It:
def is_anagram(s, t):
if len(s) != len(t):
return False
count_s = {}
count_t = {}
for c in s:
count_s[c] = count_s.get(c, 0) + 1
for c in t:
count_t[c] = count_t.get(c, 0) + 1
return count_s == count_tHow It Can Be Better Written:
from collections import Counter
def is_anagram(s, t):
return Counter(s) == Counter(t)Explanation:
Issue: Manually counting elements is verbose and error-prone.
Improvement: Use
Counterto efficiently count elements and compare.
6. Not Using List Comprehensions for Simple Transformations
How People Write It:
squares = []
for num in nums:
squares.append(num * num)How It Can Be Better Written:
squares = [num * num for num in nums]
Explanation:
Issue: Using loops for simple list transformations is less concise.
Improvement: List comprehensions provide a readable and efficient way to create lists.
7. Not Using zip to Iterate Over Multiple Sequences
How People Write It:
for i in range(len(list1)):
print(list1[i], list2[i])How It Can Be Better Written:
for item1, item2 in zip(list1, list2):
print(item1, item2)Explanation:
Issue: Using indices to access elements from multiple lists is less readable.
Improvement: Use
zip()to iterate over multiple sequences in parallel.
8. Not Using any() or all() for Checking Conditions
How People Write It:
def has_positive(nums):
for num in nums:
if num > 0:
return True
return FalseHow It Can Be Better Written:
def has_positive(nums):
return any(num > 0 for num in nums)Explanation:
Issue: Writing loops for simple condition checks adds unnecessary code.
Improvement: Use
any()to check if any element meets a condition.
9. Re-Implementing sum(), max(), or min() Instead of Using Built-in Functions
How People Write It:
def find_sum(nums):
total = 0
for num in nums:
total += num
return totalHow It Can Be Better Written:
def find_sum(nums):
return sum(nums)Explanation:
Issue: Manually calculating sums or finding maximum/minimum values is unnecessary.
Improvement: Use built-in functions like
sum(),max(), andmin()for clarity and efficiency.
10. Not Using set Operations for Common Set Logic (Intersection, Union, Difference)
How People Write It:
def common_elements(list1, list2):
result = []
for item in list1:
if item in list2:
result.append(item)
return resultHow It Can Be Better Written:
def common_elements(list1, list2):
return list(set(list1) & set(list2))Explanation:
Issue: Manually checking for common elements is less efficient.
Improvement: Use set operations like intersection (
&), union (|), and difference (-) for cleaner and faster code.
11. Not Using Dictionary's get() Method with Default Values
__________________
Alright the list has gotten too long. You can find the rest in my blog: https://blog.faangshui.com/p/write-python-like-you-mean-it
Is there any concise recommended resource, e.g. PDF/web page/video that discusses what are the most importance algorithms to know, the data structures to be familiar with in Python programming language to pass coding interviews?
I'm aware there are books of cracking interviews that are hundreds of pages, and I'm looking for a distilled version of all that.
I code in java and my friend does too, however, he told me that python is way easier to code in. He told me that two sum can be done in half the lines of code that it would normally take you to do the same in java. Some people on YouTube have also mentioned this. I feel comfortable with java and despite everyone saying that python is easy because it reads like english, I despise that it does not have curly braces and the the indenting.
Is python really worth learning and does it actually make coding easier(friend says the libraries are more useful than java’s)?
I am comfortable with both, but sometimes C++ syntax bothers me, and it takes time to write it. but with python i have seen people saying, the same solution that passes in C++ gives TLE in Python. It is a rare case, but it happens sometimes.