Ahmad
Ahmad

Reputation: 61

how to remove particular element from unicode list in python

I want to remove specific value from a Unicode list i.e field

u'abv,( field),apn,army,elev,fema'

But when i try something like result.remove ('(field)') it stops working and gives an error ?

Upvotes: 3

Views: 163

Answers (1)

akash karothiya
akash karothiya

Reputation: 5950

Convert it into list and use remove

s = u'abv,( field),apn,army,elev,fema'
res = s.split(",")
res.remove("army") # lets assume we need to remove army
['abv', '( field)', 'apn', 'elev', 'fema']

You can make your output list back to string as well, if you wish

output = ",".join(res)
'abv,( field),apn,elev,fema'

Upvotes: 3

Related Questions