Python / google Spreadsheet - How to remove [' '] or get all columns except the first one

Viewed 105

As so many others, I'm new to python and just playing around a little, to build a discord bot for my wow guild.

So far, I've acces to my google spreadsheet and are reading the values with heals = worksheet.col_values(2)

This works fine. My output is in a discord embed and looks like this embed.add_field(name="Healer", value=format(sep.join(heals)), inline=True)

But this method includes ofcourse every value from the column. Now I want to exclude the first row. (A1, B1, C1, and so on)

I have approached different ways and am using now test = worksheet.get('A2:A'), this works to a certain degree. It does what I want, and starts with A2 BUT I can't get it to be formatted in my discord output.

I'm doing my output with embed.add_field(name="Tanks", value=format('\n'.join(map(str, test))), inline=True)

It looks like this:

['Tim']
['Julian'] 

So my question is, how do I get rid of the brackets OR other methods, how I can exclude the first row. I hope I could explain it in a understandable way.

my discord output

1 Answers

Given that test has the following structure:

test = [['Tim'], ['Julian']]

Put this after the definition of test:

test = [item for sublist in test for item in sublist]
'\n'.join(map(str,test))

and this will give this output:

'Tim\nJulian'

which you can pass as a value to add_field().

More explanation:

In more detail, test = [['Tim'], ['Julian']] is a list of lists. In order to flatten this list and get a list of elements instead, you can use List Comprehensions. Please have a look at the documentation to see how the latter work.

Related