Steven D'Aprano wrote: > On Sun, 26 Nov 2006 00:25:13 -0800, hollowspook wrote: > > > Hi, there > > > > a = range(100) > > > > if I want to use No 7, 11, 56,90 in a, then the only way I do is [a[7], > > a[11], a[56], a[90]]. > > Is there any other way? > > a = [7, 11, 56, 90] > > Are those numbers supposed to be in some sort of series? They aren't an > arithmetic series: > > (11 - 7) = 4 > (56 - 11) = 45 # not a constant difference > > nor are they a geometric series: > > (11/7) = 1.57 > (56/11) = 5.09 # not a constant ratio > > They don't look like some form of a Fibonacci series: > > 7+11 != 56 > 11+56 != 90 > > If they're just "random" numbers, plucked out of thin air, then you > probably can't calculate them and you'll need to just create them in a > list a = [7, 11, 56, 90]. >
Actually, it's a cubic polynomial ;-) | >>> def f(x): | ... return ( | ... 7 | ... + 4 * x | ... + 41 * x * (x - 1) // 2 | ... - 52 * x * (x - 1) * (x - 2) // 6 | ... ) | ... | >>> [f(x) for x in range(4)] | [7, 11, 56, 90] HTH, John -- http://mail.python.org/mailman/listinfo/python-list