dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
80 lines
1.4 KiB
Markdown
80 lines
1.4 KiB
Markdown
---
|
|
id: 698a1a73ade5ac0e19180fa6
|
|
title: "Challenge 203: Flattened"
|
|
challengeType: 29
|
|
dashedName: challenge-203
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given an array, determine if it is flat.
|
|
|
|
- An array is flat if none of its elements are arrays.
|
|
|
|
# --hints--
|
|
|
|
`is_flat([1, 2, 3, 4])` should return `True`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertIs(is_flat([1, 2, 3, 4]), True)`)
|
|
}})
|
|
```
|
|
|
|
`is_flat([1, [2, 3], 4])` should return `False`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertIs(is_flat([1, [2, 3], 4]), False)`)
|
|
}})
|
|
```
|
|
|
|
`is_flat([1, 0, False, True, "a", "b"])` should return `True`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertIs(is_flat([1, 0, False, True, "a", "b"]), True)`)
|
|
}})
|
|
```
|
|
|
|
`is_flat(["a", [0], "b", True])` should return `False`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertIs(is_flat(["a", [0], "b", True]), False)`)
|
|
}})
|
|
```
|
|
|
|
`is_flat([1, [2, [3, [4, [5]]]], 6])` should return `False`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertIs(is_flat([1, [2, [3, [4, [5]]]], 6]), False)`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def is_flat(arr):
|
|
|
|
return arr
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def is_flat(arr):
|
|
for el in arr:
|
|
if isinstance(el, list):
|
|
return False
|
|
return True
|
|
```
|