Questions tagged [pep448]

Questions related to PEP 448: Additional Unpacking Generalizations, used for unpacking iterables and mappings within literal tuples, lists, sets and dicts using * and **

For questions related to PEP 448: Additional Unpacking Generalizations, used for unpacking iterables and mappings within literal tuples, lists, sets and dicts

5 questions
27
votes
3 answers

Python: Splat/unpack operator * in python cannot be used in an expression?

Does anybody know the reasoning as to why the unary (*) operator cannot be used in an expression involving iterators/lists/tuples? Why is it only limited to function unpacking? or am I wrong in thinking that? For example: >>> [1,2,3, *[4,5,6]] File…
Har
  • 3,005
  • 8
  • 27
  • 63
13
votes
1 answer

asterisk in tuple, list and set definitions, double asterisk in dict definition

I'm playing now with Python 3.5 interpreter and found very interesting behavior: >>> (1,2,3,"a",*("oi", "oi")*3) (1, 2, 3, 'a', 'oi', 'oi', 'oi', 'oi', 'oi', 'oi') >>> [1,2,3,"a",*range(10)] [1, 2, 3, 'a', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>…
George Sovetov
  • 3,923
  • 4
  • 26
  • 54
2
votes
2 answers

Weird unpacking in list comprehension

I was watching a lecture from David Beazley. At minute 23:20 he does some "magic" with unpacking that I am having hard time understanding. The "magic line" is fail = [ { **row, 'DBA Name': row['DBA Name'].replace("'",'').upper() } for row in fail…
alec_djinn
  • 7,288
  • 8
  • 29
  • 58
1
vote
0 answers

What does the * sign mean in the following code?

I was solving a programming puzzle and came across this solution by someone. I don't understand why the * is used. a = [*map(len,input().replace(" ","").replace("12","1 2").replace("21","2 1").split(" "))]
govind
  • 11
  • 2
1
vote
2 answers

Additional Unpacking Generalizations (PEP 448) with variable number of elements

The acceptance of PEP 448 has introduced Additional Unpacking Generalizations in Python 3.5. For example: >>> l1 = [1, 2, 3] >>> l2 = [4, 5, 6] # unpack both iterables in a list literal >>> joinedList = [*l1, *l2] >>> print(joinedList) [1, 2, 3, 4,…
Jean-Francois T.
  • 9,065
  • 3
  • 46
  • 79