[Solved] List index out of range in python

[ad_1]

You check for the empty line after appending the splitted line to data. .split() on an empty line returns an empty list.

x[0] on an empty list produces an IndexError.

data +=[line.split()] # equal to data.append([])
if line =='':
    ips=[
         x[0] # Access to the first element of every list in data.
         for x in data
        ]

You need to check for the empty line before appending it to data

0

[ad_2]

solved List index out of range in python