cython

Форк
0
/
contains_T455.pyx 
95 строк · 1.9 Кб
1
# ticket: t455
2

3
def in_sequence(x, seq):
4
    """
5
    >>> in_sequence(1, [])
6
    False
7
    >>> in_sequence(1, ())
8
    False
9
    >>> in_sequence(1, {})
10
    False
11
    >>> in_sequence(1, [1])
12
    True
13
    >>> in_sequence(1, (1,))
14
    True
15
    >>> in_sequence(1, {1:None})
16
    True
17

18
    >>> in_sequence(1, None)    # doctest: +ELLIPSIS
19
    Traceback (most recent call last):
20
    TypeError: ...iterable...
21

22
    >>> in_sequence(1, 1)       # doctest: +ELLIPSIS
23
    Traceback (most recent call last):
24
    TypeError: ...iterable...
25
    """
26
    return x in seq
27

28
def not_in_sequence(x, seq):
29
    """
30
    >>> not_in_sequence(1, [])
31
    True
32
    >>> not_in_sequence(1, ())
33
    True
34
    >>> not_in_sequence(1, {})
35
    True
36
    >>> not_in_sequence(1, [1])
37
    False
38
    >>> not_in_sequence(1, (1,))
39
    False
40
    >>> not_in_sequence(1, {1:None})
41
    False
42

43
    >>> not_in_sequence(1, None)    # doctest: +ELLIPSIS
44
    Traceback (most recent call last):
45
    TypeError: ...iterable...
46

47
    >>> not_in_sequence(1, 1)       # doctest: +ELLIPSIS
48
    Traceback (most recent call last):
49
    TypeError: ...iterable...
50
    """
51
    return x not in seq
52

53

54
def in_dict(k, dict dct):
55
    """
56
    >>> in_dict(1, {})
57
    False
58
    >>> in_dict(1, {1:None})
59
    True
60

61
    >>> in_dict(1, None)
62
    Traceback (most recent call last):
63
    ...
64
    TypeError: 'NoneType' object is not iterable
65
    """
66
    return k in dct
67

68
def not_in_dict(k, dict dct):
69
    """
70
    >>> not_in_dict(1, {})
71
    True
72
    >>> not_in_dict(1, {1:None})
73
    False
74

75
    >>> not_in_dict(1, None)
76
    Traceback (most recent call last):
77
    ...
78
    TypeError: 'NoneType' object is not iterable
79
    """
80
    return k not in dct
81

82
def cascaded(a, b, c):
83
    """
84
    >>> cascaded(1, 2, 3)    # doctest: +ELLIPSIS
85
    Traceback (most recent call last):
86
    ...
87
    TypeError: ...iterable...
88
    >>> cascaded(-1, (1,2), (1,3))
89
    True
90
    >>> cascaded(1, (1,2), (1,3))
91
    False
92
    >>> cascaded(-1, (1,2), (1,0))
93
    False
94
    """
95
    return a not in b < c
96

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.