На вход приходит как кириллица так и латиница.
Пробовал # -*- coding: utf-8 -*- и # -*- coding: cp1251 -*-
>>> def f(lst, func):
... for i in range(len(lst)):
... if isinstance(lst[i], list):
... f(lst[i], func)
... else:
... lst[i] = func(lst[i])
... return lst
...
>>> lst = [1, [2, 3], [4, [5, 6]]]
>>>
>>> lst = f(lst, lambda x: 2 * x + 1)
>>> lst
[3, [5, 7], [9, [11, 13]]]
>>>
где-то "int a[10]", где-то "vector a(10)". В чем разница, если она есть?
[guest@localhost ~]$ echo 'abcd' | sed 's/bb*//'
acd
[guest@localhost ~]$
abcd (почему?!!)
[guest@localhost ~]$ echo 'abcd' | sed 's/b*/x/'
xabcd
[guest@localhost ~]$
[guest@localhost ~]$ echo 'abcdabcd' | sed 's/b*/x/g'
xaxcxdxaxcxdx
[guest@localhost ~]$
[guest@localhost ~]$ echo 'abcdabcd' | sed 's/bb*/x/'
axcdabcd
[guest@localhost ~]$
>>> class Human:
...
... def __init__(self, age, name):
... self.age = age
... self.name = name
...
>>> lst = [Human(20, 'aaa'),
... Human(25, 'fff'),
... Human(30, 'ggg'),
... Human(35, 'jjj'),
... Human(40, 'zzz')]
>>>
>>> out = [i for i in lst if 'f' <= i.name[0] <= 'l']
>>> out
[<__main__.Human object at 0xb740d50c>, <__main__.Human object at 0xb740d58c>, <__main__.Human object at 0xb740d5ac>]
>>>
>>> [i.name for i in out]
['fff', 'ggg', 'jjj']
>>>
>>> out = filter(lambda i: 'f' <= i.name[0] <= 'l', lst)
>>> out
<filter object at 0xb740d68c>
>>>
>>> [i.name for i in out]
['fff', 'ggg', 'jjj']
>>>
if __name__ == '__main__':
>>> def f(n):
... for i in range(n):
... for j in range(n):
... if i == j or n - 1 - i == j:
... print(' 1', end='')
... else:
... print(' 0', end='')
... if j == n - 1:
... print()
...
>>> f(5)
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
>>> f(11)
1 0 0 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 1 0 0 0 1 0 0 0
0 0 1 0 0 0 0 0 1 0 0
0 1 0 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 0 0 1
>>>
Подскажите пожалуйста курсы (именно курсы), пусть платные и на зарубежных ресурсах, где можно изучить алгоритмы и структуры данных
(key, array, max, min)
((key , array) , max) , min)
#!/bin/bash
test_parameter()
{
echo "$1" | grep -q '\(video\|audio\|pic\)\*'
}
if ! test_parameter "$1"; then
echo error
else
echo success
fi
exit 0
[guest@localhost sh]$ ./t.sh video
error
[guest@localhost sh]$ ./t.sh video*
success
[guest@localhost sh]$ ./t.sh audio
error
[guest@localhost sh]$ ./t.sh audio*
success
[guest@localhost sh]$ ./t.sh x
error
[guest@localhost sh]$
#!/bin/bash
error()
{
echo "error: $1" 1>&2
}
ok()
{
echo "success: $1" 1>&2
}
test_parameter()
{
echo "$1" | grep -q '\(video\|audio\|pic\)\*'
}
main()
{
if ! test_parameter "$1"; then
error "incorrect parameter: \"$1\""
else
ok "parameter is correct"
fi
}
main "$@" || exit 1
exit 0
[guest@localhost sh]$ ./t.sh
error: incorrect parameter: ""
[guest@localhost sh]$ ./t.sh video
error: incorrect parameter: "video"
[guest@localhost sh]$ ./t.sh video*
success: parameter is correct
[guest@localhost sh]$ ./t.sh audio
error: incorrect parameter: "audio"
[guest@localhost sh]$ ./t.sh audio*
success: parameter is correct
[guest@localhost sh]$ ./t.sh pic
error: incorrect parameter: "pic"
[guest@localhost sh]$ ./t.sh pic*
success: parameter is correct
[guest@localhost sh]$ ./t.sh x
error: incorrect parameter: "x"
[guest@localhost sh]$
В C++ есть функция cout.flush(), которая, как написано в документации, "очищает буфер". Что это значит?