Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107607
| From | Jussi Piitulainen <jussi.piitulainen@helsinki.fi> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: what is the difference between one-line-operation and 2-line-operation |
| Date | 2016-04-25 17:42 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <lf5d1pdvjfo.fsf@ling.helsinki.fi> (permalink) |
| References | <CACW-qXU_b9G3016m12FgqgUEhGE-QkioiXacQOCAHrRrVzbQPg@mail.gmail.com> <mailman.78.1461593638.32212.python-list@python.org> |
oyster writes:
- -
> I found
> type(map(lambda e: e, vexList)) is <type 'list'> in py2
> type(map(lambda e: e, vexList)) is <class 'map'> in py3
>
> so, what produces this difference between py2 and py3 in nature? is
> there more examples? where can I find the text abiut his difference?
Yes, there are more ways obtain objects that behave like the map and
filter objects on Python 3. One similar to map and filter is enumerate.
Try iter('foo'), iter((1,2,4)), ..., iter(range(3)). This is used
implicitly by certain Python constructions. Note that range objects
themselves are different.
Open a file for reading: open('example.txt'). You get lines out.
A generator expression: ( "{}".format(x) for x in (1,2,3) ), where the
outer parentheses are for grouping and not always needed.
Define and call a generator function:
def foo(o):
yield '('
yield o
yield ')'
x = foo(31)
'(-31-)' == '-'.join(foo('31'))
You can ask for the next element from any of these, or collect their
remaining elements in a list or tuple, or otherwise iterate or map over
them. They will be consumed when you do so, otherwise they just wait.
They can be huge, even infinite. Best not to collect their contents in a
data structure if they are huge. They trade space for time.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
what is the difference between one-line-operation and 2-line-operation oyster <lepto.python@gmail.com> - 2016-04-25 22:13 +0800 Re: what is the difference between one-line-operation and 2-line-operation Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 17:42 +0300
csiph-web