mirror of
https://github.com/davrot/pytutorial.git
synced 2025-06-06 13:00:01 +02:00
Update README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
parent
e1e98a2a5a
commit
c837e25203
1 changed files with 16 additions and 0 deletions
|
@ -95,3 +95,19 @@ Testfile_2
|
||||||
Testfile_3
|
Testfile_3
|
||||||
Testfile_10
|
Testfile_10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Alternatively without a for-loop but using [map](https://docs.python.org/3/library/functions.html#map) , [list](https://docs.python.org/3/library/functions.html#func-list) and [lambda functions](https://docs.python.org/3/reference/expressions.html#lambda):
|
||||||
|
|
||||||
|
```python
|
||||||
|
import glob
|
||||||
|
from natsort import natsorted
|
||||||
|
|
||||||
|
filenames = natsorted(glob.glob("*.mat"))
|
||||||
|
filenames = list(map(lambda s: s.rsplit(".", 1)[0], filenames))
|
||||||
|
print(filenames)
|
||||||
|
```
|
||||||
|
|
||||||
|
```python console
|
||||||
|
['Testfile_1', 'Testfile_2', 'Testfile_3', 'Testfile_10']
|
||||||
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue