r/learnpython • • 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.

412 Upvotes

83 comments sorted by

View all comments

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?

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

u/[deleted] 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 reversed to 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 reversed is 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.