Python: Why is comparison between lists and tuples not supported?
You can always “cast” it >>> tuple([1, 2]) == (1, 2) True Keep in mind that Python, unlike for example Javascript, is strongly typed, and some (most?) of us prefer it that way.
You can always “cast” it >>> tuple([1, 2]) == (1, 2) True Keep in mind that Python, unlike for example Javascript, is strongly typed, and some (most?) of us prefer it that way.
Update As Martin R states in the comments, tuples with up to six components can now be compared with ==. Tuples with different component counts or different component types are considered to be different types so these cannot be compared, but the code for the simple case I described below is now obsolete. Try this: … Read more
Tuple order is as you insert values into the tuple. They’re not going to be sorted as I think you’re asking. zip will again, retain the order you inserted the values in. It’s an acceptable method, but I have 2 alternate suggestions: Use the copy module, or use dtg1 = mdtimes[:]. Sounds reasonable.
You can just use var, but you need to make sure the tuple elements are actually named. In C# 7.0, you need to do this explicitly: var tuples = source.Select(x => (A: x.A, B: x.B)); foreach (var tuple in tuples) { Console.WriteLine($”{tuple.A} / {tuple.B}”); } In C# 7.1, when the value in a tuple literal … Read more
And to complete the answer and stay in the example: import itertools a = [1, 2, 3] b = [4, 5, 6] c = list(itertools.product(a, b)) idx = c.index((1,4)) But this will be the zero-based list index, so 0 instead of 1.
Use textwrap.wrap: >>> import textwrap >>> s=”aaaaaaaaaaaaaaaaaaaaaaa” >>> textwrap.wrap(s, 4) [‘aaaa’, ‘aaaa’, ‘aaaa’, ‘aaaa’, ‘aaaa’, ‘aaa’]
b = [i for sub in a for i in sub] That will do the trick.
The relevant std::tuple constructors are explicit. This means that what you want to do is not possible, since the syntax you want to use is defined in terms of copy initialization (which forbids calling an explicit constructor). In contrast, std::tuple<int, float, char> { 1, 2.2, ‘X’ } uses direct initialization. std::pair does have non-explicit constructors … Read more
Anonymous types are immutable, ValueTuples are not. This is reflected in the fact that anonymous types expose properties, ValueTuples expose fields. Data binding almost always requires properties. Plenty of existing code only works with reference types, not with value types. What in particular comes to mind are projections in Entity Framework: projections to value types … Read more
It seems not. There’s an open issue for this on GitHub: https://github.com/dotnet/roslyn/issues/6877 Edit Issue moved to dotnet/csharplang#355