0

I'm aware I can just use for loop to iterate through each index and access index 0 of the sublist.

for example:

for i in res:
        print(i[0])

However, I was wondering if it was possible to do something like:

print(*res, sep="\n")

Since the example above is for a normal list and not a nested list, I was wondering if there's a way to print the 0th index of values in a nested list in one line instead of using a loop.

For example [['a', 1.0], ['b', 2.0], ['c', 2.0]] should print: 'a,b,c'

Let me know if I can make anything more clear, thanks.

v0lk
  • 58
  • 1
  • 6

1 Answers1

0

using list comprehension:

my_list = [['a', 1.0], ['b', 2.0], ['c', 2.0]]
print("\n".join([i[0] for i in my_list]))
MartijnVanAttekum
  • 1,405
  • 12
  • 20