Live data from Hacker News

What’s New in Python 3.7

docs.python.org

31–40 of 70 posts

Re: What’s New in Python 3.7

#31

Unrelated to python 3.7, but they recently added this feature that you can add two dictionaries together in 3.5 by doing: new_dict = {**dict1, **dict2} It is so handy and nice

What happens to duplicate keys?

I think it raises an exception.

https://www.python.org/dev/peps/pep-0448/

EDIT: yeah, nvm, it's what everyone else said.

Re: What’s New in Python 3.7

#33

Unrelated to python 3.7, but they recently added this feature that you can add two dictionaries together in 3.5 by doing: new_dict = {**dict1, **dict2} It is so handy and nice

What happens to duplicate keys?

They get overwritten by the value of the dictionary that came last.

  >>> dict1 = {"key1": 1, "key2": "hello", "key3": [1, 2, 3]}
  >>> dict2 = {key1": 1, "key2": "world", "key3": [1, 4], "key4": "4"}

  >>> {**dict1, **dict2}
  {'key1': 1, 'key2': 'world', 'key3': [1, 4], 'key4': '4'}

Re: What’s New in Python 3.7

#34

Earlier quoted context omitted.

What happens to duplicate keys?

I think it raises an exception. https://www.python.org/dev/peps/pep-0448/ EDIT: yeah, nvm, it's what everyone else said.

No it doesn't, you simply get the value from the last dict:

  >>> a = {'x': 1}
  >>> b = {'x': 2}
  >>> {**a, **b}
  {'x': 2}
  >>> {**b, **a}
  {'x': 1}

Re: What’s New in Python 3.7

#36

Unrelated to python 3.7, but they recently added this feature that you can add two dictionaries together in 3.5 by doing: new_dict = {**dict1, **dict2} It is so handy and nice

Looks like this came from https://www.python.org/dev/peps/pep-0448/

Seems similar to the spread operator in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re: What’s New in Python 3.7

#37

Unrelated to python 3.7, but they recently added this feature that you can add two dictionaries together in 3.5 by doing: new_dict = {**dict1, **dict2} It is so handy and nice

What happens to duplicate keys?

Last pair wins, same as setting an existing key or doing an update() with an existing key.

Re: What’s New in Python 3.7

#38
post #2

Switching the default encoding from ASCII to utf-8 sounds like a pretty big change.

The only real question is: When am I going to be able to name my variable as emojis?

You've been able to do that for a while.

edit: I take that back. Apparently thebunicode allowed in identifers is not unrestricted..... in my defense I don't use unicode identifiers as a rule....

Re: What’s New in Python 3.7

#39
post #2

Switching the default encoding from ASCII to utf-8 sounds like a pretty big change.

The only real question is: When am I going to be able to name my variable as emojis?

Well Python 3 broadly follows UAX 31 "UNICODE IDENTIFIER AND PATTERN SYNTAX", and emoji don't have the xid_start or xid_continue properties, so… never unless you decide to be the change to believe in and get the Unicode consortium to change its ways?

Re: What’s New in Python 3.7

#40

Earlier quoted context omitted.

The only real question is: When am I going to be able to name my variable as emojis?

You've been able to do that for a while. edit: I take that back. Apparently thebunicode allowed in identifers is not unrestricted..... in my defense I don't use unicode identifiers as a rule....

You can use non-ascii characters but not emoji as arbitrary symbols are not generally classified as either XID_Start or XID_Continue.
Post reply on HN