get_sandwich

A sandwich is two pieces of bread with something in between. Return the string that is between the first and last appearance of “bread” in the given string, or return the empty string “” if there are not two pieces of bread.

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:

'breadjambread'

Output:

'jam'

Test 2

Input:

'xxbreadjambreadyy'

Output:

'jam'

Test 3

Input:

'xxbreadyy'

Output:

''

Test 4

Input:

'xxbreadbreadjambreadyy'

Output:

'breadjam'

Test 5

Input:

'breadAbread'

Output:

'A'

Test 6

Input:

'breadbread'

Output:

''

Test 7

Input:

'abcbreaz'

Output:

''

Test 8

Input:

'xyz'

Output:

''

Test 9

Input:

''

Output:

''

Test 10

Input:

'breadbreaxbread'

Output:

'breax'

Test 11

Input:

'breaxbreadybread'

Output:

'y'

Test 12

Input:

'breadbreadbreadbread'

Output:

'breadbread'