Given a string, return a version without the first and last char, so "Hello" yields "ell". The string length will be at least 2.
without_end('Hello') → 'ell'
without_end('java') → 'av'
without_end('coding') → 'odin'
This is the code I wrote as a solution to this problem. I feel that this simple of a problem can be written in one line, but I can baffled as to how I can do so; after many attempts. Any and all feedback is appreciated and considered so I can further improve my python practices.
def without_end(str): if len(str) <= 2: return "" no_start = str[1:] no_end = no_start[:len(no_start) - 1] return no_end