```if:javascript
`Array.prototype.length` will give you the number of top-level elements in an array.
```
```if:ruby
`Array#length` will give you the number of top-level elements in an array.
```
```if:csharp
The `Length` property of an array will give you the number of top-level elements in an array.
```
```if:php
`count()` will give you the number of top-level elements in an array if exactly one argument `$a` is passed in which is the array.
```
```if:python
`len(a)` will give you the number of top-level elements in the list/array named `a`.
```

Your task is to create a function ```deepCount``` that returns the number of ALL elements within an array, including any within inner-level arrays.

For example:

```if:javascript
    deepCount([1, 2, 3]);  
    //>>>>> 3
    deepCount(["x", "y", ["z"]]);  
    //>>>>> 4
    deepCount([1, 2, [3, 4, [5]]]);  
    //>>>>> 7
```
```if:ruby
    deepCount([1, 2, 3]);  
    //>>>>> 3
    deepCount(["x", "y", ["z"]]);  
    //>>>>> 4
    deepCount([1, 2, [3, 4, [5]]]);  
    //>>>>> 7
```
```if:csharp
    deepCount([1, 2, 3]);  
    //>>>>> 3
    deepCount(["x", "y", ["z"]]);  
    //>>>>> 4
    deepCount([1, 2, [3, 4, [5]]]);  
    //>>>>> 7
```
```if:php
    deep_c([1, 2, 3]);
    //>>>>> 3
    deep_c(["x", "y", ["z"]]);
    //>>>>> 4
    deep_c([1, 2, [3, 4, [5]]]);
    //>>>>> 7
```
```if:python
    deepCount([1, 2, 3]);  
    //>>>>> 3
    deepCount(["x", "y", ["z"]]);  
    //>>>>> 4
    deepCount([1, 2, [3, 4, [5]]]);  
    //>>>>> 7
```

The input will always be an array.

```if:php
In PHP you may *not* assume that the array passed in will be non-associative.

Please note that `count()`, `eval()` and `COUNT_RECURSIVE` are disallowed - you should be able to implement the logic for `deep_c()` yourself ;)
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Complete search

Starter code: def deep_count(a):
	

Solutions:
def deep_count(a):
	result = 0
	for i in range(len(a)):
		if type(a[i]) is list:
			result += deep_count(a[i])
		result += 1
	return result


def deep_count(a):
	return sum((1 + (deep_count(x) if isinstance(x, list) else 0) for x in a))


def deep_count(a):
	return len(a) + sum((deep_count(e) for e in a if isinstance(e, list)))


def deep_count(a):
	total = 0
	for item in a:
		total += 1
		if isinstance(item, list):
			total += deep_count(item)
	return total


def deep_count(a):
	count = 0
	for i in a:
		count += 1
		if type(i) is list:
			count += deep_count(i)
	return count


deep_count = lambda a: sum((1 + (deep_count(x) if isinstance(x, list) else 0) for x in a))


def deep_count(a):
	return len(a) + sum((deep_count(b) for b in a if isinstance(b, list)))


def deep_count(a):
	b = []
	while a:
		for i in a:
			if type(i) == list:
				a.extend(i)
				a.remove(i)
				a.append('1')
			else:
				b.append(i)
				a.remove(i)
	return len(b)


deep_count = d = lambda a: sum((type(e) is not list or d(e) + 1 for e in a))


def deep_count(a):
	if a == []:
		return 0
	if isinstance(a[0], list):
		return 1 + deep_count(a[0]) + deep_count(a[1:])
	return 1 + deep_count(a[1:])