Home > Mobile >  Appending a string during list comprehension with np.arange()
Appending a string during list comprehension with np.arange()

Time:11-01

I would a list like this example: [1970s, 1980s, 1990, 2000s, 2010s].

list = [year for year in np.arange(1970, 2020, 10)]

creates a list without the "s" letter.

Is there a way to add a string during list generation? I tried " "s"", .append and similar but nothing worked.

I just need a list to be used as bin_labels. The comments solved the issues. Thanks.

CodePudding user response:

You can use the format() function:

base = "{}s"
[base.format(year) for year in np.arange(1970, 2020, 10)]
  • Related