← Back to challenges

Identical Sublists

PythonHardarraysloopsconditions

Instructions

Create a function that takes in a two-dimensional list and returns the number of sub-lists with only identical elements.

Examples

count_identical([
  [1],
  [2],
  [3],
  [4]
]) ➞ 4

# Single-item lists still count as having identical elements.

count_identical([
  [1, 2],
  [2, 3],
  [3, 4],
  [4, 4]
]) ➞ 1

count_identical([
  [33, 33],
  [5],
  ["a", "a"],
  [2, 2, 2],
  [1, 2, 2],
  [3, 1]
]) ➞ 4

# 4 lists with identical elements: [33, 33], [5], ["a", "a"], and [2, 2, 2]

count_identical([
  ["@", "@", "@", "@"],
  [2, 3], [3, 4], [4, 4]
]) ➞ 2

Notes

Single-element lists count as (trivially) having identical elements.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Check if a Number is a Palindrome