[Tutor] How to remove the comma only at the end?
Panchanathan Suresh
suresh.gm at gmail.com
Fri Jan 24 08:12:36 EST 2020
Hi everyone,
How to remove the last comma , from the variable members?
I tried members[:-1], members.rstrip(","), but no luck. It is
always returning:
Mike, Karen, Jake, Tasha,
I want it to return Mike, Karen, Jake, Tasha (no comma after Tasha)
Below is my code:
*****
def group_list(group, users):
members = ""
members1 = ""
for x in range(0,len(users)):
#print(users[x])
members = members + users[x] + ", "
return members[:-1]
print(group_list("Marketing", ["Mike", "Karen", "Jake", "Tasha"])) # Should
be "Marketing: Mike, Karen, Jake, Tasha"
*****
Thanks so much,
Suresh
More information about the Tutor
mailing list