Comparing elements of the $n^{\text{th}}$ sublist in a ragged list with the $n^{\text{th}}$ member of a sequence

I have a list of lists that are not of the same length (for example, {{6}, {14}, {6, 26, 30}}), but I have to compare every element in the $n^{\text{th}}$ sublist with the corresponding $n^{\text{th}}$ odd number. So, 6 in the first sublist with 1 (first odd number), 14 in the second sublist with 3 (second odd number), 6 with 5 (third odd number), 26 with 5, 30 with 5, etc.

I tried to make another list with odd numbers, but I really don't know how to program the case when the comparison is with only one element in the sublist (e.g. sublists 1 and 2) and with multi-element sublists (e.g., 3rd sublist).

• Your last few questions have made me curious: what is your actual problem that has you dealing with lists of lists with different lengths? – J. M. will be back soon Sep 5 '12 at 9:14

MapIndexed is your friend :) The part specification for each of the sublists is supplied as a second argument to the function being mapped. With this, you can construct your $n^{\text{th}}$ odd number to compare against. For example:

list = {{6}, {14}, {6, 26, 3}, {5, 10}};
MapIndexed[Thread[# > First@(2 #2 - 1)] &, list]
(* {{True}, {True}, {True, True, False}, {False, True}} *)

Replace > (Greater) with < (Less) or == (Equal) or any other comparison function as per your needs.

Something like :

data = {{6}, {14}, {6, 2, 30}};

odds = 2 # + 1 & /@ Range[0, Length[data] - 1];

(* {{True}, {True}, {True, False, True}} *)

If the condition is :

cond[x_, y_] := If[x > y, Pi y, 0]

then one needs to wrap it with Unevaluated :