A number is self-descriptive when the n'th digit describes the amount n appears in the number.

E.g. 21200:

There are two 0's in the number, so the first digit is 2.

There is one 1 in the number, so the second digit is 1.

There are two 2's in the number, so the third digit is 2.

There are no 3's in the number, so the fourth digit is 0.

There are no 4's in the number, so the fifth digit is 0


Numbers can be of any length up to 9 digits and are only full integers. For a given number derive a function ```selfDescriptive(num)``` that returns; ```true``` if the number is self-descriptive or ```false``` if the number is not.

Source: codewars | Difficulty: EASY
Tags: Number theory

Fundamentals

Mathematics

Starter code: def self_descriptive(num):
	

Solutions:
from collections import Counter

def self_descriptive(num):
	s = [int(a) for a in str(num)]
	cnt = Counter(s)
	return all((cnt[i] == b for (i, b) in enumerate(s)))


def self_descriptive(num):
	numList = list(str(num))
	for (i, s) in enumerate(numList):
		if int(s) != numList.count(str(i)):
			return False
	return True


def self_descriptive(num):
	digits = [int(d) for d in str(num)]
	return all((digits.count(i) == digits[i] for i in range(len(digits))))


from collections import Counter

def self_descriptive(num):
	s = str(num)
	return Counter(s) == {str(i): int(n) for (i, n) in enumerate(s) if n != '0'}


def self_descriptive(num):
	num = str(num)
	return all((num.count(str(i)) == int(d) for (i, d) in enumerate(num)))


def self_descriptive(num):
	from collections import Counter
	snum = str(num)
	c = Counter(snum)
	return all((int(d) == c[str(i)] for (i, d) in enumerate(snum)))


def self_descriptive(num):
	for (i, d) in enumerate(str(num)):
		if str(num).count(str(i)) != int(d):
			return False
	return True