Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
22 lines (18 loc) · 537 Bytes

split-lines.md

File metadata and controls

22 lines (18 loc) · 537 Bytes
title type tags cover dateModified
Split into lines
snippet
string
succulent-4
2020-11-02 19:28:35 +0200

Splits a multiline string into a list of lines.

  • Use str.split() and '\n' to match line breaks and create a list.
  • str.splitlines() provides similar functionality to this snippet.
def split_lines(s):
  return s.split('\n')
split_lines('This\nis a\nmultiline\nstring.\n')
# ['This', 'is a', 'multiline', 'string.' , '']