This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author FrankMillman
Recipients BreamoreBoy, FrankMillman, docs@python, r.david.murray
Date 2015-03-18.06:33:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426660423.06.0.112807205291.issue23677@psf.upfronthosting.co.za>
In-reply-to
Content
Lists and tuples are described like this -

class list([iterable]) 
Lists may be constructed in several ways:
[...]

class tuple([iterable]) 
Tuples may be constructed in a number of ways:
[...]

I think a similar approach to Dicts and Sets could make sense -

class dict([**kwarg])
Dicts may be constructed in a number of ways:

- Using a pair of braces to denote the empty dict: {}
- Placing a comma-separated list of key: value pairs within braces: {'jack': 4098, 'sjoerd': 4127} or {4098: 'jack', 4127: 'sjoerd'}
- Using a dict comprehension: {k: v for k, v in iterable}
- Using the dict() built-in: dict() or dict(**kwarg) or dict(mapping, **kwarg) or dict(iterable, **kwarg) 

Add a new example -

f = {k: v for k, v in [('one', 1), ('two', 2), ('three', 3)]}


class set([iterable])
class frozenset([iterable])
Sets may be constructed in a number of ways:

- Non-empty sets (not frozensets) can be created by placing a comma-separated list of elements within braces, for example: {'jack', 'sjoerd'}
- Non-empty sets (not frozensets) can be created by using a set comprehension: {x for x in iterable}
- Using the set() or frozenset() built-in


The 'bullet-point' construction is not really necessary for Sets, but it would make it consistent with the others.


A related point (I can raise a separate Issue if preferred) -

For me, the power of comprehensions lies in their 'filtering' ability. This is not mentioned in any of the above examples, so newcomers may wonder why they should use them.

We don't want to make the examples too complicated. Maybe just add 'if ...' to the example, and provide a cross-reference to Section 6.2.4 in the Language Reference (Displays for lists, sets and dictionaries).
History
Date User Action Args
2015-03-18 06:33:43FrankMillmansetrecipients: + FrankMillman, r.david.murray, docs@python, BreamoreBoy
2015-03-18 06:33:43FrankMillmansetmessageid: <1426660423.06.0.112807205291.issue23677@psf.upfronthosting.co.za>
2015-03-18 06:33:43FrankMillmanlinkissue23677 messages
2015-03-18 06:33:42FrankMillmancreate