Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"""': 0.05; 'subject:test': 0.07; 'http,': 0.09; 'none.': 0.09; 'python': 0.10; 'output': 0.13; 'def': 0.13; 'variables': 0.15; '"%s': 0.16; '"hello': 0.16; "'s')": 0.16; ':-p': 0.16; 'dictionaries': 0.16; 'ftp,': 0.16; 'iterators': 0.16; 'pep8': 0.16; 'traceback.': 0.16; 'wrote:': 0.16; 'input': 0.18; '%s"': 0.22; 'decorator': 0.22; 'code.': 0.23; 'leave': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'distribute': 0.27; 'define': 0.27; 'not.': 0.27; 'question': 0.27; 'yield': 0.27; 'function': 0.28; '**kwargs)': 0.29; '**kwargs):': 0.29; 'prints': 0.29; 'program,': 0.29; 'print': 0.30; 'code': 0.30; 'source': 0.33; 'decorators': 0.33; 'received:10.0': 0.34; 'lists': 0.34; 'so,': 0.35; 'best,': 0.35; 'could': 0.35; 'propose': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'method': 0.37; 'end': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'questions': 0.40; 'provide': 0.61; 'is.': 0.63; 'different': 0.63; 'python-list': 0.66; 'here': 0.66; 'subjectcharset:utf-8': 0.71; 'mail,': 0.72; 'decorate': 0.84; 'f(*args,': 0.84; 'subject:you': 0.85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mail201212; t=1442950963; bh=5cRABcd7uzDlFCJr1sZfVTuPkW20t2tKRi8h2umg4p4=; h=Date:From:To:Subject:References:In-Reply-To:From; b=dSSMWvz+XpyTKtvPQWBwQGfjWTpOu+v/DZsRaGk/BhOHqO6kG3K+qhcEW2/uSOc+i tVK++zIqQ+sMFKGG46L7/6T8FnpmPADoHW1hy5wYQMZRcp/9/TlyIzARtOQ4INOcVe vspRe6i2F12tCKng7iEPNyINe6TBtusaaFLEIVmY= Date: Tue, 22 Sep 2015 21:42:41 +0200 From: "Sven R. Kunze" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A little test for you =?UTF-8?B?R3V5c/CfmJw=?= References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> In-Reply-To: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 2243 X-purgate-ID: 154282::1442950963-00000883-542B066B/0/0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 107 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442950966 news.xs4all.nl 23795 [2001:888:2000:d::a6]:60976 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96987 Hmm, why not. :D On 22.09.2015 20:43, Python_Teacher via Python-list wrote: > you have 10 minutes😂 Good luck!! > > > 1. What is PEP8 ? A PEP. > 2. What are the different ways to distribute some python source code ? unison, rsync, scp, ftp, sftp, samba, http, https, mail, git, .... > 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? Don't optimized until you need to. So, we leave it as is. ;) > 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 ? # :-P def function(input): 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 ? The program ends with a traceback. So, my variables are all gone. :( > 5 Decorators > > Let's consider now : > > def str2print(f): > def str2print_wrap(*args, **kwargs): > """wrapper""" > s = f(*args, **kwargs) > print s > return str2print_wrap > > def hello(s): > """ Return "Hello $s" """ > return "%s %s" % ("Hello", s) > > Questions : > > 1. Decorate the method 'hello' with 'str2printf' and write the corresponding code. @str2print def hello(s): """ Return "Hello $s" but actually returns None """ return "%s %s" % ("Hello", s) > 2. What is the effect of the decorator on a call to the new method 'hello' ? It prints "Hello {s}" and returns None. > 3. What is the return value of hello.__doc__ 'wrapper' Best, Sven