Hello! Explain, please, in detail the meaning of the index () method in the list. Not just an example, but with an explanation. There is code that works but understand how the index () method works in this code does not reach ...
test=[ {'is_blocked': 0, 'ip': '10.10.10.1', 'id': 113}, {'is_blocked': 0, 'ip': '10.10.10.16', 'id': 113}, {'is_blocked': 0, 'ip': '10.10.10.1', 'id': 114}, {'is_blocked': 0, 'ip': '10.10.10.16', 'id': 115}, {'is_blocked': 0, 'ip': '10.10.10.1', 'id': 114}, {'is_blocked': 0, 'ip': '10.10.10.16', 'id': 116} ] def f(arr): vals, ips, res=[], [], [] for i in arr: ip= i['ip'] del i['ip'] try: ips[vals.index(i)]+= ","+ip except: vals.append(i) ips.append(ip) for i in range(len(vals)): vals[i]['ip']=ips[i] res.append(vals[i]) print res