0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

7 kyu Form The Minimum

Posted at

7 kyu Form The Minimum
https://www.codewars.com/kata/5ac6932b2f317b96980000ca/train/python
Task
Given a list of digits, return the smallest number that could be formed from these digits, using the digits only once (ignore duplicates). Only positive integers in the range of 1 to 9 will be passed to the function.

Verbalization

Exclude duplicated digits = select digits only once (use set())
Sort digits from small (use sorted())
join digits (append and join() be careful that join() can be used only for string)

Code

def min_value(digits):
    s = set(digits)
    d = sorted(s)
    n = []
    for i in d:
        n.append(str(i))
    return int("".join(n))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?