Back to Freecodecamp

Challenge 203: Flattened

curriculum/challenges/english/blocks/daily-coding-challenges-python/698a1a73ade5ac0e19180fa6.md

latest1.3 KB
Original Source

--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