Python Forum
get the one element from 1-list or 1-set
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get the one element from 1-list or 1-set
#1
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 .
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
next(iter(x)) perhaps?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sume Every 10 element in the list and Divided of Sum quest_ 7 135 Yesterday, 10:58 AM
Last Post: perfringo
  Counting Element in Multidimensional List quest_ 1 91 Nov-25-2020, 10:00 PM
Last Post: quest_
  Adding List Element if Second part of the List Elements are the Same quest_ 3 121 Nov-25-2020, 04:33 PM
Last Post: bowlofred
  Removing element from list squall 6 171 Nov-22-2020, 09:34 PM
Last Post: jefsummers
  2d Array adds last element to entire list waiteup 2 96 Nov-19-2020, 08:25 PM
Last Post: bowlofred
  How to get index of minimum element between 3 & 8 in list Mekala 2 162 Nov-10-2020, 12:56 PM
Last Post: DeaD_EyE
  Problem printing last element from a list tester_V 3 196 Oct-30-2020, 04:54 AM
Last Post: tester_V
  Finding an element in a 1d list in a 2d array lionrocker221 0 372 Jun-27-2020, 04:50 PM
Last Post: lionrocker221
  removing dictionary element in list using (key, value) MelonMusk 3 436 Jun-13-2020, 02:37 PM
Last Post: buran
  using element on a list as condition statement glennford49 11 824 May-21-2020, 12:53 PM
Last Post: hussainmujtaba

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020