r/learnpython • u/Dexteroid • Apr 10 '19
My recent interview experience on Python.
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.
16
u/SOADNICK Apr 10 '19
Thank you for the info, may I ask how many (if any) years of experience were required and how many do you have? Is this position considered junior?
13
u/Dexteroid Apr 10 '19
This is mid seniority. The tech part is I guess just the filter. for this post they needed 5 + years on QA automation role, with 3 years or more in Test planning, Test matrix creation etc.
9
Apr 10 '19
Reverse a sentence without using slicing.
This is a dumb question, in practice just use the best solution there is.
1
u/Dexteroid Apr 10 '19
There are no dumb questions. in Python we use so many things which are python oriented and don't exist in other languages, some times the interviewers are looking for an agnostic solution which is more generic. All the people who are using .reversed(), .sorted() might not actually be able to implement a reverse function or sorted. The idea is not to write a reverse function, the idea is whether you understand what goes on behind it.
2
Apr 10 '19
I guess, but if the code works and is efficient then it's okay. And you can look up reversed() in 30 seconds.
I wrote our interview process, we have a Docker image with some questions (mostly focussing on SQL).
For Python we focus more on testing, linting, using type hints, etc. for good deployment practices, as those are the things that really can trip us up.
5
u/dirk2654 Apr 10 '19
As someone who has never been in an interview like this, how does it go? Do you just write it down on paper as they ask you these questions, or do they set you up at a computer and have you take a test?
9
u/Dexteroid Apr 10 '19
They used the website called codesignal.com, it's free to use for anyone to practice. Your session is shared with your interviewer.
3
6
u/nate256 Apr 10 '19 edited Apr 10 '19
1 Given a file, write a function which accepts a version number, date and returns pass or fail? Hope you didn't miss this one.
import random
GIVEN_FILE = "a.txt"
def function(version, date):
return random.choice(["pass", "fail"])2
def revsenwords(sen):
return " ".join(reversed(sen.split())
def revsenchars(sen):
return "".join(reversed(sen))3
[x for x in basics]3
u/Dexteroid Apr 10 '19
Ha ha I should have been more clear. the file structure is basically a test result 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 :)
1
u/kl31 Apr 10 '19
Ha ha I should have been more clear. the file structure is basically a test result 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 :)
You got trolled so hard man.
1
2
u/zr0gravity7 Apr 10 '19
in an interview wouldn't you opt to use a list comprehension or iterator for part 2 rather than a built in method. JUst to flex knowledge
1
u/Decency Apr 11 '19
Flexing knowledge means using the right tool for the job, not the most complicated one you know. ESPECIALLY in Python.
3
Apr 10 '19
Thanks bro! Actually I'm thinking of switching from java to python so this might be helpful. Do you have any more suggestions for me?
2
u/Dexteroid Apr 10 '19
python so
I stumbled upon many jobs for framework development, all needed Selenium driver api and java knowledge. May be that could be a niche area for you to explore?
3
u/roryokane Apr 11 '19 edited Apr 11 '19
Given a file, write a function which accepts a version number, date and returns pass or fail. […]
I gave solving this a go. I had to assume some details of the file format and desired output, but even if my assumptions are wrong, solving the problem I did still forced me to learn a decent amount of Python techniques. Given a file test_log.txt with these lines:
v1.0 2019-04-10 4 fail
v1.0 2019-04-10 4 pass
v0.9 2019-04-10 6 pass
v1.0 2019-04-10 3 pass
v1.0 2019-04-09 3 pass
v1.0 2019-04-09 2 pass
v1.0 2019-04-09 2 fail
v0.9 2019-04-09 6 pass
v0.9 2019-04-08 6 pass
v0.9 2019-04-07 5 failRunning python main.py v1.0 2019-04-10 in the same directory will output this:
Filtering to results for version v1.0 on date 2019-04-10
Passing lines:
v1.0 2019-04-10 4 pass
v1.0 2019-04-10 3 pass
Failing lines:
v1.0 2019-04-10 4 failWhere main.py contains this Python code:
import sys
pass_lines = []
fail_lines = []
target_version = sys.argv[1]
target_date = sys.argv[2]
print(f"Filtering to results for version {target_version} on date {target_date}")
with open('./test_log.txt') as log_file:
for line in log_file:
(version, date, _num_tests, pass_or_fail) = line.split()
if not (version, date) == (target_version, target_date):
continue
line = line.rstrip()
if pass_or_fail == "pass":
pass_lines.append(line)
elif pass_or_fail == "fail":
fail_lines.append(line)
else:
print(f"Invalid test result status: #{line}", file=sys.stderr)
print("Passing lines:")
for line in pass_lines:
print(line)
print("Failing lines:")
for line in fail_lines:
print(line)As a bonus, here is the equivalent program in the Ruby programming language. I actually wrote this version first since I know Ruby better than Python.
pass_lines = []
fail_lines = []
target_version = ARGV[0]
target_date = ARGV[1]
puts "Filtering to results for version #{target_version} on date #{target_date}"
File.open('./test_log.txt') do |log_file|
log_file.each_line do |line|
version, date, _num_tests, pass_or_fail = line.split
next unless [version, date] == [target_version, target_date]
case pass_or_fail
when "pass"
pass_lines.push line
when "fail"
fail_lines.push line
else
$stderr.puts "Invalid test result status: #{line}"
end
end
end
puts "Passing lines:"
pass_lines.each do |line|
puts line
end
puts "Failing lines:"
fail_lines.each do |line|
puts line
endRun that with ruby main.rb v1.0 2019-04-10 to get the same output as the Python program.
2
u/Dexteroid Apr 11 '19
yeah, your Python solution is pretty close to what I ended up writing. Good thing you wrote the solution here, people might be benefited from it. Thank you!
3
u/elbiot Apr 11 '19
My understanding is that it's hard to break out of testing/QA into a development role. If you want to do development, shoot for that
1
u/Dexteroid Apr 11 '19
The thing is that, if I do that, I lose my experience of QA, automation, project management, product planning and start fresh. My end goal is to just be a product manager in an AGILE environment. Possibly manage the entire development team and look at the product overall.
1
u/Decency Apr 11 '19 edited Apr 11 '19
I've been doing test automation for 5 years or so (among a variety of other things) and have had multiple opportunities at different companies to move into dev or to take a new job as a developer. Not interested, for now.
If it's what you want to do, make that timeline clear to your manager and be willing to find somewhere new to work if they won't accommodate you. If you never take the initiative on projects outside of test automation to prove yourself, it seems pretty easy to get stuck there.
23
u/dillpicklezzz Apr 10 '19
Short but sweet. This is an excellent post and I wish there were a Weekly Thread for this exactly
5
14
u/cipher315 Apr 10 '19
Glad you emphasized this stuff. It's all generally true. For a python job, we are not looking at your ability to write more low-level solutions, See classic interview problems OP mentioned. If you were going to be working on low-level stuff Python is probably the wrong language, you want something like C C++ GO ect. A lot of your python jobs will be about taking files/ data objects, normally JSON or XML, searching for and extracting relevant data and then doing something with it.
For example, a JSON with the key email which is a list of dictionaries these dictionaries have a boolean key critical. For all email objects where critical is true create a custom object that extracts some but not all the email objects keys. append this to a new list. then append the list to a file along with today's data. There will also probably be some formatting requirements. I end up writing this sort of JSON manipulation all the time.
20
u/too_tired_bicycle Apr 10 '19
This continues to be a problem for me, i.e. real world problems. Too many Python books/lessons/exercises are a bit too theoretical. Too many of them give you the basics and underlying principles and concepts without saying "okay, now here's a real world example of why this is useful." I'd say the same about Linux shell commands and scripting.
For example, I've been reading a book on the Linux shell and it explained how you can write a for loop in bash. And I'm like, okay, that's cool I guess. I know what a for loop is and it's kind of neat that you can do that in bash. But, thankfully, the book went on to give an example of how that could be used in a practical way: by creating 12 directories representing the 12 months of the year all with a single line of code on the command line. I wish I saw more of this.
6
7
u/PCHarambeRace Apr 10 '19
Let's not forget bash one liners.
for ip in $(seq 0 254); do host 152.105.251.$ip | grep "pointer"; done
Elegant and beautiful.
5
u/Darkaliafr Apr 11 '19
for ip in $(seq 0 254); do host 152.105.251.$ip | grep "pointer"; done
for ip in {0..254} works too in bash.
1
u/manusatx Apr 14 '19
just to give you a real word example for ksh or bash or even python, a lot of database maintenance scripting or job scheduling tools among others can be automated. Such as look in each view and then check each view base tables list and check if a certain column exists in those base tables, the use case being that column is being changed in size or data type, and you dont want the dependent objects to become invalid.
For python, a simple use case is to do a sensitive data search in a bunch of columns across many databases or filesystems. (use regex and implement parallelism the whole search process)
hope this helps, i am sure there are better solutions for each and everything.
7
u/MyCousinVinny101 Apr 10 '19
Any tips on learning linux? Wouldn’t even know where to begin if im being honest
7
u/CompSciSelfLearning Apr 10 '19
If you have a usb drive. Create a live bootable USB to use on your existing PC or Laptop or both. You can install to dual boot or just use the live usb.
Then just use it.
1
u/MyCousinVinny101 Apr 11 '19
Thanks! Any way I could really mess up my PC doing this though? I watched a youtube tutorial on this and some of the comments were a bit discouraging in that they ran into some issues
2
u/CompSciSelfLearning Apr 11 '19
A live USB will not mess with your machine at all. You can also use a virtual machine install. It will be slower but again no risk to your machine.
1
u/MyCousinVinny101 Apr 11 '19
Ok thanks again!
3
u/CompSciSelfLearning Apr 11 '19
Using the live USB is no risk. Partitioning and installing can risk your data. Don't partition until you've backed up your data and make a Windows recovery USB.
1
u/MyCousinVinny101 Apr 13 '19
What size USB drive do I need?
2
u/CompSciSelfLearning Apr 13 '19
2
1
1
u/sje46 Apr 11 '19
I highly recommend dual booting. Don't do a VM or run off a live image.
You can fuck up your hard drive during the installation process. But that's easy to avoid. Use the GUI install, follow along a guide. If you're really that nervous, back up all your data. But it's easy. Only an idiot will fuck it up.
Once you have it installed, learn enough to do the bare minimum you need. Don't rush with Linux. Use it as your primary os. Use Windows only when you need to. Go at your own pace.
I did this ten years ago and haven't touched Windows in years. I don't even work in IT. Linux has everything I need.
Vms and live disks are a mistake!
1
u/jorvaor Apr 20 '19
I have tried both ways. I have a laptop with three different OS (Ubuntu, Vista and Windows 7). I have another one with Windows in which I have a couple of virtual machines with linuxes.
Both ways worked well for me. The virtual machine way is quicker and easier. Having Linux in its own partition is more satisfactory but fiddlier and slightly riskier.
6
u/joelgsus Apr 10 '19
Download VirtualBox,
install it.
Download Ubuntu image.
run it with virtualbox.
1
u/MyCousinVinny101 Apr 11 '19
Thank you, so this does not require a usb install?
1
u/joelgsus Apr 11 '19
No. Just google how to install Ubuntu on virtual box and watch some YouTube videos
1
u/Ran4 Apr 19 '19
No, virtualbox is a regular program you can run inside of windows. In it, you create and run a "virtual computer".
Do note that you may need to activate VT-X in your bios settings. Google how to do so, it's not that hard.
2
u/heisenberg149 Apr 11 '19
In addition to what everyone else has mentioned, I went over the Linux Journey over the last couple weeks. It's great that everyone said to get a distro (I personally like Fedora's KDE spin) and try it out, but no one told you what to really do with it to start to learn Linux aside from the surface stuff. I found the info on there really helpful, I'd been using Linux on and off since '08 but never needed to dig any deeper than a few commands and general web browsing, homework, etc.
3
u/cantredditforshit Apr 10 '19
Get a Raspberry Pi and a MicroSD for like $50 total. Install NOOBS on the MicroSD, throw it in the Pi, hook up a monitor/USB mouse + keyboard and you're set to start exploring a Linux environment.
Basic navigation of the filesystem commands are probably your best start; cd, ls, etc. Editing/viewing files: cat, nano. Maybe you'll want to set up the SSH server on it so you can just SSH to it from your desktop/laptop without having to plug in a monitor, mouse and keyboard. And then from there you just keep exploring. Come up with a project and make it happen.
17
u/CnidariaScyphozoa Apr 10 '19
I mean you could do that and PIs are fun... But why wouldn't you just spin up a vm for a whopping $0?
1
u/FluffyBunnyOK Apr 10 '19
You can attach hardware to the rpi. Temperature sensors, oled displays etc which is much more fun than just a web server VM.
5
u/ReaverKS Apr 10 '19
for #2, reversing a string assuming it's a list of characters. If you want to do it in place, without using additional memory you can do this:
def reverse_str(s: List[str]) -> None:
end, start= len(s) - 1, 0
while(end > start):
s[end], s[start] = s[start], s[end]
start += 1
end -= 1If instead its just a string you want to return you could do:
def reverse_str(s):
return ''.join(reversed(s))2
u/nonamesareleft1 Apr 11 '19
In this case do the variables end and start not take up additional memory? Or is the fact that they are local to the function important here?
2
u/elbiot Apr 11 '19
Assuming a string is a list would be a mistake. I'd guess that a list of characters would take much more memory than two strings
1
u/visigothatthegates Apr 10 '19
Wow those python questions don’t seem bad at all. I guess you just created a stack for reversing the sentence?
5
u/Dexteroid Apr 10 '19
I actually did well in questions like those.
I coudn't do the file problem very well though. I had forgotten what Split() and Strip do. I ended writing a complex regex to parse the version number and date. then returned pass or fail. The interviewer said, that's one way to do it, but there is a much simpler way, which was basically open file, read lines and split them with spaces then just match the given version number, date and return the result. :/ Perhaps I was nervous.
2
u/jwhibbles Apr 10 '19
This sounds like something I would do. Completely over-analyze the question and come up with some weird solution when the one they are looking for is very simple.
2
u/Dexteroid Apr 10 '19
that exactly what I did, again I was prepared for a lot of tough questions, simple questions caught me off guard lol.
2
2
u/Dexteroid Apr 10 '19
Yes, basically iterated over the sentence, found the words and added them to a stack. Then did pop in a loop and kept addng the output to a string.
0
Apr 10 '19
[deleted]
1
u/Dexteroid Apr 10 '19
s = 'The quick brown fox jumped over the lazy dog.'
' '.join([w_ for _, w_ in sorted([(i, w) for i, w in enumerate(s.split())], key=lambda r: 0 - r[0])]This is too elegant :) mind writing an explanation of this?
6
u/ivosaurus Apr 10 '19
split up sentence, number each word using enumerate, reverse the list by sorting on the negative of that numbered index, filter off the index again, and join back up.
Feels like some weird obfuscation over not using
reversedto me.' '.join(reversed(s.split()))2
u/visigothatthegates Apr 10 '19
While this is definitely going to be fewer lines than creating a stack, I feel like this kind of falls under KISS. Setting it up this way is certainly elegant, but way more complex than a simple push and pop stack.
4
u/ivosaurus Apr 10 '19
IMO this is actually the simplest. Split the sentence up by words, reverse the list, join it back up.
"pushing and popping a stack" to me is just one possible implementation of "reversing a list", so
reversedis simpler.1
u/visigothatthegates Apr 10 '19
Maybe I’m just stuck on the class room exercises that prohibit you from using certain functions that make your life easier
1
u/ivosaurus Apr 11 '19
I always think those types of exercises are kinda silly anyway.
A lot of times in a higher level language with all these convenience functions you're supposed to use, trying to program a "lower level" version of the function in that language just tends to look contrived, cumbersome and ugly.
If you wanna see how it looks with a memory model closer to the actual hardware, use a language that does that, like C or Rust.
4
0
u/ultraDross Apr 10 '19
' '.join(reversed(s))2
u/ivosaurus Apr 10 '19
You should try running that and see if it gives the result you expect ;)
1
u/ultraDross Apr 10 '19
Not at the computer at the moment. I assume I would need to
s.split()first.
1
u/Full-Effect Apr 10 '19
Is there a website or book that show you these real world problems/programs?
3
u/Dexteroid Apr 10 '19
automate the boring stuff, and python automation cookbook. the cookbook if not designed for beginners though.
1
2
Apr 10 '19
Cracking The Coding Interview is specifically targeting a FAANG job, right? If so, it's not too surprising that its interview questions would be misleading for other types of companies.
2
2
u/RIZZIT Apr 11 '19
I once hired a back end python dev for a job and made the mistake to focus on the coding challenge for judgement. we had to fire the guy 6 months after because altough he was an absolute beast in python he sadly had the attitude with it. The next interview I did no coding challenge at all and the guy I recruited then is by no means a python "guru" but is a genuine star level employee.
1
u/shoretel230 Apr 10 '19
What were the tricky linux commands?
1
u/selotec Apr 11 '19
At my interview it was "grep" for searching strings and "sed" for replacing strings in files
0
Apr 11 '19
[deleted]
1
u/Dexteroid Apr 11 '19
You should not be scared, seems liek you got what it takes! go for it.
I had done a bit of this and that in python and shell. But i am not in a dedicated automation team. Right now i am sort of lead of a QA team and sometimes all i am doing is just replying emails which gets pretty mind numbing.
52
u/[deleted] Apr 10 '19
This is good to know. Thank you.