How can I get items inside a list to print into the terminal individually in Python
List = ["cat", "dog", "snake"]
I want them to print to the terminal on a separate line like
Cat
Dog
Snake
Oh I googled it
I did google it before but I didn't phrase it correctly
for x in list: print(x)
I will save you some time in the future then for other data structures
# list
= [1, 2, 3]
x for thing in x:
print(thing)
# dictionary
= { "a": "apple", "b": "banana" }
x
## For everything here, don't rely on the order you get them in being the same always
for key in x:
print(key) # will give you "a" and "b"
for key in x.keys():
print(key) # identical behaviour to the above, but a bit more explicit
for value in x.values():
print(value) # Will give you "apple" and "banana"
for key, value in x.items():
print(key) # Will give you the pairs ("a", "apple") and ("b", "banana")
print(value)
"a" in x # Will evaluate to True
"apple" in x # Will evaluate to False. "in" with a dictionary checks keys.
# sets
= { 1, 2, 3 }
x
for thing in x:
print(thing) # Will give you 1, 2, and 3, but just like dicts dont rely on the order
## A set is the data structure you should use if you want a list of things where it wouldn't matter
## how many times something is in the list and you don't care about the ordering of those things
1 in x # Will evaluate to True
4 in x # Will evaluate to False
## Small note, make an empty set by calling set(), not by using empty braces {} - That will create an empty dictionary