List Comparison Operations
The standard comparisons (<
, <=
,
>
, >=
, ==
, !=
,
in
,
not in
) work exactly the same
among list
s, tuple
s and
string
s. The list
s are
compared element by element. If the corresponding elements are the same
type, ordinary comparison rules are used. If the corresponding elements
are different types, the type names are compared, since there is no
other rational basis for comparison.
d1= random.randrange(6)+1
d2= random.randrange(6)+1
if d1+d2 in [2, 12] + [3, 4, 9, 10, 11]:
print "field bet wins on ", d1+d2
else:
print "field bet loses on ", d1+d2
This will create two random numbers, simulating a roll of dice. If
the number is in the list
of field bets, this is
printed. Note that we assemble the final list
of
field bets from two other list
s. In a larger
application program, we might separate the different
list
s of winners based on different payout
odds.