What are “named tuples” in Python?

Named tuples are basically easy-to-create, lightweight object types. Named tuple instances can be referenced using object-like variable dereferencing or the standard tuple syntax. They can be used similarly to struct or other common record types, except that they are immutable. They were added in Python 2.6 and Python 3.0, although there is a recipe for … Read more

Using Pairs or 2-tuples in Java [duplicate]

I don’t think there is a general purpose tuple class in Java but a custom one might be as easy as the following: Of course, there are some important implications of how to design this class further regarding equality, immutability, etc., especially if you plan to use instances as keys for hashing.

What is the equivalent of the C++ Pair in Java?

In a thread on comp.lang.java.help, Hunter Gratzner gives some arguments against the presence of a Pair construct in Java. The main argument is that a class Pair doesn’t convey any semantics about the relationship between the two values (how do you know what “first” and “second” mean ?). A better practice is to write a very simple class, like the one … Read more