0

I need to copy a variable and make changes to it. I've alredy seen this, but i want the oposite. In this code i need the returned tuple to be two different lists, not the same.

def getIPRange(self):
    group = [0, self.getJoinedNetworks() - 1]
    while True:
        if self.ip[2] > group[0] and self.ip[2] < group[1]:
            res_ip_min = self.ip      #self.ip is for example [70, 30, 20, 0]
            res_ip_min[2] = group[0]
            res_ip_min[3] = 1

            res_ip_max = self.ip
            res_ip_max[2] = group[1]
            res_ip_max[3] = 254

            return (res_ip_min, res_ip_max)

        else:
            group[0] = group[1] + 1
            group[1] = group[0] + self.getJoinedNetworks() - 1
Community
  • 1
  • 1
gcq
  • 937
  • 3
  • 13
  • 19

1 Answers1

0

The most common is probably to do

...
res_ip_min = list(self.ip)
...
res_ip_max = list(self.ip)
...

which creates a new list from the elements of self.ip. Alternately you can use python's copy utilities

kalhartt
  • 3,999
  • 20
  • 25