0

This should be a straightforward python question, but it's not working for me. I have a list of strings, the columns, as well as an integer, with repeated number of columns as the output.

multi_cols = lpd.columns
len(multi_cols)
103
multi_cols = [[k]*6 for k in lpd.columns]
len(multi_cols)
103

Why does this output 103?

2 Answers2

1

The resulting multi_cols is a list of lists of length 103, with each element being a list of length 6.

There are several ways to do what you are looking for, I'd refer to this question: How do I make a flat list out of a list of lists?

Wayoshi
  • 1,688
  • 1
  • 7
0

The length of multi_cols is 103 because it is a list containing 103 items.
The instruction [k]*6 results in a list of 6 items. And thus multi_cols is a list of lists.

Husseinfo
  • 472
  • 2
  • 9