[Tutor] Tutor Digest, Vol 191, Issue 32

Panchanathan Suresh suresh.gm at gmail.com
Sat Jan 25 12:33:57 EST 2020


Brilliant suggestions from everyone. Thanks a ton!

On Sat, Jan 25, 2020 at 9:01 AM <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>         tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>    1. Re: How to remove the comma only at the end? (Panchanathan Suresh)
>
>
>
> ---------- Forwarded message ----------
> From: Panchanathan Suresh <suresh.gm at gmail.com>
> To: tutor at python.org
> Cc:
> Bcc:
> Date: Fri, 24 Jan 2020 10:03:29 -0800
> Subject: Re: [Tutor] How to remove the comma only at the end?
> Thanks a lot Mark and Alex, really appreciate it.
>
> I thought about this more and then this worked  return members[:-2]
> (-2 because there is an extra space after , in members = members + users[x]
> + ", ")
>
> I was all along trying -1 and was unsuccessful.
>
> Thanks again.
>
> On Fri, Jan 24, 2020 at 10:02 AM Panchanathan Suresh <suresh.gm at gmail.com>
> wrote:
>
> > Thanks a lot Mark and Alex, really appreciate it.
> >
> > I thought about this more and then this worked  return members[:-2]
> > (-2 because there is an extra space after , in members = members +
> > users[x] + ", ")
> >
> > On Fri, Jan 24, 2020 at 9:50 AM Alex Kleider <akleider at sonic.net> wrote:
> >
> >> On 2020-01-24 05:12, Panchanathan Suresh wrote:
> >> > 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"
> >> >
> >>
> >> You might find the str join method useful;
> >> more specifically:
> >> >>> ', '.join(["Mike", "Karen", "Jake", "Tasha"])
> >>
> >
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list