List comprehension, check if item is unique

You can use set and set comprehension:

{hobby for name, hobbies in input.items() for hobby in hobbies}

As m.wasowski mentioned, we don’t use the name here, so we can use item.values() instead:

{hobby for hobbies in input.values() for hobby in hobbies}

If you really need a list as the result, you can do this (but notice that usually you can work with sets without any problem):

list({hobby for hobbies in input.values() for hobby in hobbies})

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)