Follow

challenge was to write a function that takes a string as an input and returns true if all the characters in the string are unique, and false otherwise.

Roast my attempt, but not too hard I just started.

@pope_meat

One line solution:

return len(input) == len(set(input))

@pope_meat
I'm no python expert, but you start by filling X with the sorted set of characters. Then duplicates will be next to eachother. So you could use a loop comparing two neighbors, stopping when two neighbors are equal.
(It's a very common pattern, for finding duplicates: sort, and compare neighbors)
Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.