Removal of Unicode (u) from a list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sashi2keng
    New Member
    • Feb 2010
    • 4

    Removal of Unicode (u) from a list

    Hi,

    How can I remove unicode character(u) from a list output?
    Example:
    [[u'r118', u'BB']]
    [[u'r119', u'BB']]

    I want the output to be without "u". Example:

    [['r118', 'BB']]
    [['r119', 'BB']]

    Any help appreciated.

    Thanks,
    Sashi.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Code:
    In [1]: a=u'r118'
    
    In [2]: type(a)
    Out[2]: <type 'unicode'>
    
    In [3]: b=a.encode('ascii')
    
    In [4]: b
    Out[4]: 'r118'
    
    In [5]: type(b)
    Out[5]: <type 'str'>
    Hope this helps.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      You can also type cast the str.
      Code:
      >>> s = [u'r118', u'BB']
      >>> [str(item) for item in s]
      ['r118', 'BB']
      >>>

      Comment

      Working...