without_x

Given a string, if the first or last chars are ‘x’, return the string without those ‘x’ chars, and otherwise return the string unchanged.

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:

'xHix'

Output:

'Hi'

Test 2

Input:

'xHi'

Output:

'Hi'

Test 3

Input:

'Hxix'

Output:

'Hxi'

Test 4

Input:

'Hi'

Output:

'Hi'

Test 5

Input:

'xxHi'

Output:

'xHi'

Test 6

Input:

'Hix'

Output:

'Hi'

Test 7

Input:

'xaxbx'

Output:

'axb'

Test 8

Input:

'xx'

Output:

''

Test 9

Input:

'x'

Output:

''

Test 10

Input:

''

Output:

''

Test 11

Input:

'Hello'

Output:

'Hello'

Test 12

Input:

'Hexllo'

Output:

'Hexllo'