Python convert list of one element into string with bracket -


how convert python list containing 1 element string bracket? more 1 element, easy me just use tuple(list['a','b']) returns tuple ('a','b') if element one, returns ('a',) rather want return ('a') sample:

mylist = ["a", " b"] print tuple([s.strip() s in mylist]) >> ('a', 'b')  mylist = ["a"] print tuple([s.strip() s in mylist]) >> ('a', ) #rather want return ('a') 

avoid relying on default __repr__() method, format strings, might change.

be explicit intent instead

 print "('" + "', '".join(mylist) + "')" 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -