Python-Livecode Cheat Sheet Page 2

ADVERTISEMENT

Control Structures
Control structures are used to control what code is executed and how many times.
for x in tVar:
repeat
for each char
tChar
in
tVar
# do things
end repeat
for x in range(5):
repeat
10
# do things
end repeat
while x < 10:
repeat
with
x =
1
to
10
x -= 1
end repeat
if tVar:
repeat
while
x <
10
elif tOther:
subtract
1
from
x
else:
end repeat
if
true
then
...
else
...
if tVar then
else if tOther then
else
end if
switch tVar
case
"a"
break
default
break
end switch
Sorting
These examples show how to sort items and lists.
list = [5, 2, 3, 1, 4]
local
tList
sorted(list) == [1, 2, 3, 4, 5]
put
"5,2,3,1,4"
into
tList
sorted(list, reverse=True) == [5, 4, 3, 2, 1]
sort
items of
tList
ascending numeric
-> tList
is
"1,2,3,4,5"
data = [(6, 1), (8, 3), (2, 2)]
sort
items of
tList
descending numeric
sorted(data, key=itemgetter(2)) == [(6, 1),
-> tList
is
"5,4,3,2,1"
(2, 2), (8, 3)]
local
tData
put
"6,1:8,3:2,2"
into
tData
set
the
lineDelimiter
to
":"
sort
lines of
tData
ascending numeric by
item
2
of each
-> tData
is
"6,1:2,2:8,3"

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 4