You could just .split it:
>>> Path('logs/date.log.txt').stem.split('.')[0]
'date'
os.path works just as well:
>>> os.path.basename('logs/date.log.txt').split('.')[0]
'date'
It passes all of the tests:
In [11]: all(Path(k).stem.split('.')[0] == v for k, v in {
....: 'a': 'a',
....: 'a.txt': 'a',
....: 'archive.tar.gz': 'archive',
....: 'directory/file': 'file',
....: 'd.x.y.z/f.a.b.c': 'f',
....: 'logs/date.log.txt': 'date'
....: }.items())
Out[11]: True
Answer from Blender on Stack OverflowMatplotlib
matplotlib.org › stable › api › _as_gen › matplotlib.pyplot.stem.html
matplotlib.pyplot.stem — Matplotlib 3.11.2 documentation
A stem plot draws lines perpendicular to a baseline at each location locs from the baseline to heads, and places a marker there. For vertical stem plots (the default), the locs are x positions, and the heads are y values.
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
>>> p = PurePath('/usr/bin/python3') >>> p.parts ('/', 'usr', 'bin', 'python3') >>> p = PureWindowsPath('c:/Program Files/PSF') >>> p.parts ('c:\\', 'Program Files', 'PSF') (note how the drive and local root are regrouped in a single part) The parent, name, stem, and suffix properties describe different parts of a path.
02:03
Why Python? - Intro to Python 🍎📚 STEM For Others - YouTube
11:37
P&S03- Learn Stem and Leaf Plots With Python Made EASY - YouTube
Python - Stem-and-Leaf Display
02:47
Python - Stem-and-Leaf Display with stikpetP - YouTube
10:47
Matplotlib Crash Course: Python Data Visualization Course | Stem ...
My Stem Project Python Lecture 4 : If Conditions and Loops
PyPI
pypi.org › project › stem
stem
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Pythontic
pythontic.com › visualization › charts › stem plot
Stem plot using Python and Matplotlib | Pythontic.com
A stem plot separates the digits in data points to form two columns. Python Matplotlib draws a stem plot as a set of Y values plotted against common X-axis values.
Python Programming
pythonprogramming.net › stemming-nltk-tutorial
Python Programming Tutorials
The reason why we stem is to shorten the lookup, and normalize sentences.
Top answer 1 of 7
40
You could just .split it:
>>> Path('logs/date.log.txt').stem.split('.')[0]
'date'
os.path works just as well:
>>> os.path.basename('logs/date.log.txt').split('.')[0]
'date'
It passes all of the tests:
In [11]: all(Path(k).stem.split('.')[0] == v for k, v in {
....: 'a': 'a',
....: 'a.txt': 'a',
....: 'archive.tar.gz': 'archive',
....: 'directory/file': 'file',
....: 'd.x.y.z/f.a.b.c': 'f',
....: 'logs/date.log.txt': 'date'
....: }.items())
Out[11]: True
2 of 7
9
Why not go recursively?
from pathlib import Path
def true_stem(path):
stem = Path(path).stem
return stem if stem == path else true_stem(stem)
assert(true_stem('d.x.y.z/f.a.b.c') == 'f')
Matplotlib
matplotlib.org › stable › gallery › lines_bars_and_markers › stem_plot.html
Stem plot — Matplotlib 3.11.2 documentation
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) plt.stem(x, y) plt.show()
GeeksforGeeks
geeksforgeeks.org › python › stem-and-leaf-plots-in-python
Stem and Leaf Plots in Python - GeeksforGeeks
January 30, 2026 - Each value is split into a stem (all but the last digit) and a leaf (the last digit).
» pip install stemgraphic
Arch Linux
archlinux.org › packages › extra › any › python-stem
Arch Linux - python-stem 1.8.3-4 (any)
View the file list for python-stem · View the soname list for python-stem · Copyright © 2002-2026 Judd Vinet, Aaron Griffin and Levente Polyák. The Arch Linux name and logo are recognized trademarks. Some rights reserved.
DataCamp
datacamp.com › tutorial › stemming-lemmatization-python
Stemming and Lemmatization in Python | DataCamp
June 1, 2026 - This tutorial covers stemming and lemmatization from a practical standpoint using the Python Natural Language ToolKit (NLTK) package.
IEEE Xplore
ieeexplore.ieee.org › document › 9388001
STEM and STEAM Technologies in Problem Solving with Python | IEEE Conference Publication | IEEE Xplore
The article deals with the structure and methods of construction of the course "Problem Solving with Python" using STEM and STEAM technologies. The course is built on the principle of "visualization and problem solving head first". The techniques are offered to make the course easy to understand, including operations with NumPy arrays and slices, libraries of the Python ecosystem, domain-specific languages.
TutorialsPoint
tutorialspoint.com › how-to-a-plot-stem-plot-in-matplotlib-python
How to a plot stem plot in Matplotlib Python?
June 10, 2021 - import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) markerline, stemlines, baseline = plt.stem(x, y, linefmt='grey', markerfmt='*', bottom=1.1) markerline.set_markerfacecolor('red') plt.show()