This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
'''tes | |
連結リスト | |
---------- | |
Pythonでは__(アンダースコア2つ)で囲まれたメソッドを、特殊メソッドと呼ぶ。特殊メソッドを決められた仕様に沿って実装することで、様々なポリモーフィズムの恩恵を得ることができる。 例えば、__iter__特殊メソッドを実装したクラスのインスタンスはfor文の中で用いることができるようになる。 | |
以下の手順で **MyLinkedList** クラスを実装せよ。 | |
#. __reversed__()とMyReverseIterator以外を実装し連結リストを完成させよ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>test.php</title> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<form action="" method="GET"> | |
<input type="text" name="name"> | |
<input type="submit"> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>test.php</title> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<form action="" method="GET"> | |
<input type="text" name="name"> | |
<input type="submit"> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quicksort(seq) | |
if seq.size == 0 | |
return seq | |
end | |
pivot = seq[0] | |
right = Array.new | |
left = Array.new | |
for i in 1..seq.size-1 | |
if seq[i] <= pivot | |
left.push(seq[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import urllib | |
import requests | |
import json | |
class Bing(object): | |
# コンストラクタ(初期化) | |
def __init__(self, key): | |
self.api_key = key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def score(self, words, category): | |
# logを取るのは、word_probが0.000....01くらいの小数になったりするため | |
score = math.log(self.prior_prob(category)) | |
for word in words: | |
score += math.log(self.word_prob(word, category)) | |
return score | |
# logを取らないと値が小さすぎてunderflowするかも。 | |
def score_without_log(self, words, category): | |
score = self.prior_prob(category) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
# http://gihyo.jp/dev/serial/01/machine-learning/0003 のベイジアンフィルタ実装をPython3.3向けにリーダブルに改良 | |
import math | |
import sys | |
import MeCab | |
class NaiveBayes(): | |
def __init__(self): | |
self.vocabularies = set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
left_double_quotation = '“' | |
right_double_quotation = '”' | |
single_quotation = '’' | |
result = str() | |
with open('word_to_tex.txt', 'r') as f: | |
for row in f: | |
row = row.replace(left_double_quotation, '``') | |
row = row.replace(right_double_quotation, "''") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.6 | |
# encoding: utf-8 | |
import sys | |
import sqlite3 | |
from collections import namedtuple | |
conn = sqlite3.connect("wnjpn-0.9.db") | |
Word = namedtuple('Word', 'wordid lang lemma pron pos') | |
OlderNewer