Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Курс по питону. Рассказать нюанс про моржа ;) #72

Open
Microvenator opened this issue Apr 17, 2024 · 0 comments

Comments

@Microvenator
Copy link
Contributor

Наш пользователь оставил важное предложение по улучшению. Делаю issue, чтобы не забыть реализовать.

А есть в главе со строками (Python) нюанс с моржом? Я быстро чекнул и не нашёл. Контекст:
Глава 14 (не строки, но было интересно попробовать альтернативные решения), предлагаемое решение:

def print_set(obj):
    s = set(obj)
    print(s)
    print(len(s))

Решил закрепить форматирование и попробовал такой вариант:

def print_set(obj): 
    print(f"{s:=set(obj)}\n{len(s)}")

Не отработало т.к. s:=set(obj) нужно завернуть в скобки и тогда всё заколосилось:

def print_set(obj): 
    print(f"{(s:=set(obj))}\n{len(s)}")

P.s. ни в коем случае не предлагаю менять авторское решение - оно простое и понятное, что огромный плюс

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant