Ben Muircroft Ben Muircroft - 2 months ago 10
Python Question

Can't a list have symbols in it?

I have not done python before (only javascript). I am finding the docs alien and the other stackoverflow posts on

list.pop()
even more cryptic!

my args are
'0','0','0','0','0000'


here's my code:

i=['.','.','.',':','']

host=''
for v in sys.argv[1:]:
host=host+str(v)+str(i.pop())
host=host[:-1]

print host


I'm trying to get
'0.0.0.0:0000'


But instead I get:
IndexError: pop from empty list


https://repl.it/DirH/1

The reason I ask is that I can't find any SO questions where the list is symbols and the list is declared in plain writing!

Answer
a=['script','location','00','11','22','33','4444']
i=['.','.','.',':','',''] # added an extra ''

host=''

for v in a[1:]:
    host=host+str(v)+i.pop(0)

print (host)

Something like this? Changed pop(0) cause you want the start not the end. Your issue was you were trying to pop more than there was.

Comments