Python Forum

Full Version: get the one element from 1-list or 1-set
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 .
next(iter(x)) perhaps?