Let's say for example that I have an array that represents a name and I want to use just the first letter of any part of a name that is not the first or the last part:
# Have
name = ["John", "Banana", "Doe"]
# Want
["John", "B", "Doe"]
Can I iterate through a subset of an array and change the variables inside it through the variable that references it like so?
for part in name[1:-1]:
part = part[0]
The only solution I fould for this was to use list comprehention, but it was too hard to read:
name = [part if i in [0, len(name)-1] else part[0] for i, part in enumerate(name)]