How can you get the nth line of a string in Python 3? For example
getline(\"line1\\nline2\\nline3\",3)
Is there any way to do this
My solution (effecient and compact):
def getLine(data, line_no): index = -1 for _ in range(line_no):index = data.index('\n',index+1) return data[index+1:data.index('\n',index+1)]