Remove Duplicates While Preserving Order in Python #coding #python #programming

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Here is an explanation step by step:

s = "banana" defines s as a string containing "banana"

dict.fromkeys class method makes a dictionary which all the key coming from the iterable, in this case the string s.
Since dictionaries cannot have the same key, that means dict.fromkeys(s) == {'b': None, 'a': None, 'n': None}

str.join method makes a string which the strings in an iterable get separated by the given string in this case, a dictionary.
Note that the dictionary, only iterates the keys,
That means ''.join({'b': None, 'a': None, 'n': None}) == 'ban'

Print function, well, print the value inside of it, in this case 'ban'

If you have further questions, feel free to ask in the reply section.

eastereggpuri
welcome to shbcf.ru