Posts

Showing posts from August, 2016

set operations on python

import math first_set={1,math.pi,"d"} second_set={"care","l",4,1,24,2,4,1,2} first_set.add(12) second_set.remove(4) union=first_set | second_set intersection=first_set & second_set difference=first_set - second_set symmetric_difference=first_set ^ second_set #It showed the contents of clusters without similar elements in the cluster. print(list(set(second_set))) print("first set size : ",len(first_set)) print ("\n",union) print ("\n",intersection) print ("\n",difference) print ("\n",symmetric_difference) from itertools import product,permutations,accumulate prodct=list(product(first_set,range(1))) print(prodct,"\n") perm=list(permutations(first_set)) print(perm) accumlt=list(accumulate(str(first_set))) print("accumulate :\n",accumlt)

Python List Trial

import sys print("\n\tremove add show quit") #dynamic list list=[] #add number list.append(12) list.append(18) list.append(17) def my_list():         #lowercase write     s=raw_input("Enter your operation.\n").lower()         if s=="show":                 print(list)         my_list()             elif s=='remove':          if len(list)==0:           print("\n list is empty.")           my_list()        else:           print(list)           x=int(input("enter your number.\n"))           list.remove(x)           my_list()                     elif s=="add":       ...