-1

My text is:

'3. COMMENCEMENT; TERM OF LEASE; AND OPTION TO RENEW\nThe initial term of this Lease shall be for a period of Five (5) years commencing on'

I want the following list:

[
    '3. COMMENCEMENT; TERM OF LEASE; AND OPTION TO RENEW',
    'The initial term of this Lease shall be for a period of Five (5) years commencing on'
]
khelwood
  • 55,782
  • 14
  • 81
  • 108
yishairasowsky
  • 741
  • 1
  • 7
  • 21

2 Answers2

0

If you replace all instances of a . with a \n, then you can split at every \n, and get the output you want.


text = '3. COMMENCEMENT; TERM OF LEASE; AND OPTION TO RENEW\nThe initial term of this Lease shall be for a period of Five (5) years commencing on'

# You might wish to replace the "." with a ".\n" instead so the "." is preserved
text = text.replace(".","\n")

text = text.split("\n")

print(text)

Output:

['3', ' COMMENCEMENT; TERM OF LEASE; AND OPTION TO RENEW', 'The initial term of this Lease shall be for a period of Five (5) years commencing on']
Ed Ward
  • 2,333
  • 2
  • 10
  • 16
0
>>> initial_statement = "3. COMMENCEMENT; TERM OF LEASE; AND OPTION TO RENEW\nThe initial term of this Lease shall be for a period of Five (5) years commencing on"
>>> temp_list = initial_statement.split("\n")
>>> print(temp_list)
['3. COMMENCEMENT; TERM OF LEASE; AND OPTION TO RENEW', 'The initial term of this Lease shall be for a period of Five (5) years commencing on.']

Or make it a string again

>>> final_result = ""
>>> for i in temp_list:
...     final_result += i
... 
>>> print(final_result)
3. COMMENCEMENT; TERM OF LEASE; AND OPTION TO RENEWThe initial term of this Lease shall be for a period of Five (5) years commencing on.
DUDANF
  • 2,618
  • 1
  • 12
  • 42