[Tutor] Add elements to list and display it [Very newbie question]

Kent Johnson kent37 at tds.net
Tue Mar 3 00:22:07 CET 2009


On Mon, Mar 2, 2009 at 5:36 PM, Network Administrator
<administrador.de.red at gmail.com> wrote:
> I appreciate your explanation about the reserved word "list" as well as the
> code you gently wrote to me. Now, I want to show everybody what I did:
>
> #!/usr/bin/env python
> #####################
> # This function fills any given list
> #
> mylist = []
> x = 0
> while (x != 't2'):
>     x = raw_input('Enter IP: ')
>     mylist.append(x)
> mylist.pop()

A little more straightforward, perhaps:
mylist = []
while True:
  x = raw_input('Enter IP: ')
  if x == 't2':
    break
  mylist.append(x)

Kent


More information about the Tutor mailing list