[PYTHON] 100 language processing knock 00 ~ 02

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

100 Language Processing Knock (2020): 28
100 language processing knock 00 ~ 02
100 language processing knock 2020 [00 ~ 39 answer]
100 language processing knock 2020 [00-79 answer]
100 language processing knock 2020 [00 ~ 69 answer]
100 Language Processing Knock 2020 Chapter 1
100 Amateur Language Processing Knock: 17
100 Language Processing Knock-52: Stemming
100 Language Processing Knock Chapter 1
100 Amateur Language Processing Knock: 07
100 Language Processing Knock 2020 Chapter 3
100 Language Processing Knock 2020 Chapter 2
100 Amateur Language Processing Knock: 09
100 Language Processing Knock-53: Tokenization
100 Amateur Language Processing Knock: 97
100 language processing knock 2020 [00 ~ 59 answer]
100 Amateur Language Processing Knock: 67
100 Language Processing with Python Knock 2015
100 Language Processing Knock-51: Word Clipping
100 Language Processing Knock-57: Dependency Analysis
100 language processing knock-50: sentence break
100 Language Processing Knock Chapter 1 (Python)
100 Language Processing Knock Chapter 2 (Python)
100 Language Processing Knock-25: Template Extraction
100 Language Processing Knock-87: Word Similarity
I tried 100 language processing knock 2020
100 language processing knock-56: co-reference analysis
Solving 100 Language Processing Knock 2020 (01. "Patatokukashi")
100 Amateur Language Processing Knock: Summary
100 language processing knocks 03 ~ 05
100 language processing knocks (2020): 40
100 language processing knocks (2020): 32
100 Language Processing Knock 2020 Chapter 2: UNIX Commands
100 Language Processing Knock 2015 Chapter 5 Dependency Analysis (40-49)
100 language processing knocks (2020): 35
100 language processing knocks (2020): 47
100 language processing knocks (2020): 39
100 Language Processing Knock with Python (Chapter 1)
100 Language Processing Knock Chapter 1 in Python
100 language processing knocks (2020): 22
100 Language Processing Knock 2020 Chapter 4: Morphological Analysis
100 language processing knocks (2020): 42
100 language processing knock-76 (using scikit-learn): labeling
100 language processing knocks (2020): 29
100 language processing knocks (2020): 49
100 Language Processing Knock with Python (Chapter 3)
100 language processing knocks (2020): 45
100 Language Processing Knock: Chapter 1 Preparatory Movement
100 Language Processing Knock Chapter 4: Morphological Analysis
100 language processing knocks (2020): 10-19
100 Language Processing Knock 2020 Chapter 10: Machine Translation (90-98)
100 language processing knocks (2020): 30
100 Language Processing Knock 2020 Chapter 5: Dependency Analysis
100 language processing knocks (2020): 00-09
100 Language Processing Knock-28: MediaWiki Markup Removal
100 Language Processing Knock 2020 Chapter 7: Word Vector
100 Language Processing Knock 2020 Chapter 8: Neural Net
Python beginner tried 100 language processing knock 2015 (05 ~ 09)
100 Language Processing Knock-31 (using pandas): Verb
100 language processing knock 2020 "for Google Colaboratory"
100 language processing knocks (2020): 48