papabomay
papabomay

Reputation: 205

Compare two lists in python and obtain non-equality

This piece of code in theory have to compare two lists which have the ID of a tweet, and in this comparison if it already exists in screen printing , otherwise not. But I print all or not being listed. Any suggestions to compare these two lists of ID's and if not the ID of the first list in the second then print it ? Sorry for the little efficient code . ( and my English )

What I seek is actually not do RT ( retweet ) repeatedly when I already have . I use Tweepy library , I read the timeline , and make the tweet RT I did not do RT

def analizarRT():
    timeline = []
    temp = []
    RT = []
    fileRT = openFile('rt.txt')
    for status in api.user_timeline('cnn', count='6'):
        timeline.append(status)
    for i in range(6):
        temp.append(timeline[i].id)
    for a in range(6):
        for b in range(6):
            if str(temp[a]) == fileRT[b]:
                pass
            else:
                RT.append(temp[a])
    for i in RT:
        print i

Solved add this function !

def estaElemento(tweetId, arreglo):
    encontrado = False
    for a in range(len(arreglo)):
         if str(tweetId) == arreglo[a].strip():
            encontrado = True
            break
return encontrado

Upvotes: 0

Views: 68

Answers (2)

user4398985
user4398985

Reputation:

Its a simple program, don't complicate it. As per your comments, there are two lists:)

1. timeline

2. fileRT

Now, you want to compare the id's in both these lists. Before you do that, you must know the nature of these two lists.

I mean, what is the type of data in the lists?

Is it

  1. list of strings? or
  2. list of objects? or
  3. list of integers?

So, find out that, debug it, or use print statements in your code. Or please add these details in your question. So, you can give a perfect answer.

Mean while, try this:

if timeline.id == fileRT.id should work.

Edited:

def analizarRT():
    timeline = []
    fileRT = openFile('rt.txt')
    for status in api.user_timeline('cnn', count='6'):
        timeline.append(status)
    for i in range(6):
        for b in range(6):
            if timeline[i].id == fileRT[b].id:
                pass
            else:
                newlist.append(timeline[i].id)
    print newlist

As per your question, you want to obtain them, right?. I have appended them in a newlist. Now you can say print newlist to see the items

Upvotes: 1

Julien
Julien

Reputation: 15081

your else statement is associated with the for statement, you probably need to add one more indent to make it work on the if statement.

Upvotes: 0

Related Questions