without_x_2

Given a string, if one or both of the first 2 chars is ‘x’, return the string without those ‘x’ chars, and otherwise return the string unchanged. This is a little harder than it looks.

This exercise was taken from codingbat.com and has been adapted for the Python language. There are many great programming exercises there, but the majority are created for Java.

Test 1

Input:

'xHi'

Output:

'Hi'

Test 2

Input:

'Hxi'

Output:

'Hi'

Test 3

Input:

'Hi'

Output:

'Hi'

Test 4

Input:

'xxHi'

Output:

'Hi'

Test 5

Input:

'Hix'

Output:

'Hix'

Test 6

Input:

'xaxb'

Output:

'axb'

Test 7

Input:

'xx'

Output:

''

Test 8

Input:

'x'

Output:

''

Test 9

Input:

''

Output:

''

Test 10

Input:

'Hello'

Output:

'Hello'

Test 11

Input:

'Hexllo'

Output:

'Hexllo'

Test 12

Input:

'xHxllo'

Output:

'Hxllo'