Python: Split, strip, and join in one line

Posted by PandemoniumSyndicate on Stack Overflow See other posts from Stack Overflow or by PandemoniumSyndicate
Published on 2012-09-12T04:51:01Z Indexed on 2012/09/12 15:38 UTC
Read the original article Hit count: 228

Filed under:
|
|
|
|

I'm curious if their is some python magic I may not know to accomplish a bit of frivolity

given the line:

csvData.append(','.join([line.split(":").strip() for x in L]))

I'm attempting to split a line on :, trim whitespace around it, and join on ,

problem is, since the array is returned from line.split(":"), the

for x in L #<== L doesn't exist!

causes issues since I have no name for the array returned by line.split(":")

So I'm curious if there is a sexy piece of syntax I could use to accomplish this in one shot?

Cheers!

© Stack Overflow or respective owner

Related posts about python

Related posts about join