Answers for "line.split in python"

26

split string in python

def split(word): 
    return [char for char in word]  
      
# Driver code 
word = 'geeks'
print(split(word)) 

#Output ['g', 'e', 'e', 'k', 's']
Posted by: Guest on December-07-2019
3

python split lines

>>> text = """Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia,
molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum
numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga praesentium
optio, eaque rerum! Provident similique accusantium nemo autem."""

# the str.splitlines() method is basically just str.split("n").
>>> text.splitlines()
[
	'Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia,',
	'molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum',
	'numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga praesentium',
	'optio, eaque rerum! Provident similique accusantium nemo autem.'
]
Posted by: Guest on March-01-2021
24

split string python

file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
Posted by: Guest on April-01-2020

Python Answers by Framework

Browse Popular Code Answers by Language