There is an even more powerful operation, namely \tl_range:Nnn
.
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\cs_new:Nn \db_tl_pop_left:NN
{
\tl_set:Nx #2 { \tl_range:Nnn #1 { 1 } { 1 } }
\tl_set:Nx #1 { \tl_range:Nnn #1 { 2 } { \tl_count:N #1 } }
}
\cs_new:Nn \db_tl_pop_right:NN
{
\tl_set:Nx #2 { \tl_range:Nnn #1 { -1 } { -1 } }
\tl_set:Nx #1 { \tl_range:Nnn #1 { 1 } { \tl_count:N #1 - 1 } }
}
\tl_set:Nn \l_tmpa_tl {{ab}cdef}
\db_tl_pop_right:NN \l_tmpa_tl \l_tmpb_tl
\tl_show:N \l_tmpa_tl
\tl_show:N \l_tmpb_tl
\db_tl_pop_left:NN \l_tmpa_tl \l_tmpb_tl
\tl_show:N \l_tmpa_tl
\tl_show:N \l_tmpb_tl
\stop
The output on the console is
> \l_tmpa_tl={ab}cde.
<recently read> }
l.21 \tl_show:N \l_tmpa_tl
?
> \l_tmpb_tl=f.
<recently read> }
l.22 \tl_show:N \l_tmpb_tl
?
> \l_tmpa_tl=cde.
<recently read> }
l.26 \tl_show:N \l_tmpa_tl
?
> \l_tmpb_tl={ab}.
<recently read> }
l.27 \tl_show:N \l_tmpb_tl
Your simpler function could be implemented as
\cs_new:Nn \db_tl_lastitem:n
{
\tl_range:nnn { #1 } { -1 } { -1 }
}
Full example
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Nn \db_tl_lastitem:n
{
\tl_range:nnn { #1 } { -1 } { -1 }
}
\NewExpandableDocumentCommand{\lastitem}{m}
{
\db_tl_lastitem:n { #1 }
}
\ExplSyntaxOff
\begin{document}
\lastitem{abcdef}
\lastitem{abcd{ef}}
\end{document}

If you want to throw away the last item:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Nn \db_tl_nolastitem:n
{
\tl_range:nnn { #1 } { 1 } { \tl_count:n { #1 } - 1 }
}
\NewExpandableDocumentCommand{\nolastitem}{m}
{
\db_tl_nolastitem:n { #1 }
}
\ExplSyntaxOff
\begin{document}
\nolastitem{abcdef}
\nolastitem{abcd{ef}}
\end{document}

The fact that \tl_range:nnn
and \tl_range:Nnn
are in the “candidates” should not be of a concern: the functions are useful and they should stay. Perhaps the name could change.
With “non candidates”:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Nn \db_tl_nolastitem:n
{
\tl_reverse:f
{
\tl_tail:f
{
\tl_reverse:n { #1 }
}
}
}
\cs_generate_variant:Nn \tl_tail:n { f }
\cs_generate_variant:Nn \tl_reverse:n { f }
\NewExpandableDocumentCommand{\nolastitem}{m}
{
\db_tl_nolastitem:n { #1 }
}
\ExplSyntaxOff
\begin{document}
\nolastitem{abcdef}
\nolastitem{abcd{ef}}
\end{document}
\tl
-commands are tokens in plural, not one token.s
to\foo
. What do you expect\tl_pop_right
to do?pop
method of lists inPython
(see my edit).