From c837e25203555b5568d043d36a9593edd52b3431 Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Sat, 2 Dec 2023 02:28:44 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- glob/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/glob/README.md b/glob/README.md index 3d496f6..df3bdf4 100644 --- a/glob/README.md +++ b/glob/README.md @@ -95,3 +95,19 @@ Testfile_2 Testfile_3 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'] +``` +