Reputation: 690
I have a list I generate like this:
cols = [td['data-stat'] for td in rows[0].find_all("td")]
cols
contains:
['age','team_id','lg_id','pos','g','gs','mp','fg', ...]
as it should. However, when I insert "season" to the beginning OR extend ["season"]
with cols
, I suddenly get NoneType
:
new_cols = ["season"].extend(cols)
Any ideas?
Upvotes: -1
Views: 42
Reputation: 27577
The list.extend()
method doesn't return a value, it alters an existing one.
If you want a separate list that contains every element in the cols
list, along with the "extend"
string, use the list.copy()
method to duplicate the list, and use the list.extend()
method on the new list:
new_cols = cols.copy()
new_cols.extend(["season"])
If you do not intend to keep the old list, then you can directly use the list.extend()
method on the old list:
cols.extend(["extend"])
Upvotes: 2