[PYTHON] 100 amateur language processing knocks: 00

Introduction

I've never used Linux, I don't know Python at all, I don't remember the statistics I should have gnawed at university, I don't know regular expressions, and I'm not good at English. ](Http://www.cl.ecei.tohoku.ac.jp/nlp100/) is a record of the challenge to receive. Please see the list from here.

By the way, as for my specs, I grew up in the Windows Visual C / C ++ field as a former programmer. By the way, before that, it was C ++ with MPW of 68k Mac. Those who understand the meaning are the same generation or seniors ^ ^ How much can you withstand knocking at this age ...

About the environment

I will challenge with. Since my current computer is a Mac, I'm actually virtualizing it with Parallels Desktop.

I was wondering if Python should be 3.x, but if an Ubuntu layman stumbled on something like switching the Python version, knocking would not start, so I decided to use the Ubuntu default as it is.

I searched for an IDE for a while, but it seems that there are many major ones in the Python world. At this point, I'm too amateur to make a decision, so I'll start with an Ubuntu text editor.

Chapter 1: Preparatory movement

00. Reverse order of strings

Get a string in which the characters of the string "stressed" are arranged in reverse (from the end to the beginning).

The finished code:

main.py


# coding: utf-8
target = u'stressed'
result = target[::-1]
print(result)

Execution result:

Terminal


desserts

In the end, it became simple, but I was really into the reverse order.

Slices that can be specified with [start: stop: step] are very convenient, but they are a little confusing when step is negative.

I heard that the index specified by the slice is easy to understand if you think that it points to the "between" of the element of that index and the element immediately before it, but I thought "I see!" Does not work in the reverse order. I will actually try it with an interpreter.

Interpreter


>>> target = 'abcde'
>>> target[0:4:1]
'abcd'

If step is positive, it is okay to understand that index 4 specified by stop points between'd'and'e', so you can get up to'd'. But if step is negative,

Interpreter


>>> target[4:0:-1]
'edcb'

You can get'e'at index 4 specified by start. On the contrary,'a' specified by index 0 cannot be acquired.

It seems good to understand that the index specified in the slice points to the front if it is specified in start, and if it is specified in stop (in the direction specified by step).

In addition, since this problem is targeted from the beginning to the end, it was OK if both start and stop were omitted. If step is negative, the front and back will be switched properly even if omitted. Clearly, if step is negative, it cannot be omitted, and you have to specify the one that you swapped before and after! I was addicted to thinking, "I can't specify the beginning with stop> <".


In Python 3.x, the print statement became a print function and needed parentheses, so I added parentheses. It's refreshing to see changes that make compatibility so far with the version upgrade. Python looks pretty interesting ^^

That's all for the first knock. If you have any mistakes, I would appreciate it if you could point them out.


(I thought I'd put a link to the next issue, but I had to modify the previous post each time I posted, so I decided to add a link to the list at the beginning. Kisyaman, Thank you for your advice.)

Recommended Posts

100 amateur language processing knocks: 41
100 amateur language processing knocks: 71
100 amateur language processing knocks: 56
100 amateur language processing knocks: 24
100 amateur language processing knocks: 50
100 amateur language processing knocks: 59
100 amateur language processing knocks: 70
100 amateur language processing knocks: 62
100 amateur language processing knocks: 60
100 amateur language processing knocks: 92
100 amateur language processing knocks: 30
100 amateur language processing knocks: 06
100 amateur language processing knocks: 84
100 amateur language processing knocks: 81
100 amateur language processing knocks: 33
100 amateur language processing knocks: 46
100 amateur language processing knocks: 88
100 amateur language processing knocks: 89
100 amateur language processing knocks: 40
100 amateur language processing knocks: 45
100 amateur language processing knocks: 43
100 amateur language processing knocks: 55
100 amateur language processing knocks: 22
100 amateur language processing knocks: 61
100 amateur language processing knocks: 94
100 amateur language processing knocks: 54
100 amateur language processing knocks: 04
100 amateur language processing knocks: 63
100 amateur language processing knocks: 78
100 amateur language processing knocks: 12
100 amateur language processing knocks: 14
100 amateur language processing knocks: 08
100 amateur language processing knocks: 42
100 amateur language processing knocks: 19
100 amateur language processing knocks: 73
100 amateur language processing knocks: 75
100 amateur language processing knocks: 98
100 amateur language processing knocks: 83
100 amateur language processing knocks: 95
100 amateur language processing knocks: 32
100 amateur language processing knocks: 96
100 amateur language processing knocks: 87
100 amateur language processing knocks: 72
100 amateur language processing knocks: 79
100 amateur language processing knocks: 23
100 amateur language processing knocks: 05
100 amateur language processing knocks: 00
100 amateur language processing knocks: 02
100 amateur language processing knocks: 37
100 amateur language processing knocks: 21
100 amateur language processing knocks: 68
100 amateur language processing knocks: 11
100 amateur language processing knocks: 90
100 amateur language processing knocks: 74
100 amateur language processing knocks: 66
100 amateur language processing knocks: 28
100 amateur language processing knocks: 64
100 amateur language processing knocks: 34
100 amateur language processing knocks: 36
100 amateur language processing knocks: 77
100 amateur language processing knocks: 01