Skip to content

Tag: tuples

Python Tuples: remove the first three elements cleanly

My issues: How is (9,) different from (9)? (9,)==(9) yields False Why is (9,) showing up in the snippet below? How do I fix the code below so I get (9)? Answer The simple answer is, parentheses are overloaded for grouping and for tuples. To differentiate these forms in python, a trailing comma explicitly indi…

Tuple comparison in function

I am wondering why my comparison returns False and not True although ‘a’ == ‘a’. Output: False Answer It’s because you are using *values rather than values in your function definition When you use the special syntax *args in a function, args will already come back as a tuple, whe…

Find tuple in list of tuples in python

I have a list of tuple (simulationtime,efficiency) and I want to find the tuple in which the maximum efficiency is stated with respect to the minimum simulation time. Any hints on how that could be done? A small part of the otherwise very large list: [(109.00537427472713, 0.8), (109.00588429136333, 0.85), (10…