tarmas99
tarmas99

Reputation: 429

Why `None` is printed in Google colab when I try to print a list?

I have two lists, sentences and tags, which are actually list of lists.

When I try to print

print(sentences[1]), print(tags[1])

output comes as

['Made', 'it', 'back', 'home', 'to', 'GA', '.', 'It', 'sucks', 'not', 'to', 'be', 'at', 'Disney', 'world', ',', 'but', 'its', 'good', 'to', 'be', 'home', '.', 'Time', 'to', 'start', 'planning', 'the', 'next', 'Disney', 'World', 'trip', '.']
['O', 'O', 'O', 'O', 'O', 'loc', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'facility', 'facility', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'facility', 'facility', 'O', 'O']
(None, None)

I can't work out why None is getting printed.

Upvotes: 0

Views: 761

Answers (1)

DeepSpace
DeepSpace

Reputation: 81594

Because x, y creates a tuple which the notebook tries to evaluate (and therefore every element in the tuple is evaluated).

Since print returns None, you are getting the tuple (None, None) as an output.

In order to remedy this put each print call on its own line instead of creating the tuple.

Upvotes: 3

Related Questions