Python, gspread. How i can cut or parse my list

Question:

when I use the worksheets() function from gspread package I obtain the list, but this list contains not only string type. how can I obtain only string?
Here is my code:

import gspread


cred = gspread.service_account(filename="creds.json")
sheet = cred.open("nameoftable")
sheet_list = sheet.worksheets()
print(sheet_list)

Out data> [<Worksheet 'Name 0' id:0>, <Worksheet 'Name 1' id:298444145>, <Worksheet 'Name 2' id:1037339372>, <Worksheet 'Name 3' id:1556601152>, <Worksheet 'Name 4' id:2041525675>, <Worksheet 'Name 5' id:1830132413>]

I need a list with only names, but I don’t understand how I can do that.

Asked By: neowhizz

||

Answers:

Use list comprehension to get the title for each worksheet object in the list

[x.title for x in sheet_list]

or map with a lambda function

list(map(lambda x: x.title, sheet_list))
Answered By: It_is_Chris