LoginSignup
2

More than 5 years have passed since last update.

pythonでカンマ区切りテキストを作成する

Posted at

pythonでカンマ区切りテキストを作成する

2000~2030までの整数をカンマ区切りで並べたテキストを作成したい。

data = [i for i in range(2000, 2031)]
result = ','.join(map(str, data))

内包表記をつかうなら、以下のほうがpythonic
map関数を使わずに済む

data = [str(i) for i in range(2000, 2031)]
result = ','.join(data)

数が多い場合はジェネレータを使うのがいいかも

data = (str(i) for i in range(2000, 3600000))
result = ','.join(data)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2