On Mon, 01 Nov 2004 17:22:12 +0100
Martin B�hr <[EMAIL PROTECTED]> wrote:
> this is not a python solution, but an excellent opportunity to show
> some
OK, OK! It's a free-for-all! I had been holding back, BUT Tcl must
have
the neatest function for stepping through lists:-
foreach {a b} {1 2 3 4 5 6} { add your code here, using $a and $b }
e.g.
set ls {1 2 3 4 5 6}
foreach {a b} $ls {puts $a,$b}
1,2
3,4
5,6
OR (just to show off mixed types) (line continuation '\' added for
email wrap)
foreach {a b} {1 2 3 4 5 6} {
puts "Divided by 3, $a = [expr $a / 3.00]; \
Multiplied by 10, $b = [expr $b * 10]"}
Divided by 10, 1 = 0.1; Multiplied by 10, 2 = 20
Divided by 10, 3 = 0.3; Multiplied by 10, 4 = 40
Divided by 10, 5 = 0.5; Multiplied by 10, 6 = 60
OR (slightly obscure, but quick'n'dirty'n'small)
array set ls {1 2 3 4 5 6}
then here is the array:
parray ls
ls(1) = 2
ls(3) = 4
ls(5) = 6
Now somebody out there will do it in 5 obscure characters using Perl!
--
Alasdair Tennant
Dunedin
New Zealand