I am very new to python.

I am making a program to see if certain part of current line is same as that of next line

for example

perter's age is 16
john's age is 16
Craig's age is 18

I want to see if people's ages are the same or not.

how do you set a program to compare the ages?

thank you in advance

Recommended Answers

All 4 Replies

Check out Python module difflib

thanks for the reply ZZucker
but can you give me some example of how to compare new line to current line?

Also what I really wanna do is that if the age is the same I want to write their names onto different .txt file.

You should try to come up with some code,many just post there school task here and show no effort to solve it.
When that said,here something you can look at.

with open('people.txt') as f, open('names.txt', 'w') as f_out:
    lst = [i.split() for i in f]
    lst_diff = [x for x in lst[-1] if x in lst[-1]]
    if lst_diff in lst:
        lst.remove(lst_diff)
    f_out.write('\n'.join(i[0] for i in lst))

    """names.txt Output-->
    perter's
    john's
    """
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.