D
D
di_gangsta2016-03-24 17:29:31
Python
di_gangsta, 2016-03-24 17:29:31

What does this loop look like in Python?

Here is a PHP example:
foreach( $squads as $squadNumber => $squadPupils )
{
$first = $squadPupils[ 0 ];
$last = $squadPupils[ count( $squadPupils ) - 1 ]; }
Squads is an array (two dimensional) and squadNumber is the key of the array.
The "for key in array" loop doesn't work. Thank you in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2016-03-24
@di_gangsta

for squadPupils in squads:
    first = squadPupils[0]
    last =squadPupils[len(squadPupils)-1]

if the last fails, then
b = int(len(squadPupils)-1)
    last =squadPupils[b]

scribu.net/blog/python-equivalents-to-phps-foreach.html
is the closest here:
stackoverflow.com/questions/18294534/is-there-a-fo...

A
asd111, 2016-03-24
@asd111

scribu.net/blog/python-equivalents-to-phps-foreach.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question