Files
freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/6939b873185d8e00d453563d.md

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