How do I save the Python list separately?

Asked 2 years ago, Updated 2 years ago, 9 views

i = []
for data in range(1,101):
    i.append(data)

for data in range(101,201):
    i.append(data)

print(i)

This code [[1,2,3,4,5,6,7....100],[101,102,103,200] I want to save it in this way, but what should I do?

python

2022-09-22 11:09

2 Answers

Performance, when viewing memory utilization

>>> i = [range(1, 101), range(101, 201)]
>>> print(i[1][50])
151

It's better to do it with


2022-09-22 11:09

i = [[],[]]
for data in range(1,101):
    i[0].append(data)

for data in range(101,201):
    i[1].append(data)

print(i)

After declaring this two-dimensional list, How about making it like append to element 0 and append to element 1?


2022-09-22 11:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.