If I understand what you’re trying to do correctly, you can just do this:
def littery(lst):
return ''.join(lst)[:-1]
>>> littery(['Andy', 'Warhol'])
'AndyWarho'
Or if you want to take the last element off of each element of lst
, you could do this:
def littery(lst):
return ''.join(word[:-1] for word in lst)
>>> littery(['Andy', 'Warhol'])
'AndWarho'
Or if you don’t want to build a list in the call, you can do this:
def littery(*lst):
return ''.join(lst)[:-1]
>>> littery('Andy', 'Warhol')
'AndyWarho'
Or if you want to do it another way, you can do this:
def littery(*lst):
return ''.join(lst[:-1] + [lst[-1][:-1]])
Or if you might need the slice again at some point:
last = slice(-1)
def littery(*lst):
return ''.join(lst)[last]
3
solved How do I join a list and then delete the last character?