I'm currently studying machine learning in a book called Introduction to Machine Learning for Language Processing. As the output, I will implement 100 language processing knock 2015 of Tohoku University Inui-Okazaki laboratory with python. The goal will be completed by the end of August ... This is python partition 2.7.9. http://www.cl.ecei.tohoku.ac.jp/nlp100/
Chapter 1
nlp00.py
#!/usr/bin/env python
s = 'stressed'
def reverse(a):
for i in range(len(a)/2):
temp = a[i]
a[i] = a[len(a)-(i+1)]
a[len(a)-(i+1)] = a[i]
return a
print(reverse(s))
nlp00re.py
#!usr/bin/env python
s = "stressed"
print(s[::-1])
nlp01.py
#coding: UTF-8
str = u'Patatoku Kashii'
print(str[0:len(str):2])
nlp01re.py
#! usr/bin/env python
#coding:UTF-8
str = u"Patatoku Kashii"
print(str[::2])
str [:: 2]
I wonder if this way of writing is like python.
nlp02.py
#!/usr/bin/env python
#coding: UTF-8
str1 = u'Police car'
str2 = u'taxi'
str = ''
for i in range(len(str1)):
str = str + str1[i]+str2[i]
print(str)
nlp02.py
#!usr/bin/env python
# coding:UTF-8
str1 = u'Police car'
str2 = u'taxi'
print(''.join(i+j for i,j in zip(str1,str2)))
Oh, I want to be able to write beautiful code
Recommended Posts