← Back to challenges

String Pairs

PythonHardstringslanguage_fundamentalsarraysconditions

Instructions

Create a function that takes a string s and returns a list of two-paired characters. If the string has an odd number of characters, add an asterisk * in the final pair.

See the below examples for a better understanding:

Examples

string_pairs("mubashir") ➞ ["mu", "ba", "sh", "ir"]

string_pairs("sample") ➞ ["sa", "mp", "le"]

string_pairs("airforces") ➞ ["ai", "rf", "or", "ce", "s*"]

Notes

Return [] if the given string is empty.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Count the Number of Duplicate Characters