1

I want to compare two lists: -CAGGTGGTGAT (my_list[0])

--CAGGTGTGAT (my_list[1])

And I want to find how many pairs I have (A-A, C-C, G-G, T-T) and how many mismatches. I have this code for the mismatches

for i in range(len(my_list[0])):
        if my_list[0][i-1]!=my_list[1][i-1]:
            print("mismatch")

How can i count how many mismatches are printed? I tried to use count, but it counts pairs and mismatches. I want to count only the mismatches that are printed.

1 Answer 1

1

You can use sum() with zip() to count the mismatches:

mylist = ["-CAGGTGGTGAT", "--CAGGTGTGAT"]

mismatches = sum(a != b for a, b in zip(mylist[0], mylist[1]))
print(mismatches)

Prints:

5
Sign up to request clarification or add additional context in comments.

3 Comments

it returns the error 'Counter' object is not callable. I'm new to python so I don't really know what I can do.
@anastasia You've probably assigned to name sum before. Don't use python builtin names as variable names.
if i didn't assign sum before, what might be the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.