I have a string and I'm trying to iterate it in blocks and save the value of each block into a list, but, without success.
string_A = '920dfffffffff27aff024932090901212003024937090901212003024942090901212003024947090901212003'
newFileTtsInHexString = []
finalListFile = []
for element in string_A[0:len(string_A):18]:
newFileTtsInHexString = element
print("\n=== newFileTtsInHexString ==="+newFileTtsInHexString)
finalListFile = '\n'.join(newFileTtsInHexString)
that's the output :
=== newFileTtsInHexString ===9
=== newFileTtsInHexString ===0
=== newFileTtsInHexString ===0
=== newFileTtsInHexString ===0
=== newFileTtsInHexString ===0
But my goal is to have the finalListFile like this:
920dfffffffff27aff
024932090901212003
024937090901212003
024942090901212003
024947090901212003
in blocks of 18 characters.
for element in string_A[0:len(string_A):18]. Slice [0:len(string_A):18] is "90000", for element in '90000' iterates through '9' '0' '0' '0' '0'. Slice [0:18] is the first chunk you want "920dfffffffff27aff".while string_A: element = string_A[0:18] string_A = string_A[18:]for element in string_A[incorrectSlice]work? Issues are: 1. fixing slice, 2. iterating char by char, 3. program structure for iterating through the string in chunks.