'How do you print an entire row of a list made of words?
I have simplified my question where I just have a 2x2 list of words. I'm trying to print an entire row but it evidently doesn't work the same as with a list of numbers. How would I print an entire row? This is for simple list manipulation.
array=[dog, cat],[hat,cap]
print(array[0][:])
I'm looking for an output of dog cat
.
Solution 1:[1]
I assume you mean
array = [['dog','cat'],['hat','cap']]
and you want to print without the quotation marks and square brackets. In this case
print(' '.join(array[0]))
should do the job. Note the space in quotation marks.
Generally, its advised that you don't name your variables (in this case 'array') after things that are already part of python. Might be better to choose something like
string_list = [['dog','cat'],['hat','cap']]
Solution 2:[2]
array = [['dog','cat'],['hat','cap']]
a = list(array)
print(a[0:1])
Maybe this will help? I'm beginner in python so I'am not sure if this solution is right. After this it will print: [['dog', 'cat']]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Balage |