N.T.C
0
Q:

python split string

# Default splits at whitespace
txt = "Welcome to the jungle, baby!"
txt.split()
# Output:
# ["Welcome", "to", "the", "jungle," "baby!"]

# You can specify where to split
txt = "Welcome to the jungle, baby!"
txt.split(", ")
# Output:
# ["Welcome to the jungle", "baby!"]
72
string = 'James Smith Bond'
x = string.split(' ') #Splits every ' ' (space) in the string to a list
# x = ['James','Smith','Bond']
print('The name is',x[-1],',',x[0],x[-1])
2
# Basic syntax:
string.split("text_to_split_by")

# Example usage:
text = "this|is|an|example"
print(text.split("|"))
--> ['this', 'is', 'an', 'example']
2
file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
15
text.split('\n\n')
0
import pandas as pd
row , coloumn = df.shape
year = [2012,2103,2014,2015]

for i in range(0,row) :
  if df.iloc[i]['A'] =="task1" or df.iloc[i]['A'] == "task2"  :
    if df.iloc[i]['B'] in year and df.iloc[i]['B'] >= 7:
      print(df.iloc[i]['C'])
-1

New to Communities?

Join the community