Python and Ruby split

Python split behavior

Python


>>> ',,,1,2,3,,,4,5,,,'.split(',')
['', '', '', '1', '2', '3', '', '', '4', '5', '', '', '']

Is intuitive, but if you use Ruby's split in the same way, the empty elements that are continuous at the end are removed and you are addicted to it.

Ruby


> ',,,1,2,3,,,4,5,,,'.split(',')
=> ["", "", "", "1", "2", "3", "", "", "4", "5"]

If you want to behave like Python, pass -1.

Ruby


> ',,,1,2,3,,,4,5,,,'.split(',',-1)
=> ["", "", "", "1", "2", "3", "", "", "4", "5", "", "", ""]

reference

Recommended Posts

Python and Ruby split
Ruby, Python and map
Python on Ruby and angry Ruby on Python
Python and ruby slice memo
Ruby and Python syntax ~ branch ~
Scraping with Node, Ruby and Python
Differences between Ruby and Python in scope
Eating and comparing programming languages: Python and Ruby
Encrypt with Ruby (Rails) and decrypt with Python
Easy web scraping with Python and Ruby
Differences between Ruby and Python (basic syntax)
[python] Compress and decompress
Correspondence summary of array operation of ruby and python
Instant method grammar for Python and Ruby (studying)
Batch design and python
Python iterators and generators
ffmpeg-Build a python environment and split the video
Python packages and modules
Vue-Cli and Python integration
Specifying the range of ruby and python arrays
python input and output
[Python] Split the date
Python3, venv and Ansible
Python asyncio and ContextVar
About shallow and deep copies of Python / Ruby
Split Python images and arrange them side by side
Comparison of Python and Ruby (Environment / Grammar / Literal)
AtCoder ARC080 D simulation solved in Ruby and Python
[Ruby vs Python] Benchmark comparison between Rails and Flask
Difference between Ruby and Python in terms of variables
[Python] How to split and modularize files (simple, example)
Interprocess communication between Ruby and Python (POSIX message queue)
Comparison of CoffeeScript with JavaScript, Python and Ruby grammar
Version control of Node, Ruby and Python with anyenv
Encryption and decryption with Python
3-3, Python strings and character codes
Python 2 series and 3 series (Anaconda edition)
Python and hardware-Using RS232C with Python-
Python indentation and string format
Python real division (/) and integer division (//)
Java VS PHP VS Python VS Ruby
Å (Ongustromu) and NFC @ Python
Understand Python packages and modules
# 2 [python3] Separation and comment out
Python shallow copy and deep copy
Python installation and basic grammar
Standard input / summary / python, ruby
I compared Java and Python!
Python shallow and deep copy
Zundokokiyoshi with python / ruby / Lua
About Python, len () and randint ()
About Python datetime and timezone
Install Python 3.7 and Django 3.0 (CentOS)
Python environment construction and TensorFlow
Python class variables and instance variables
[Python] Python and security-① What is Python?
Stack and Queue in Python
python metaclass and sqlalchemy declareative
Fibonacci and prime implementations (python)
Ruby, Python Module Installation Guide
Python basics: conditions and iterations