From e1e98a2a5aefc21b4179e88cf9ac2340d87afbad Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Sat, 2 Dec 2023 02:22:18 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- glob/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/glob/README.md b/glob/README.md index 5694489..3d496f6 100644 --- a/glob/README.md +++ b/glob/README.md @@ -77,3 +77,21 @@ print(list) ['Testfile_1.mat', 'Testfile_2.mat', 'Testfile_3.mat', 'Testfile_10.mat'] ``` +## rsplit + +And maybe you don't want to have the file extensions. Then we can use [rsplit](https://docs.python.org/3/library/stdtypes.html#str.rsplit) on the string. + +```python +import glob +from natsort import natsorted + +for filename in natsorted(glob.glob("*.mat")): + print(filename.rsplit(".", 1)[0]) +``` + +```python console +Testfile_1 +Testfile_2 +Testfile_3 +Testfile_10 +```