>>> a = '0 1 2 3 4 5 6 7 8 9'
>>> import re
>>> [len(x) for x in re.split('\d',a)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
c=a.replace(' ', ' ', 2000)
>>> [len(x) for x in re.split('\d',c)]
[0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 0]
>>> (lambda x: x//3 + x%3)(8)
4
>>> (lambda x: x//3 + x%3)(9)
3
>>> [len(x) for x in re.split('\d',a.replace(' ', ' ', 0))]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
>>> [len(x) for x in re.split('\d',a.replace(' ', ' ', 1))]
[0, 1, 2, 1, 4, 5, 6, 7, 8, 9, 0]
>>> [len(x) for x in re.split('\d',a.replace(' ', ' ', 2))]
[0, 1, 2, 1, 2, 5, 6, 7, 8, 9, 0]
>>> [len(x) for x in re.split('\d',a.replace(' ', ' ', 3))]
[0, 1, 2, 1, 2, 3, 6, 7, 8, 9, 0]
>>> [len(x) for x in re.split('\d',a.replace(' ', ' ', 4))]
[0, 1, 2, 1, 2, 3, 4, 7, 8, 9, 0]
>>> [len(x) for x in re.split('\d',a.replace(' ', ' ', 5))]
[0, 1, 2, 1, 2, 3, 2, 7, 8, 9, 0]
...
In [1]: Product.objects.values_list('id', flat=True).order_by('title')
Out[1]: [6, 7, 2, 15, 5, 4, 12, 14, 16, 1, 13, 10, 8, 11, 9, 3]
In [2]: my_pk = 12
In [3]: Product.objects.raw('SELECT * FROM product WHERE title<(SELECT title FROM product WHERE id=%s) ORDER BY title DESC LIMIT 1',[my_pk])[0].pk
Out[3]: 4
In [4]: Product.objects.raw('SELECT * FROM product WHERE title>(SELECT title FROM product WHERE id=%s) ORDER BY title ASC LIMIT 1',[my_pk])[0].pk
Out[4]: 14
str1 = 'pol xxx nog yyy len'
mass = [x for x in str1.split(' ')]
res = []
res.append(mass.pop(0))
out = filter(lambda x: x[0]==res[-1][-1], mass)
while len(out)!=0:
res.append(out[0])
mass.pop(mass.index(out[0]))
out = filter(lambda x: x[0]==res[-1][-1], mass)
res += mass
print res
>>> str1 = 'pol xxx nog yyy len'
>>> mass = [x for x in str1.split(' ')]
>>> res = []
>>> res.append(mass.pop(0))
>>> out = filter(lambda x: x[0]==res[-1][-1], mass)
>>> while len(out)!=0:
... res.append(out[0])
... mass.pop(mass.index(out[0]))
... out = filter(lambda x: x[0]==res[-1][-1], mass)
...
'len'
'nog'
>>> res
['pol', 'len', 'nog']
>>> mass
['xxx', 'yyy']
>>> res += mass
>>> res
['pol', 'len', 'nog', 'xxx', 'yyy']
x = 60 * int(input("How much hours need you for sleep?: "))
h = 60 * int(input("What time did you go to bed?: "))
m = int(input("+ minutes: "))
t = x+h+m
m1 = t
t2 = t // 60 - 24 if t // 60 > 24 else t // 60
if t2 < 12 and (m1 % 60) >= 0:
print(t2, ":", m1 % 60, "AM")
else:
print(t2,":",m1 % 60,"PM")
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing a group
separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.
-C NUM, -NUM, --context=NUM
Print NUM lines of output context. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.
$ mysqldump --opt -usome_user -psome_pass mysql | openssl enc -aes-256-cbc | bzip2 -9 > backup.bz2
enter aes-256-cbc encryption password:mysqldump:
[Warning] Using a password on the command line interface can be insecure.
Verifying - enter aes-256-cbc encryption password:
$ bzip2 -d backup.bz2
$ head backup
Salted__????,?z"?1f???? 9???>?>??n??q?/?{,??}E2'4*W?e?,+N???
????i??"??Lc[?-??Io?`??3???%fnXf????s??5A<?hz?}...
$ bzip2 -d -c backup.bz2 | openssl enc -aes-256-cbc -d > out.sql
enter aes-256-cbc decryption password:
$ head out.sql
-- MySQL dump 10.13 Distrib 5.7.10, for osx10.11 (x86_64)
--
-- Host: localhost Database: mysql
-- ------------------------------------------------------
-- Server version 5.7.10
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;