Files
30-seconds-of-code/snippets/split-lines.md
Angelos Chalaris f6a215e9e3 Kebab file names
2023-04-27 22:00:06 +03:00

557 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Split into lines string succulent-4 2019-08-20T16:15:15+03:00 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.' , '']