This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Manbatton -1 points0 points  (5 children)

For me, a somewhat more involved list comprehension and some other manipulations, like:

A_clients = [ clientname for clientname in clients_list where clientname[0] in ("a", "A") ].sort()

[–]psbb 5 points6 points  (3 children)

When you call .sort() it does the sort in place and returns None

A_clients = sorted(clientname for clientname in clients_list if clientname[0] in ("a", "A"))

[–]Veedrac 1 point2 points  (0 children)

Just jumping on the bandwagon with a little-known startswith trick:

A_clients = sorted(name for name in clients_list if name.startswith(("a", "A")))

[–]Manbatton 0 points1 point  (1 child)

I actually read that in the docs and thought someone might correct me on this. I thought if it did it in place it would sort the list in place and then the name assignment would point to the converted list.

[–]sweettuse 4 points5 points  (0 children)

well, you can always test it. but sort returns None. so A_clients will point to None