A liberal arts engineer tried knocking 100 language processes in Python 02

This time is the 02 problem. I don't think I will post my study content more regularly

Obtain the character string "Patatokukashi" by alternately connecting the characters "Police car" + "Taxi" from the beginning.

100 knocks for language processing: 100 knocks for language processing

02.py


a = u"Police car"
b = u"taxi"
c = ""
for i in range(len(a)):
    c = (c + a[i] +b[i])

print c

I wrote a code like this. At the time of writing this article, there is a convenient thing called zip, so if you use that

02.py


char1 = u"Police car"
char2 = u"taxi"
print('' .join([char1 + char2 for char1, char2 in zip(a, b)]))

Yeah, this one can be refreshing.

Zip is a very useful function when creating a list from multiple sequence objects. Especially, it is often used when processing multiple sequence objects with for.

Let's master zip more!

Recommended Posts

A liberal arts engineer tried knocking 100 language processes in Python 02
A liberal arts engineer tried knocking 100 language processes in Python 01
A liberal arts engineer tried knocking 100 language processes in Python 00
I tried a functional language with Python
I tried playing a typing game in Python
[Memo] I tried a pivot table in Python
I tried adding a Python3 module in C
A story about a liberal arts programming amateur getting a Python 3 engineer certification basic exam
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 7-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 0-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 5-
I tried to implement a pseudo pachislot in Python
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 6-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 4-
[Beginner] [Python / Django] A fledgling web engineer tried a Django tutorial-Part 3-
Take a screenshot in Python
Create a function in Python
Create a dictionary in Python
I tried to implement a one-dimensional cellular automaton in Python
I tried "a program that removes duplicate statements in Python"
I tried "How to get a method decorated in Python"
Make a bookmarklet in Python
I created a class in Python and tried duck typing
I tried to make a stopwatch using tkinter in python
Draw a heart in Python
I tried to implement a misunderstood prisoner's dilemma game in Python
Maybe in a python (original title: Maybe in Python)
Write a binary search in Python
[python] Manage functions in a list
Hit a command in Python (Windows)
Create a DI Container in Python
100 Language Processing Knock Chapter 1 in Python
Draw a scatterplot matrix in python
I tried knocking 100 image processes (Q1 ~ Q10)
ABC166 in Python A ~ C problem
Write A * (A-star) algorithm in Python
Create a binary file in Python
Solve ABC036 A ~ C in Python
Start SQLite in a programming language
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python
I learned about processes in Python
Python beginner tried 100 language processing knock 2015 (05 ~ 09)
Implementing a simple algorithm in Python 2
Create a Kubernetes Operator in Python
Solve ABC037 A ~ C in Python
Run a simple algorithm in Python
Draw a CNN diagram in Python
web coder tried excel in Python
Create a random string in Python
I tried Line notification in Python
Schedule a Zoom meeting in Python
When writing a program in Python
Python beginner tried 100 language processing knock 2015 (00 ~ 04)
You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1
I tried to develop a Formatter that outputs Python logs in JSON
You will be an engineer in 100 days ――Day 30 ―― Python ―― Basics of Python language 6
I tried to implement a card game of playing cards in Python
You will be an engineer in 100 days ――Day 25 ―― Python ―― Basics of Python language 2
Generate a first class collection in Python