Skip to content
Advertisement

How to count the occurrences of a string in a number of string pairs in python? [closed]

I have two textfiles here. I want to count the number of occurrences of strings in “Textfile 1” among the string pairs given in “Textfile 2”.

Textfile_1:

JavaScript

Textfile_2:

JavaScript

Expected Output:

JavaScript

I tried the following script. But it is not giving the expected output.

JavaScript

Does anybody know how to do this in python? I’m quite new to python programming.

Advertisement

Answer

A few things not done correctly in your code. Here’s the list comprehension code.

JavaScript

The output of this is:

JavaScript

The output to Textfile_3 will be:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement