Python-Ref > Data structures > Sets > Set looping
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Set looping

Expand/Shrink
21
46
27
3
28
42
2
49
27
44
8
8
30
13
42
3
21
8
39
4
38
22
38
17
32
10
2
39
46
29
3
48
38
1
25
41
42
49
26
20
47
30
41
30
24
30
4
42
39
38
17
30
37
47
20
30
19
8
27
5
1
30
24
1
26
3
15
32
33
10
1
21
15
15
15
18
28
28
24
33
24
2
16
35
14
26
15
0
43
5
24
3
8
6
14
17
33
36
32
44
Zdroj: (sets3-1.py)
  1   f = file( "100numbers.txt", "r")
  2   
  3   numbers = set()
  4   for line in f:
  5     numbers.add( int( line.strip()))
  6   
  7   # looping is the same as over a list
  8   for number in numbers:
  9     print number
stdout:
0
1
2
3
4
5
6
8
10
13
14
15
16
17
18
19
20
21
22
24
25
26
27
28
29
30
32
33
35
36
37
38
39
41
42
43
44
46
47
48
49
Doba běhu: 27.1 ms
Expand/Shrink
21
46
27
3
28
42
2
49
27
44
8
8
30
13
42
3
21
8
39
4
38
22
38
17
32
10
2
39
46
29
3
48
38
1
25
41
42
49
26
20
47
30
41
30
24
30
4
42
39
38
17
30
37
47
20
30
19
8
27
5
1
30
24
1
26
3
15
32
33
10
1
21
15
15
15
18
28
28
24
33
24
2
16
35
14
26
15
0
43
5
24
3
8
6
14
17
33
36
32
44
Zdroj: (sets3-2.py)
  1   f = file( "100numbers.txt", "r")
  2   
  3   numbers = set()
  4   for line in f:
  5     numbers.add( int( line.strip()))
  6   
  7   # we cannot ask about the next value
  8   for i, number in enumerate( numbers):
  9     print number, numbers[i+1]
stdout:
0
stderr:
Traceback (most recent call last):
  File "sets3-2.py", line 9, in <module>
    print number, numbers[i+1]
TypeError: 'set' object is unindexable
Doba běhu: 22.1 ms