Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/6939b873185d8e00d453563d.md
T
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6939b873185d8e00d453563d Challenge 158: Array Swap 29 challenge-158

--description--

Given an array with two values, return an array with the values swapped.

For example, given ["A", "B"] return ["B", "A"].

--hints--

array_swap(["A", "B"]) should return ["B", "A"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(array_swap(["A", "B"]), ["B", "A"])`)
}})

array_swap([25, 20]) should return [20, 25].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(array_swap([25, 20]), [20, 25])`)
}})

array_swap([True, False]) should return [False, True].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(array_swap([True, False]), [False, True])`)
}})

array_swap(["1", 1]) should return [1, "1"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(array_swap(["1", 1]), [1, "1"])`)
}})

--seed--

--seed-contents--

def array_swap(arr):

    return arr

--solutions--

def array_swap(arr):

    return [arr[1], arr[0]]