makemore
makemore copied to clipboard
Simplify code for collecting + sorting of all possible characters.
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
@jonasreinsch set is unordered https://docs.python.org/3.11/library/stdtypes.html#set-types-set-frozenset
@jonasreinsch
setis 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']