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