string = 'this is a python string'
wordList = string.split(' ')
list = [11, 18, 19, 21]
length = len(list)
middle_index = length // 2
first_half = list[:middle_index]
second_half = list[middle_index:]
print(first_half)
print(second_half)
text = 'This is python!
x = text.split()
print(x)
def split(txt, seps):
default_sep = seps[0]
# we skip seps[0] because that's the default separator
for sep in seps[1:]:
txt = txt.replace(sep, default_sep)
return [i.strip() for i in txt.split(default_sep)]
>>> split('ABC ; DEF123,GHI_JKL ; MN OP', (',', ';'))
['ABC', 'DEF123', 'GHI_JKL', 'MN OP']
string = "this is a string" # Creates the string
splited_string = string.split(" ") # Splits the string by spaces
print(splited_string) # Prints the list to the console
# Output: ['this', 'is', 'a', 'string']
# Python program to take space
# separated input as a string
# split and store it to a list
# and print the string list
# input the list as string
string = input("Enter elements (Space-Separated): ")
# split the strings and store it to a list
lst = string.split()
print('The list is:', lst) # printing the list