def checksum(code, awards={'A': 15, 'B': 20, 'C': 30, '': 40}, joker='D'):
return sum(
awards.get(''.join(set(triplet)-{joker}), 0) for triplet in zip(*[iter(code)]*3)
)
checksum('ABCAABDCA') # 0
checksum('ADAAABDCA') # 15
def checksum2(code, awards={'A': 15, 'B': 20, 'C': 30, '': 40}, joker='D'):
return reduce(
lambda xsum, triplet: xsum + awards.get(
''.join(set(triplet).difference(joker)), 0
),
(code[0:3], code[3:6], code[6:9]), 0
)
Что не так я делаю?работаешь с xml как с html
from lxml import etree
tree = etree.parse('http://xml.weather.yahoo.com/forecastrss/RSXX0091_c.xml')
print tree.xpath('//description/text()')[0]
// Yahoo! Weather for Saint Petersburg, RS
from cStringIO import StringIO
import win32clipboard
from PIL import Image
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
image = Image.open('image.jpg')
output = StringIO()
image.convert("RGB").save(output, "BMP")
send_to_clipboard(win32clipboard.CF_DIB, output.getvalue())