are these operations on list valid?
Robin Munn
rmunn at pobox.com
Tue Oct 15 11:17:50 EDT 2002
In article <ano9fi$fo0ko$1 at ID-49758.news.dfncis.de>, Ken wrote:
> Hi, just like to know if these are valid:
>
> 1:
> Use:
> var1 = "hello"
> var2 = "world"
> list = [var1, var2]
>
> Instead of:
> list = []
> list.append(var1)
> list.append(var2)
Yes.
> --------------------
> 2.
> Use:
> list=["hello", "world"]
> if list==["hello", "world]: #comparing list with list without examining
^ (Missing ")
> through every element inside
> do something.....
>
> Instead of:
> list1=["hello", "world"]
> if list[0]==list1[0] and list[1]==list1[1]:
> do something....
> ---------------------
Yes (once you fix the typo :-)).
Both of these constructions will do exactly what you would expect.
--
Robin Munn
rmunn at pobox.com
More information about the Python-list
mailing list