
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 0.99 KB | hits: 16 | expires: Never
Python List Replace [closed]
h = "2,3,45,6"
h = h.replace(',','n')
print h
Returns:
2
3
45
6
h = ["hello","goodbye","how are you"]
"hello"
"goodbye"
"how are you"
>>> h
['2', '3', '45', '6']
>>> print 'n'.join(str(i) for i in h)
2
3
45
6
>>> h = ["hello","goodbye","how are you"]
>>> print 'n'.join(str(i) for i in h)
hello
goodbye
how are you
>>> h = ["hello","goodbye","how are you"]
>>> print 'n'.join('"{0}"'.format(i) if isinstance(i,str) else str(i) for i in h)
"hello"
"goodbye"
"how are you"
>>>
>>> search = 'foo'
>>> replace = 'bar'
>>> lst = ['my foo', 'foo', 'bip']
>>> print [x.replace(search, replace) for x in lst]
['my bar', 'bar', 'bip']
"".join([str(x) for x in h])
for each in h: print each
for each in h: print(each)
['n' if x=="," else x for x in yourlist]
for item in list:
print item
s = "n".join([ "First", "Second" ])
l = ["xax", "xaax", "yayay" ]
l = filter(lambda x: x.replace("a", "b"), l)
print l
['xax', 'xaax', 'yayay']