Get the last element of the array by splitting the string in Python and PHP

Occasional processing

https://qiita.com/n0bisuke/items I want to extract the last part from the URL such as PHP

split.php


$url = "https://qiita.com/n0bisuke/items";
$tmp = explode("/", $url);
$end_word = end($tmp);

Python

split.py


url = "https://qiita.com/n0bisuke/items"
tmp = url.split('/')
end_word = tmp[-1]

In the case of Python, it may be a feature that PHP does not have that it can be counted from the end by specifying [-1]. If you specify [-2], you can get the second from the end.

Recommended Posts

Get the last element of the array by splitting the string in Python and PHP
Divides the character string by the specified number of characters. In Ruby and Python.
Get the index of each element of the confusion matrix in Python
Note: Get the first and last items of Python OrderedDict non-destructively
Get the title and delivery date of Yahoo! News in Python
Summary of the differences between PHP and Python
[Python] Get the last updated date of the website
Get Unix time of the time specified by JST regardless of the time zone of the server in Python
[python] How to sort by the Nth Mth element of a multidimensional array
How to get the number of digits in Python
[python] Get the list of classes defined in the module
Get the size (number of elements) of UnionFind in Python
[Python] Get element by specifying name attribute in BeautifulSoup
Shift the alphabet string by N characters in Python
Extract the element by deleting the tag contained in the string
Get the URL of the HTTP redirect destination in Python
Get last month in python
Pass an array from PHP to PYTHON and do numpy processing to get the result
Find out the apparent width of a string in python
Get the MIME type in Python and determine the file format
Get the number of specific elements in a python list
Sort the string array in order of length & Japanese syllabary
How to get the last (last) value in a list in Python
Get the current date and time in Python, considering the time difference
[Tips] Problems and solutions in the development of python + kivy
Google search for the last line of the file in Python
The story of Python and the story of NaN
Get the first element of queryset
Get the desktop path in Python
Get the host name in Python
Get the query string (query string) in Django
Specify the encoding of the unicode string in the Python 2.x print statement
Count the number of Thai and Arabic characters well in Python
How to determine the existence of a selenium element in Python
[Understanding in the figure] Management of Python virtual environment by Pipenv
Check if the password hash generated by PHP matches in Python
Read the standard output of a subprocess line by line in Python
[python] Get the rank of the values in List in ascending / descending order
Get and set the value of the dropdown menu using Python and Selenium
Get the number of readers of a treatise on Mendeley in Python
python memo: enumerate () -get index and element of list at the same time and turn for statement
Fill the string with zeros in python and count some characters from the string
[Python Kivy] How to get the file path by dragging and dropping
Get a capture of the entire web page in Selenium Python VBA
Check the behavior of destructor in Python
Comparing the basic grammar of Python and Go in an easy-to-understand manner
python> array> Determine the number and initialize> mylist = [idx for idx in range (10)] / mylist = [0 for idx in range (10)] >> mylist = [0] * 10
Change the saturation and brightness of color specifications like # ff000 in python 2.5
The result of installing python in Anaconda
I want to batch convert the result of "string" .split () in Python
Read the file line by line in Python
Get and convert the current time in the system local timezone with python
Pandas of the beginner, by the beginner, for the beginner [Python]
I tried to verify and analyze the acceleration of Python by Cython
Open an Excel file in Python and color the map of Japan
Get the number of articles accessed and likes with Qiita API + Python
In search of the fastest FizzBuzz in Python
Get the last day of the specified month
[Python] Get the character code of the file
[Introduction to Python] Thorough explanation of the character string type used in Python!
Get the EDINET code list in Python