Interview Questions from a Start-Up

I have also recently had a phone-screen with a Start-Up located in the Boston metropolitan area. Here are the questions that were asked for a Python/Java related programmer position. Maybe when you are asked these questions, you'll have a better response! :-)

What is the syntax of a lambda function and why would you use it?
A. It starts off with the lambda keyword followed by argument(s), a colon, and a statement(s). A very simple lambda to return the square of an element may look like: lambda x: x*x

Lambdas are commonly use to apply a function across a set of data. Using it will allow you to use a function without actually defining one.

Q. What's the difference between a list and a tuple?
A. A tuple is an immutable data set, where the data will not change. A list is a collection of elements whose size varies with the data it contains. A tuple is typically faster and takes up less memory compared to an identical list.

Q. Explain the difference between calling .items or .iteritems on a dictionary? How about the functions range or xrange?
A. Calling items() will return a list of all key-value elements in the dictionary. The other method, iteritems(), will return an interator object and can be more memory efficient when working with large data sets. The xrange() method is similar to iteritems() as it provides a similar iterator when defining a numerical range: i.e. 1 to 1,000,000.

Q. What is the metaclass?
A. From what I understand, it allows you to modify the definition of a class at run-time. It's typically used as a "factory" or a template for creating classes. In some examples, it seems as a way to extend a class, providing it some of the same functionality of another class. The write-up at helped a bit when trying to understand some of the black magic that I've seen a few times in the past. Sigh, I do not have much experience here.

What are list comprehensions?
A. Example: [ for person in people_list] will return a list of names. Basically, list comprehension is an efficient way of creating a new list (it just is!) without using the typical for-loop construct, or a map() or lambda function.

Q. What is the difference between an int and a Integer?
A. An int is a primitive type and the value is stored in memory. An Integer is the reference type, or Object, form of the int primitive. The value of this Object is points to an address and does not contain the value of the integer. You would use Integer when working with collections or other various methods that require an Object rather than a specified primitive type.

Q. What is the difference between the == and dot-equals operator? (Actually, I didn't understand what the interviewer was asking and I thought he meant a .= operator, not the .equals method... whoops!)
A. The double equals sign represents equality between two objects. This operator checks whether or not two addresses are the same. The .equals() operator is typically an overrideable method where you define which variables will be compared to determine the equality of two objects. By default, it is similar to the == operator.

Q. Explain a String, the StringBuffer, and StringBuilder and how they differ.
A. A String is a reference type that represents a set of characters. Strings combined together will create new instances in memory as a String itself is immutable. The StringBuffer and StringBuilder Objects are common utilities to use to improve the efficiency of concatenating strings. The difference between the two is StringBuffer is synchronized and StringBuilder is not. Thus, StringBuilder is typically faster.

  1. gravatar

    # by Bradley - July 22, 2009 at 5:31 AM

    Thanks, I've seen a few of those before. Ha, dot-equals, I can see how that might get confusing over the phone.