With a comprehension? Well…
>>> seq = '012345'
>>> swapped_pairs = zip(seq[1::2], seq[::2])
>>> ''.join(item for pair in swapped_pairs for item in pair)
'103254'
More Related Contents:
- List comprehensions
- Accessing class variables from a list comprehension in the class definition
- How to find all occurrences of an element in a list
- Create a dictionary with comprehension
- Are for-loops in pandas really bad? When should I care?
- Pythonic way to print list items
- Understanding nested list comprehension
- List comprehension with if statement
- recursive iteration through nested json for specific key in python
- How to unzip a list of tuples into individual lists? [duplicate]
- What is the advantage of a list comprehension over a for loop?
- list() uses slightly more memory than list comprehension
- How to recursively find specific key in nested JSON?
- Appending item to lists within a list comprehension
- List comprehension and lambdas in Python [duplicate]
- What do backticks mean to the Python interpreter? Example: `num`
- Single Line Nested For Loops [duplicate]
- Using while in list comprehension or generator expressions
- Why is one class variable not defined in list comprehension but another is?
- Nested list comprehensions
- Change values in dict of nested dicts using items in a list?
- Python list comprehension – want to avoid repeated evaluation
- List comprehension: Returning two (or more) items for each item [duplicate]
- Name is not defined in a list comprehension with multiple loops
- Why do list comprehensions write to the loop variable, but generators don’t? [duplicate]
- List comprehension scope error from Python debugger
- range(len(list)) or enumerate(list)? [duplicate]
- Square braces not required in list comprehensions when used in a function
- How to parallelize list-comprehension calculations in Python?
- How does all() in python work on empty lists