0

I'm trying to use this code to change sublist value:

sublist = [[1],[1],[1],[]]
list = [sublist,sublist]
print(list)
for i in range(0,2):
    list[0][i] = []
print(list)

And in output I see this:

[[[1], [1], [1], []], [[1], [1], [1], []]]
[[[], [], [1], []], [[], [], [1], []]]

How to change only value of list[0] without changing of the other list elements? Thanks.

  • You are changing for `list[0]`, and no other list. What exactly do you want? – Haris Jul 14 '17 at 14:49
  • I assume you meant `list[0][0][i]` instead of `list[0][i]`. This does seem like a very odd thing to be doing though, you may wish to find another way of implementing whatever it is you're doing. – Tom Wyllie Jul 14 '17 at 14:49
  • 'list' is list of two lists [[1],[1],[1],[]]. I want to set first two elements sublist in first 'list' element as a []. Here in cycle I'm chaging list[0] subelemnts, but in output both list[0] and list[1] were changed. – Nikita Gushchin Jul 14 '17 at 14:55
  • @khelwood Oh, thank you. This is solution – Nikita Gushchin Jul 14 '17 at 14:56

0 Answers0