-2

i keep getting a typeerror on this code specifically in the last line .join(Q). can anyone help me with it?

Q=[]
a = Question.split()
for i in a:
    if i in stop:
        continue
    else: 
        Q.append(1)
    b = " ".join(Q)
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
Eyad Ahmed
  • 1
  • 1
  • 2
  • 3
    Please update your question with the full error traceback. – quamrana Jan 05 '21 at 18:07
  • Also, in your code you reference a variable called `stop`. What is that? – M-Chen-3 Jan 05 '21 at 18:08
  • 2
    And note that `join` can only join strings, not numbers. – Thierry Lathuille Jan 05 '21 at 18:08
  • `Q.append(1)` appends an integer. You can't use `str.join` on a list of ints. did you mean `Q.append("1")`? – pault Jan 05 '21 at 18:08
  • 'code' stop = stopwords.words('english') print(stop) – Eyad Ahmed Jan 05 '21 at 18:09
  • Possible duplicate of [TypeError: sequence item 0: expected string, int found](https://stackoverflow.com/questions/10880813/typeerror-sequence-item-0-expected-string-int-found) – pault Jan 05 '21 at 18:10
  • Please edit the question with additional information instead of just a comment. And feel free to make a toy example. `stop = stopwords.words('english')` isn't something we can use. Instead pick a couple for the example, `stop = ['foo', 'bar', 'baz']`. And add a `Question = ??` whatever it is. We should be able to copy your code, run it, and see the same result you see. – tdelaney Jan 05 '21 at 18:41

2 Answers2

2

Use str in list comprehension like so:

b = " ".join([str(x) for x in Q])
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
0

Q contains integers and to be passed to join() it must contain strings. Use Q.append("1") to append strings to the list.

SergiyKolesnikov
  • 7,369
  • 2
  • 26
  • 47