-1

I have this code:

 def lottery(s):
            return ''.join(x for x in s if x.isdigit()) or "One more run!"

Now when you print out the s, it only prints the numbers and when there are only letters, it prints "One more run". Everything up to this point is fine, although I also want it to not print duplicates. Meaning that when I put print(lottery(4443)) it only prints out 1 four and not the 3 of them.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Allen Chen
  • 31
  • 1
  • 5

1 Answers1

1

Try a set() to eliminate duplicates (un-ordered) and back to list with sorted

def lottery(s):
            return ''.join(x for x in sorted(set(s)) if x.isdigit()) or "One more run!"

lottery('435435')

Orders are too crucial?

def lottery(s):
            return ''.join(x for x in dict.fromkeys(s) if x.isdigit()) or "One more run!"

lottery('435435')
Wasif
  • 14,755
  • 3
  • 14
  • 34