6:Strings and Loops in python
Strings and Loops in Python
Task
Given a string, , of length that is indexed from to , print its even-indexed and odd-indexed characters as space-separated strings on a single line (see the Sample below for more detail).
Note: is considered to be an even index.
Input Format
The first line contains an integer, (the number of test cases).
Each line of the subsequent lines contain a String, .
Constraints
Output Format
For each String (where ), print 's even-indexed characters, followed by a space, followed by 's odd-indexed characters.
solution:
t=int(input( ))
for i in range(1,t+1) :
s=input()
even=[]
odd=[]
for j,char in enumerate(s) :
if j%2==0:
even.append(char)
else:
odd.append(char)
print(''.join(even), ''.join(odd))
Comments
Post a Comment