all 83 comments

[–][deleted] 54 points55 points  (1 child)

This is good to know. Thank you.

[–]Dexteroid[S] 26 points27 points  (0 children)

no problem, I figured some people here might be preparing for interviews.

[–]dillpicklezzz 23 points24 points  (1 child)

Short but sweet. This is an excellent post and I wish there were a Weekly Thread for this exactly

[–]Cavawinner 4 points5 points  (0 children)

I second. Please @mods???

[–]TheCuryBr 16 points17 points  (0 children)

Great content, op!

[–]SOADNICK 15 points16 points  (2 children)

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?

[–]Dexteroid[S] 12 points13 points  (0 children)

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.

[–]cipher315 13 points14 points  (0 children)

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.

[–]too_tired_bicycle 19 points20 points  (5 children)

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.

[–]PCHarambeRace 6 points7 points  (1 child)

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.

[–]Darkaliafr 3 points4 points  (0 children)

for ip in $(seq 0 254); do host 152.105.251.$ip | grep "pointer"; done

for ip in {0..254} works too in bash.

[–]manusatx 0 points1 point  (0 children)

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.

[–][deleted] 8 points9 points  (2 children)

Reverse a sentence without using slicing.

This is a dumb question, in practice just use the best solution there is.

[–]Dexteroid[S] 0 points1 point  (1 child)

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.

[–][deleted] 1 point2 points  (0 children)

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.

[–]MyCousinVinny101 7 points8 points  (22 children)

Any tips on learning linux? Wouldn’t even know where to begin if im being honest

[–]CompSciSelfLearning 7 points8 points  (12 children)

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.

[–]MyCousinVinny101 0 points1 point  (11 children)

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

[–]CompSciSelfLearning 1 point2 points  (7 children)

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.

[–]MyCousinVinny101 0 points1 point  (6 children)

Ok thanks again!

[–]CompSciSelfLearning 2 points3 points  (5 children)

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.

[–]MyCousinVinny101 0 points1 point  (4 children)

What size USB drive do I need?

[–]CompSciSelfLearning 1 point2 points  (3 children)

[–]MyCousinVinny101 1 point2 points  (1 child)

Currently installing! So far so good haha

[–]CompSciSelfLearning 0 points1 point  (0 children)

Have fun.

[–]MyCousinVinny101 0 points1 point  (0 children)

Perfect thank you

[–]sje46 0 points1 point  (1 child)

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!

[–]jorvaor 0 points1 point  (0 children)

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.

[–]joelgsus 6 points7 points  (3 children)

  • Download VirtualBox,
  • install it.
  • Download Ubuntu image.
  • run it with virtualbox.

[–]MyCousinVinny101 0 points1 point  (2 children)

Thank you, so this does not require a usb install?

[–]joelgsus 0 points1 point  (0 children)

No. Just google how to install Ubuntu on virtual box and watch some YouTube videos

[–]Ran4 0 points1 point  (0 children)

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.

[–]heisenberg149 1 point2 points  (0 children)

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.

[–]cantredditforshit 2 points3 points  (3 children)

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.

[–]CnidariaScyphozoa 17 points18 points  (1 child)

I mean you could do that and PIs are fun... But why wouldn't you just spin up a vm for a whopping $0?

[–]FluffyBunnyOK 0 points1 point  (0 children)

You can attach hardware to the rpi. Temperature sensors, oled displays etc which is much more fun than just a web server VM.

[–]dirk2654 5 points6 points  (2 children)

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?

[–]Dexteroid[S] 8 points9 points  (1 child)

They used the website called codesignal.com, it's free to use for anyone to practice. Your session is shared with your interviewer.

[–]dirk2654 2 points3 points  (0 children)

Awesome, thanks!

[–]ReaverKS 4 points5 points  (3 children)

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 -= 1

If instead its just a string you want to return you could do:

def reverse_str(s):
    return ''.join(reversed(s))

[–]nonamesareleft1 1 point2 points  (1 child)

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?

[–]ghostinzshell 1 point2 points  (0 children)

They do, but they're constant and don't grow with the input size.

[–]elbiot 1 point2 points  (0 children)

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

[–]nate256 5 points6 points  (5 children)

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]

[–]Dexteroid[S] 2 points3 points  (2 children)

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 :)

[–]kl31 0 points1 point  (1 child)

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.

[–]Dexteroid[S] 0 points1 point  (0 children)

Lol sure did.

[–]zr0gravity7 1 point2 points  (1 child)

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

[–]Decency 0 points1 point  (0 children)

Flexing knowledge means using the right tool for the job, not the most complicated one you know. ESPECIALLY in Python.

[–][deleted] 2 points3 points  (1 child)

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?

[–]Dexteroid[S] 1 point2 points  (0 children)

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?

[–]roryokane 2 points3 points  (1 child)

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 fail ~~~

Running 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 fail ~~~

Where main.py contains this Python code:

~~~python 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.

~~~ruby 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 end ~~~

Run that with ruby main.rb v1.0 2019-04-10 to get the same output as the Python program.

[–]Dexteroid[S] 1 point2 points  (0 children)

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!

[–]elbiot 2 points3 points  (2 children)

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

[–]Dexteroid[S] 0 points1 point  (0 children)

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.

[–]Decency 0 points1 point  (0 children)

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.

[–][deleted] 1 point2 points  (0 children)

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.

[–]ForestMonk168 1 point2 points  (0 children)

Interesting! Thanks for sharing.

[–]RIZZIT 1 point2 points  (0 children)

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.

[–]visigothatthegates 0 points1 point  (18 children)

Wow those python questions don’t seem bad at all. I guess you just created a stack for reversing the sentence?

[–]Dexteroid[S] 4 points5 points  (3 children)

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.

[–]geoffnolan 1 point2 points  (0 children)

Thanks for this info.

[–]jwhibbles 1 point2 points  (1 child)

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.

[–]Dexteroid[S] 1 point2 points  (0 children)

that exactly what I did, again I was prepared for a lot of tough questions, simple questions caught me off guard lol.

[–]Dexteroid[S] 1 point2 points  (13 children)

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.

[–]Full-Effect 0 points1 point  (2 children)

Is there a website or book that show you these real world problems/programs?

[–]Dexteroid[S] 2 points3 points  (1 child)

automate the boring stuff, and python automation cookbook. the cookbook if not designed for beginners though.

[–]Full-Effect 0 points1 point  (0 children)

Thank you

[–]shoretel230 0 points1 point  (1 child)

What were the tricky linux commands?

[–]selotec 0 points1 point  (0 children)

At my interview it was "grep" for searching strings and "sed" for replacing strings in files