Python Forum
get the one element from 1-list or 1-set - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: get the one element from 1-list or 1-set (/thread-22262.html)



get the one element from 1-list or 1-set - Skaperen - Nov-05-2019

i have a list or tuple or set or frozenset with exactly one element within. i'd like to code a simple way to get that one element that can be used with any of those container types. i can't use x[0] since that does not work with set or frozenset .


RE: get the one element from 1-list or 1-set - Gribouillis - Nov-05-2019

next(iter(x)) perhaps?