>>> s="aabbccdd"
>>> '-'.join(s[i:i+2] for i in range(0, len(s), 2))
'aa-bb-cc-dd'
More Related Contents:
- What does += mean in this context?
- How to convert a string in the desired manner?
- Why does comparing strings using either ‘==’ or ‘is’ sometimes produce a different result?
- Format timedelta to string
- How to search and replace text in a file?
- Convert hex string to int in Python
- Stripping everything but alphanumeric chars from a string in Python
- How to display a float with two decimal places?
- Convert JSON string to dict using Python
- Print string to text file
- How can I do multiple substitutions using regex?
- How to find char in string and get all the indexes?
- Reading a text file and splitting it into single words in python
- Split a string to even sized chunks
- Split string using a newline delimiter with Python [duplicate]
- How to convert an int to a hex string?
- Python spacing and aligning strings
- How to get the size of a string in Python?
- How to generate random strings in Python?
- How to convert a string of space- and comma- separated numbers into a list of int? [duplicate]
- Insert some string into given string at given index
- Convert list of strings to dictionary
- How do I check if raw input is integer in python 2.7?
- Sort list of strings by a part of the string
- Is there a way to split a string by every nth separator in Python?
- Python Remove Comma In Dollar Amount
- How to replace whitespaces with underscore?
- What is internal representation of string in Python 3.x
- Extract string from between quotations
- How to join two string with a new line between them?