I have a list of tuples
servers = [('server1', 80 , 1, 2), ('server2', 443, 3, 4)]
I want to create a new list that only has the first two fields as in:
[('server1', 80), ('server2', 443)]
but I cannot see how to craft a list comprehension for more than one element.
hosts = [x[0] for x in servers] # this works to give me ['server1', server2']
hostswithports = [x[0], x[1] for x in servers] # this does not work
I prefer to learn the pythonic way vs using a loop - what am I doing wrong?