List l has the following elements
l = ['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
pairs = 
for a, b in (sub.split(None, 1) for sub in l):
pairs.append([("Z", i) if int(i) < 10 else (c, i) for c, i in zip(a,b.split())])
for a, b in (sub.split(None, 1) #What is sub.split(None,1)
for sub in l:
if int(i) < 10:
To reverse engineer the code, usually working on the python console is the best way to proceed. So, I would start taking the different statements apart one by one and see what each does. Now, there will probably be many different ways to explain/rewrite that code, so mine will be one that hopefully will help you understand the process.
Your code is good, but there is one problem and one discrepancy to the final desired output.
for a, bwith the
for sub in lline, because this should give you an error about
subnot being defined or so.
pairsis a list of lists, and instead you are trying to append a tuple. I say "try" because the statement is invalid and should be written as
pairs.append(("Z",i))for example. But still misses the subtle
listwhich is defined in the original code. In fact there you have a
pairs.append(), and the full logic inside creates what is called a
Nevertheless, very good work from your part.
The final "new code" looks like below and you can see it in action at: https://eval.in/639908
l = ['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2'] pairs =  # for each element in the list for sub in l: # we will create a new empty list new_list =  # split 'sub' into the string and the numbers parts a, b = sub.split(None, 1) # further, split the numbers into a list numbers = b.split() # now using positional index, we will... for x in range(len(a)): # ... create a new tuple taking one character from string # 'a' and one number from list 'numbers' new_tuple = ( a[x], numbers[x] ) # if the value is less than 10, then... if int(numbers[x]) < 10: # ... let's just put "Z" new_tuple = ("Z", numbers[x]) # append this to the temporary list new_list.append(new_tuple) # once the sequence is complete, add it to the main list pairs.append(new_list) # When it's all done, print the list print pairs