>>> [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
- 式、 for 句、そして0個以上の for か if 句で構成
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
>>> combs = []
>>> for x in [1,2,3]:
... for y in [3,1,4]:
... if x != y:
... combs.append((x, y))
...
>>> combs
>>> [col for row in [[1,3,5],[2,4,6]] for col in row]
[1, 3, 5, 2, 4, 6]
>>> d = {'a':'aaa','b':'bbb'}
>>> "a.is {0[a]}, b is {0[b]}".format(d)
>>> 'a.is aaa, b is bbb'
from urllib.request import urlopen
from urllib.parse import urlencode
post_data = {
'searchway':'date',
'year':'2016',
'month':'12',
'day':'31',
'kaigou':'',
'howmany':'100'
}
# HTTP リクエストは、data パラメーターが指定された場合 POST に、指定されない場合に GET になります。
html = urlopen('http://www.takarakujinet.co.jp/ajax/numbers3/pastResultPage.do',
urlencode(post_data).encode('utf-8'))
for l in html.readlines():
print(l)
YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto
Copyright© 矢木 浩人 All Rights Reserved.