-4

I have strings of the form

 sent="Software Development = 1831".

I want to extract only words from the string i.e. "Software Development". How I can extract this in Python.

neha
  • 335
  • 3
  • 5
  • 19

3 Answers3

4

You can try split :

>>> sent="Software Development = 1831"
>>> sent.split("=")[0]
'Software Development '
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
3
>>> str="Software Development = 1831"

>>> str.split()
['Software', 'Development', '=', '1831']

or 

>>> str.split("=")
['Software Development ', ' 1831']
maiky_forrester
  • 598
  • 4
  • 19
0

Initially you have spaces between '=', hence your code should look like this

sent="Software Development = 1831"
answer=sent.split(" = ")[0] # space before and after =
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
Deepak S
  • 45
  • 1
  • 10