📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 167question

Set B

Chapter 3: 4 · COMPUTER SCIENCE

Set B The caret (^) operator is used to symmetric difference set operation in python. The function () is also used to do the same operation. ={'A', , , 'D'} ={'A', 'B', 'C', 'D'} print( ^ ) Output: { , , 'B', 'C'} Example: Program to symmetric difference of two sets using caret operator ={'A', , , 'D'} ={'A', 'B', 'C', 'D'} print( . ( )) Output: { , , 'B', 'C'} Example: Program to difference of two sets using symmetric difference function 12th Computer Chapter - - .

. Programs using Sets Program : Program that generate a set of prime numbers and another set of even numbers. Demonstrate the result of union, intersection, difference and symmetirc difference operations. even=set([x* for x in range( , )]) primes=set() for i in range( , ): j= f= while j<=i/ : if i%j== : f= j+= if f== : primes.add(i) print("Even Numbers: ", even) print("Prime Numbers: ", primes) print("Union: ", even.union(primes)) print("Intersection: ", even.intersection(primes)) print("Difference: ", even.difference(primes)) print("Symmetric Difference: ", even.

(primes)) Output: Even Numbers: { , , , , , , , , , } Prime Numbers: { , , , , , , , } Union: { , , , , , , , , , , , , , , , , } Intersection: { } Difference: { , , , , , , , , } Symmetric Difference: { , , , , , , , , , , , , , , , } Example Dictionaries . Introduction In python, a dictionary is a mixed collection of elements. Unlike other collection data types such as a list or tuple, the dictionary type stores a key along with its element. The keys in a Python dictionary is separated by a colon ( : ) while the commas work as a separator for the elements.

The key value pairs are enclosed with curly braces { }. 12th Computer Chapter - - Lists, Tuples, Sets and Dictionary Syntax of defining a dictionary: = { : , : , …….. : } Key in the dictionary must be unique case sensitive and can be of any valid Python type. .

. Creating a Dictionary

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →