Reorganize snippets

This commit is contained in:
Angelos Chalaris
2023-05-03 21:19:02 +03:00
parent 7511813169
commit 5c913d20bd
1240 changed files with 992 additions and 0 deletions

23
python/s/split-lines.md Normal file
View File

@ -0,0 +1,23 @@
---
title: Split into lines
type: snippet
language: python
tags: [string]
cover: succulent-4
dateModified: 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()`](https://docs.python.org/3/library/stdtypes.html#str.splitlines) provides similar functionality to this snippet.
```py
def split_lines(s):
return s.split('\n')
```
```py
split_lines('This\nis a\nmultiline\nstring.\n')
# ['This', 'is a', 'multiline', 'string.' , '']
```