0

How can I generate a sequence of string numbers in a list in python? For example I want numbers starting from 3000 to 3100 that are stored in a list and are also in string format.

Something like this ['3000', '3001', '3002', ......., '3100']

Bob
  • 32
  • 6

3 Answers3

2

Use the range function, then combine with a map(str,)

# list of int
values = list(range(3000, 3101))
print(values)  # [3000, 3001, 3002, 3003, 3004 ... 3100]

# list of string representation of int
values = list(map(str, range(3000, 3101)))
print(values)  # ['3000', '3001', '3002', '3003',, ... '3100']
azro
  • 53,056
  • 7
  • 34
  • 70
  • @Vignesh Can you show expected result ? Because there is several ways, how concatenated, all, prefix, suffix ? – azro May 15 '21 at 17:16
2
[str(i) for i in range(3000, 3100+1)]

This is faster than using map().

user38
  • 151
  • 1
  • 14
1

first, you can generate a list from numbers, and then you can convert the type of the elements to a string.

mylist=list(range(3000,3101))
convertlist = list()
for x in mylist:
    convertlist.append(str(x))
   
print(convertlist)
print(type(convertlist[0]))