Files
30-seconds-of-code/snippets/split_lines.md
2020-09-15 16:25:15 +03:00

464 B

title, tags
title tags
split_lines string,beginner

Splits a multiline string into a list of lines.

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