0
$\begingroup$
Diff = [i - j for i,j in zip(text_features, author_signature)]

Diff is a List , text_features = [1, 2, 3] , author_signature = [3, 2, 1]

enter image description here

enter image description here

$\endgroup$
0
$\begingroup$

You must be getting a type error because the elements of text_features and/or author_signatures are not able to be subtracted in the part i - j.

Depending on what they are, you could try converting them. For example, you could try making one or both of them numbers or strings like this:

Diff = [float(i) - float(j) for i,j in zip(text_features, author_signature)]   # both made into numbers

Diff = [str(i) - str(j) for i,j in zip(text_features, author_signature)]   # both made into strings (words)

To give better advice, you need to give an example of what your two lists are that are in the zip()

EDIT

Based on the update in the question, I see that it works as expected for me:

In [1]: text_features = [1, 2, 3]                                                         

In [2]: author_signature = [3, 2, 1]                                                      

In [3]: Diff = [i - j for i,j in zip(text_features, author_signature)]                    

In [4]: Diff                                                                              
Out[4]: [-2, 0, 2]
| improve this answer | |
$\endgroup$
  • $\begingroup$ I edited my question. I tried float , int, str but not working... u can test too $\endgroup$ – Mano Oct 25 '18 at 16:34
  • $\begingroup$ @Mano - see my update. It works for me! $\endgroup$ – n1k31t4 Oct 25 '18 at 16:36
  • $\begingroup$ Again, I edited my question.. very strange because I executed this code on the Jupyter notebook & getting a Type Error. $\endgroup$ – Mano Oct 25 '18 at 16:41
  • $\begingroup$ I was trying to catch the Type Error & No Type Error found ... Hahahaha.... Thanks anyway $\endgroup$ – Mano Oct 25 '18 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.