Files
30-seconds-of-code/snippets/split_lines.md
Isabelle Viktoria Maciohsek 19f636408c Make expertise a field
2022-03-01 20:27:27 +02:00

558 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Split into lines string beginner 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.' , '']