0

Given the string:

str = 'Led Zeppelin — Blackdog'

how do I split it at , ending up with:

['Led Zeppelin', 'Blackdog']

but is not an hyphen; it is encoded as u'\u2014'

how do I do it?

Burhan Khalid
  • 161,711
  • 18
  • 231
  • 272
8-Bit Borges
  • 8,924
  • 25
  • 82
  • 157

1 Answers1

1

You can just split on explicitly what you've provided if you want it to be clear that it is not a hyphen, surrounded by a whitespace character if that is standard-included with the character. Also, don't shadow built-ins with str as a variable name.

>>> s = 'Led Zeppelin — Blackdog'
>>> s.split(u' \u2014 ')
['Led Zeppelin', 'Blackdog']
>>> s.split(' — ') # perhaps less explicit
['Led Zeppelin', 'Blackdog']
Community
  • 1
  • 1
miradulo
  • 26,763
  • 6
  • 73
  • 90