I’m playing with codingbat.com, and I found this really easy problem to solve, so I started trying to play newbie code golf.
Given a non-empty string and an int n, return a new string where the
char at index n has been removed. The value of n will be a valid index
of a char in the original string (i.e. n will be in the range
0..len(str)-1 inclusive).missing_char(‘kitten’, 1) → ‘ktten’
missing_char(‘kitten’, 0) →
‘itten’
missing_char(‘kitten’, 4) → ‘kittn’
Das Code:
def missing_char(str, n):
return ''.join(' '.join(str).split().remove(str[n]))
Oddly, Python won’t interpret this.
Why not?
This is because
removereturnsNone. Most (all?) builtin functions in python that mutate a value returnNone.Therefore your outer
joinis trying to join nothing together.