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 ...
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.
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