Files
30-seconds-of-code/snippets/split-lines.md
2023-04-28 22:24:23 +03:00

537 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Split into lines snippet
string
succulent-4 2020-11-02T19:28:35+02:00

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.' , '']