How to split a string in half but not in the middle of a word with Python

1 Answer

0 votes
str = "rust c# c java c++ python go"

halfstr = str[:len(str) // 2 + 1]
center = halfstr.rfind(' ') + 1

parts = [str[:center], str[center:]]

print(parts[0])
print(parts[1])



'''
run:

rust c# c java 
c++ python go

'''

 



answered Sep 10, 2024 by avibootz
edited Sep 10, 2024 by avibootz
...