Aug 31, 2010

More Python functions

del()
This can be used to remove lists and rev=move slices from a list.
del a[0]
del a[2:4]
del a
Tuples
t=123,567,'hello'
print t
(123, 576, 'hello')
nested tuples
u = t,(45,67)
print u
((123,567,'hello'),(45,67))
sets
This will do the arithmetic operations like union, intersection, etc.
basket=['apple','orrange', 'banana', apple' , 'orrange']
fruit=set(basket)
print fruit
set('apple','orrange','banana')
print orrange in fruit
TRUE
set_a=('abcdefg')
set_b=('efghijk')
set_a - set_b - this give the lettres which are only in "set_a"
set_a | set_b - gives the union
set_a & set_b - gives the intersection
set_a ^ set_b - letters in set_a or set_b but not both

No comments:

Post a Comment

Your comments are always welcome ...