面试的Python编码测试题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4536195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 16:13:11  来源:igfitidea点击:

Python coding test problem for interviews

python

提问by David

I'm trying to come up with a good coding problem to ask interview candidates to solve with Python.

我正在尝试提出一个很好的编码问题来要求面试候选人使用 Python 解决。

They'll have an hour to work on the problem, with an IDE and access to documentation (we don't care what people have memorized).

他们将有一个小时的时间来解决问题,使用 IDE 并访问文档(我们不在乎人们记住了什么)。

I'm not looking for a tough algorithmic problem- there are other sections of the interview where we do that kind of thing. The point of this section is to sit and watch them actually write code. So it should be something that makes them use just the data structures which are the everyday tools of the application developer - lists, hashtables (dictionaries in Python), etc, to solve a quasi-realistic task. They shouldn't be blocked completely if they can't think of something really clever.

我不是在寻找一个棘手的算法问题- 在面试的其他部分我们会做那种事情。本节的重点是坐下来观察他们实际编写代码。因此,应该使他们仅使用作为应用程序开发人员日常工具的数据结构 - 列表、哈希表(Python 中的字典)等,来解决准现实任务。如果他们想不出真正聪明的东西,就不应该完全阻止他们。

We have a problem which we use for Java coding tests, which involves reading a file and doing a little processing on the contents. It works well with candidates who are familiar with Java (or even C++). But we're running into a number of candidates who just don't know Java or C++ or C# or anything like that, but do know Python or Ruby. Which shouldn't exclude them, but leaves us with a dilemma: On the one hand, we don't learn much from watching someone struggle with the basics of a totally unfamiliar language. On the other hand, the problem we use for Java turns out to be pretty trivial in Python (or Ruby, etc)- anyone halfway competent can do it in 15 minutes. So, I'm trying to come up with something better.

我们有一个用于 Java 编码测试的问题,它涉及读取文件并对内容进行一些处理。它适用于熟悉 Java(甚至 C++)的候选人。但是我们遇到了一些候选人,他们不知道 Java 或 C++ 或 C# 或类似的东西,但知道 Python 或 Ruby。这不应该排除他们,但让我们陷入两难境地:一方面,我们并没有从观察某人与完全陌生语言的基础知识斗争中学到很多东西。另一方面,我们在 Java 中使用的问题在 Python(或 Ruby 等)中被证明是非常微不足道的——任何能胜任一半的人都可以在 15 分钟内完成。所以,我正在努力想出更好的东西。

Surprisingly, Google doesn't show me anyone doing something like this, unless I'm just too dumb to enter the obvious search term. The best idea I've come up with involves scheduling workers to time slots, but it's maybe a little too open-ended. Have you run into a good example? Or a bad one? Or do you just have an idea?

令人惊讶的是,谷歌没有向我展示任何人在做这样的事情,除非我太笨而无法输入明显的搜索词。我想出的最好的想法是将工作人员安排到时间段,但这可能有点太开放了。你遇到过一个很好的例子吗?还是坏的?或者你只是有一个想法?

采纳答案by Seamus Campbell

I've asked candidates to write code to implement bowling scoring before, which is readily comprehensible but contains enough wrinkles that most people have to iterate their approach a couple times to cover all the edge cases.

我之前曾要求候选人编写代码来实现保龄球计分,这很容易理解,但包含足够多的皱纹,以至于大多数人必须重复他们的方法几次才能涵盖所有边缘情况。

A lot of the problems at http://www.streamtech.nl/site/problem+set, which are taken from ACM competitions, are also suitable for your use. I used them to familiarize myself with python syntax and language features. A lot amount to straightforward application of standard data structures; some are more focused on algorithmic issues. If you sort through them I'm sure you'll find several that fit your needs.

http://www.streamtech.nl/site/problem+set 上的很多问题,摘自ACM比赛,也适合你使用。我用它们来熟悉 python 语法和语言特性。很多都是标准数据结构的直接应用;有些更侧重于算法问题。如果您对它们进行分类,我相信您会找到几个适合您的需求。

回答by Rafe Kettler

You can always just give them a few more questions on top of the Java one, like ask them to do the Java task, then ask them to define a class, then ask them to do FizzBuzz. That should be about as rigorous as your Java task.

你总是可以在 Java 问题之上再给他们一些问题,比如让他们做 Java 任务,然后让他们定义一个类,然后让他们做FizzBu​​zz。这应该与您的 Java 任务一样严格。

Don't be afraid to ask a series of questions. Maybe you can even ask them to write a few one-liners to make sure they get the finer points of Python (write a list comprehension, how do you define a lambda, etc.)

不要害怕提出一系列问题。也许你甚至可以让他们写一些单行代码来确保他们掌握 Python 的精髓(写一个列表推导,你如何定义一个 lambda 等等)

回答by Mathias

I don't know about Python specifically, but I found that interview questions which involve recursion are a very effective filter. I have asked candidates to produce all the permutations of a string (and think about how to test it), and I have been asked to pseudo-code the Longest Common Subsequence.

我不是特别了解 Python,但我发现涉及递归的面试问题是一个非常有效的过滤器。我已经要求候选人生成一个字符串的所有排列(并考虑如何测试它),并且我被要求对最长公共子序列进行伪代码。

回答by moinudin

Here's a question I answered on SO recentlythat might be the start of something suitable:

这是我最近在 SO 上回答的一个问题,这可能是一些合适的开始:

Given a string "O Jo?o foi almo?ar :) .", split it into a list of words. You must strip all punctuation except for emoticons. Result for example: ['O','Jo?o', 'foi', 'almo?ar', ':)']

给定一个 string "O Jo?o foi almo?ar :) .",将其拆分为一个单词列表。您必须删除除表情符号以外的所有标点符号。结果例如: ['O','Jo?o', 'foi', 'almo?ar', ':)']

I've tidied up the question a bit. See the original linked above along with my answer. It tests a number of things, and there are different ways of tackling the problem. They can also get a half-solution out that first disregards the emoticons and punctuation aspect. Just finding the emoticons is another sub-problem that can be solved separately. And so on...

我已经整理了一些问题。请参阅上面的原始链接以及我的答案。它测试了很多东西,并且有不同的方法来解决这个问题。他们还可以得到一个半解决方案,首先忽略表情符号和标点符号方面。仅仅找到表情符号是另一个可以单独解决的子问题。等等...

You could extend it to asking about emoticons adjacent to other punctuation, adjacent emoticons, overlapping emoticons, defining emoticons in :)form but also searching for those of the form :-). You could also turn it into a frequency count problem instead of just splitting to somewhat line up with your Java question.

您可以将其扩展为询问与其他标点符号相邻的表情符号、相邻的表情符号、重叠的表情符号、在:)表单中定义表情符号以及搜索表单中的表情符号:-)。您也可以将其转化为频率计数问题,而不仅仅是拆分以与您的 Java 问题保持一致。

I also suggest searching through the python+interview-questionsquestions posted on SO. There are some good ones, and you may even want to broaden your search to skim all interview-questionsposts if you have time.

我还建议搜索发布在 SO 上的python+interview-questions问题。有一些不错的,如果有时间,您甚至可能想扩大搜索范围以浏览所有面试问题帖子。

回答by Valentin Bryukhanov

I can recommend to you Checkio.org

我可以向您推荐Checkio.org