Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 404 Bytes

front_back.md

File metadata and controls

20 lines (14 loc) · 404 Bytes

front_back

Given a string, return a new string where the first and last chars have been exchanged.

front_back('code') → 'eodc'
front_back('a') → 'a'
front_back('ab') → 'ba'

Solution:

def front_back(str):
  return str[len(str)-1]+str[1:len(str)-1]+str[0] if len(str)>1 else str;

codingbat

< back to readme