So, what is this fancy, cool stuff
weights.Select(p => new { Value = p, Index = ++index })
??
We create for each item in weights a anonymous type where we create a property Value and assign the item of weights and before we assign the index to the Index property we increment it. So basically this is just like creating a Tuple but a way cooler.
Some related information
by definition anonymous types are immutable.
the order of properties matters
var p1 = new { X=1, Y=2 };
var p2 = new { X=1, Y=2 };
var p3 = new { Y=2, X=1 };
here p1.Equals(p2) == true but p1.Equals(p3) == false
An extract from a good reading about this subject
In short, an anonymous type is a reference type that derives directly
from object and is defined by its set of properties base on their
names, number, types, and order given at initialization. In addition
to just holding these properties, it is also given appropriate
overridden implementations for Equals() and GetHashCode() that take
into account all of the properties to correctly perform property
comparisons and hashing. Also overridden is an implementation of
ToString() which makes it easy to display the contents of an anonymous
type instance in a fairly concise manner.