Click here to Skip to main content
15,887,363 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list named data having the items shown as below.

a229f7d1148c27d5ff46cbf506f92a9e 
3c73dc22ddaafa58346cc5241a78d509 
c5ebe3eff60ef972fdd9a9d5e4762227 
1c720ec8c2615529e1500d77020a1dc2 
63d8e40d1c5aabbee5cf35a13a95b089 
0994bcd4f5722e3ae8620a483b83abbf 
06f628503dddc37956e586b9e537b3ae 
a229f7d1148c27d5ff46cbf506f92a9e 
3c73dc22ddaafa58346cc5241a78d509 
f6ebd290be34c47ffc84f0a4f123112a 
c5ebe3eff60ef972fdd9a9d5e4762227 
1c720ec8c2615529e1500d77020a1dc2 


I want to concatenate 2 items at a time for the entire list and copy that to an output file as below:
data[index+ 1] + data[index]
3c73dc22ddaafa58346cc5241a78d509a229f7d1148c27d5ff46cbf506f92a9e

1c720ec8c2615529e1500d77020a1dc2c5ebe3eff60ef972fdd9a9d5e4762227 

and so on till the end of the list.

What I have tried:

ind = 0
		while ind < len(data):
			for i in range(int(len(data)/2)):
				new_file.write("".join(data[(ind + 1): ind]))
				new_file.write("\n")
			ind += 2


But i am not getting the desired output. What am i doing wrong in the while loop?
Posted
Updated 20-Oct-20 21:48pm

1 solution

Try this:
Python
for i in range(0, len(data), 2):
    next = data[i] + data[i+1]
    new_file.write(next)
    new_file.write("\n")
 
Share this answer
 
Comments
Member 11362771 21-Oct-20 5:47am    
@Richard MacCutchan..can i convert those strings to uppercase? How do i do it if possible? .upper() seems to not work..
Richard MacCutchan 21-Oct-20 5:56am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900