Skip to content

Conversation

@jonasreinsch
Copy link

@jonasreinsch jonasreinsch commented Oct 19, 2023

Small code simplification:

the line

chars = sorted(list(set(''.join(words))))

can be simplified to

chars = sorted(set(''.join(words)))

because sorted(...) accepts any iterable and set(...) returns an iterable.

I noticed this in your building makemore video (thank you for that!) at 15:56

@ahasan85
Copy link

@jonasreinsch
Copy link
Author

@jonasreinsch set is unordered https://docs.python.org/3.11/library/stdtypes.html#set-types-set-frozenset

@ahasan85 yes, but sorted then returns an ordered / sorted list.

Just try it out:

>>> sorted(set(list(''.join(['hello', 'my', 'friends']))))
['d', 'e', 'f', 'h', 'i', 'l', 'm', 'n', 'o', 'r', 's', 'y']
>>> sorted(set(''.join(['hello', 'my', 'friends'])))
['d', 'e', 'f', 'h', 'i', 'l', 'm', 'n', 'o', 'r', 's', 'y']

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

Successfully merging this pull request may close these issues.

2 participants