Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I asked a question because I assumed that I might not know something about it, since C# has Tuple<T1, T2> generic class just for that and if it would be just that, Python would have nothing on C# in that regard. But your comment is exactly what I was thinking about.

So, is there something else in Python that is not present in C#?



I doubt it, other than syntactic sugar, which makes tuples really easy to use, like destructuring and construction. I.e. in Python, if you have a function that returns a tuple:

    a, b = f(xxx)
To create a tuple you just do (a, b). In Haskell, you get some other benefits, like tuples being functors (i.e. "things that can be mapped over"):

    map show ("tuple", 5) == ("tuple", "5")
P.S. Not a Python expert, but I think tuples might be enumerable in Python, which works because Python is dynamically typed.


> Not a Python expert, but I think tuples might be enumerable in Python

Yes, they are. More generally, they are sequences and they support indexing, so they are also iterable. In other words, this Python code works:

    list(map(str, ("tuple", 5, {}))) == ["tuple", "5", "{}"]
There is also a variant of a tuple which assigns names to its positions - it's also iterable. They are also allowed to have any length. Other than that, I'm not aware of any superpowers of Python tuples.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: