Re: A little test for you Guys😜

James Harris james.harris.1 at gmail.com
Tue Sep 22 22:28:30 CEST 2015


On Tuesday, September 22, 2015 at 7:45:00 PM UTC+1, Lj Fc wrote:
> you have 10 minutes😂 Good luck!!

A good set of questions, IMO. Am answering as someone coming back to Python after a few years.

> 1. What is PEP8 ?

Coding guidelines, I think.

> 2. What are the different ways to distribute some python source code ?

I don't know what that's getting at as it specifically mentions source code apart from tar/gzip or zip. Maybe git or other scm?

> 2 Lists
> 
> Let's define the function plural :
> 
> def plural(words):
>     plurals = []
>     for word in words:
>        plurals.append(word + 's')
>     return plurals
> 
> for word in plural(['cabagge','owl','toy']):
>     print word
> 
> Question : How could the code of the function plural be optimised?

I would go for

  [word + 's' for word in words]

> 3 Dictionaries
> 
> Here are two dictionnaries :
> 
> input = {
>     'foo1': 'bar1',
>     'chose': 'truc',
>     'foo2': 'bar2',
> }
> output = {
>     'bar1': 'foo1',
>     'truc': 'chose',
>     'bar2': 'foo2'
> }
> 
> Question : Propose a function that returns output when you provide input ?

  def f(input):
    output = {}
    for k,v in input.items():
      output[v] = k
    return output

> 4 Iterators
> 
> Let's consider this program :
> 
> def program_1():
>     yield 1
>     yield 2
>     yield 3
> 
> g = program_1()
> a = list(g)
> b = list(g)
> c = g()
> 
> Question : At the end of the program,
> 
> 1. What is the type of g ?
> 2. What is the value of a ?
> 3. What is the value of b ?
> 4. What is the value of c ?

Good one. I checked this and only got 1 and 2 right.

> 5 Decorators

No idea!

James


More information about the Python-list mailing list