HackerRank Set .union() Operation solution in python | python practice problems for beginners with solutions
In this Set .union() operation problem we need to develop a python program that can read four lines of input and then we need to print the total number of students who have at least one subscription on the output screen.
.union()
The .union() operator returns the union of a set and the set of elements in an iterable.
Also read :Requirement Engineering mcq oose Questions With Answers mca managment by SoftwareTechIT
Sometimes, the | operator is used in place of .union() operator, but it operates only on the set of elements in set.
Set is immutable to the .union() operation (or | operation).
Example
>>> s = set("Hacker")
>>> print s.union("Rank")
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])>>> print s.union(set(['R', 'a', 'n', 'k']))
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])>>> print s.union(['R', 'a', 'n', 'k'])
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])>>> print s.union(enumerate(['R', 'a', 'n', 'k']))
set(['a', 'c', 'r', 'e', (1, 'a'), (2, 'n'), 'H', 'k', (3, 'k'), (0, 'R')])>>> print s.union({"Rank":1})
set(['a', 'c', 'r', 'e', 'H', 'k', 'Rank'])>>> s | set("Rank")
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])
Task
The students of District College have subscriptions to English and French newspapers. Some students have subscribed only to English, some have subscribed to only French and some have subscribed to both newspapers.
You are given two sets of student roll numbers. One set has subscribed to the English newspaper, and the other set is subscribed to the French newspaper. The same student could be in both sets. Your task is to find the total number of students who have subscribed to at least one newspaper.
Also read :Current trends in Software Engineering oose mcq mca(managment) by SoftwareTechIT
Input Format
The first line contains an integer, , the number of students who have subscribed to the English newspaper.
The second line contains space separated roll numbers of those students.
The third line contains , the number of students who have subscribed to the French newspaper.
The fourth line contains space separated roll numbers of those students.
Constraints
Output Format
Also read :Neural Network msc(cs) mcq by SoftwareTechIT
Output the total number of students who have at least one subscription.
Sample Input
9
1 2 3 4 5 6 7 8 9
9
10 1 2 3 11 21 55 6 8
Sample Output
13
Explanation
Roll numbers of students who have at least one subscription:
and . Roll numbers: and are in both sets so they are only counted once.
Hence, the total is students.
Problem solution in Python 2 programming.
eng = set()
fre = set()
n = raw_input()
for i in raw_input().split(' '):
eng.add(i)
m = raw_input()
for i in raw_input().split(' '):
fre.add(i)
sol = eng.union(fre)
print len(sol)
Problem solution in Python 3 programming.
# Enter your code here. Read input from STDIN. Print output to STDOUT
n = int(input())
l = list(input().split())
m = int(input())
k = list(input().split())s1 = set(l)
s2 = set(k)print(len(s1.union(s2)))
Also read :example of Tab Layout in Android Tutorial Develop Android app by SoftwareTechIT
Read More Python Programming Here
HackerRank Alphabet Rangoli problem solution in python | python problem solution
HackerRank Arithmetic Operators solution in python | python Question Solution
HackerRank Calendar Module problem solution in python | python problem solution
HackerRank Capitalize! problem solution in Python | python problem solution
HackerRank Collections.OrderedDict() solution in python | python question solution
HackerRank Collections.deque() solution in python | python problem solution
HackerRank Collections.namedtuple() solution in python | python question solution
HackerRank Compress the String! solution in python | python question solution — New!
HackerRank DefaultDict Tutorial solution in Python | python problem solution
HackerRank Designer Door Mat problem solution in Python | python problem solution
HackerRank Exceptions problem solution in python | python problem solution
HackerRank Find Angle MBC solution in python | python question solution
HackerRank Find a string problem solution in python | python problem solution
HackerRank Find the Runner Up Score solution in python | Python Question Solution
HackerRank Finding the percentage solution in python | hacker rank interview Question solution
HackerRank Incorrect Regex solution in python | python question solution
HackerRank Introduction to Sets solution in python | python question solution
HackerRank Lists problem solution in python | python lists problem
HackerRank Loops problem solution in Python | python question solution
HackerRank Merge the Tools! solution in python | python problem solution
HackerRank Nested Lists problem solution in Python | Hacker Rank Python Question Solution
HackerRank No Idea! problem solution in Python | python question solution
HackerRank Polar Coordinates solution in python | python example solution
HackerRank Print Function problem solution in Python | Python Question Solution
HackerRank Python Division problem solution | python Question Solution
HackerRank Python If-Else problem solution | python Questions Solutions
HackerRank Set .add() problem solution in python | python Question solution
HackerRank Set .discard(), .remove() & .pop() solution in python | python Question Solution
HackerRank String split and join problem solution in python | python problem solution
HackerRank String validators problem solution in python | python problem solution
HackerRank Symmetric Difference solution in python | python question solution
HackerRank Text Alignment problem solution in Python | python problem solution
HackerRank Text Wrap problem solution in Python | python problem solution
HackerRank The Minion Game solution in python | python question solution
HackerRank Time Delta problem solution in python | python question solution
HackerRank Tuples problem solution in python | python Question Solution
HackerRank What’s your name solution in Python | python problem solution
HackerRank Word Order problem solution in Python | python Question solution
HackerRank Write a function problem solution in python | Python Question Solution
HackerRank collections.Counter() solution in Python | python problem solution
HackerRank itertools.combinations() solution in python |python question solution
HackerRank itertools.combinations_with_replacement() solution in python
HackerRank itertools.permutations() solution in Python | python problem solution
HackerRank itertools.product() solution in python | python problem solution
HackerRank sWAP cASE problem solution in python | python problem solution
Hackerrank Mutations problem solution in Python | python problem solution
Hackerrank String Formatting solution in python | python question solution
HackerRankPython
HackerRank Alphabet Rangoli problem solution in python | python problem solution
HackerRank Arithmetic Operators solution in python | python Question Solution
HackerRank Calendar Module problem solution in python | python problem solution
HackerRank Capitalize! problem solution in Python | python problem solution
HackerRank Collections.OrderedDict() solution in python | python question solution
HackerRank Collections.deque() solution in python | python problem solution
HackerRank Collections.namedtuple() solution in python | python question solution
HackerRank Compress the String! solution in python | python question solution — New!
HackerRank DefaultDict Tutorial solution in Python | python problem solution
HackerRank Designer Door Mat problem solution in Python | python problem solution
HackerRank Exceptions problem solution in python | python problem solution
HackerRank Find Angle MBC solution in python | python question solution
HackerRank Find a string problem solution in python | python problem solution
HackerRank Find the Runner Up Score solution in python | Python Question Solution
HackerRank Finding the percentage solution in python | hacker rank interview Question solution
HackerRank Incorrect Regex solution in python | python question solution
HackerRank Introduction to Sets solution in python | python question solution
HackerRank Lists problem solution in python | python lists problem
HackerRank Loops problem solution in Python | python question solution
HackerRank Merge the Tools! solution in python | python problem solution
HackerRank Nested Lists problem solution in Python | Hacker Rank Python Question Solution
HackerRank No Idea! problem solution in Python | python question solution
HackerRank Polar Coordinates solution in python | python example solution
HackerRank Print Function problem solution in Python | Python Question Solution
HackerRank Python Division problem solution | python Question Solution
HackerRank Python If-Else problem solution | python Questions Solutions
HackerRank Set .add() problem solution in python | python Question solution
HackerRank Set .discard(), .remove() & .pop() solution in python | python Question Solution
HackerRank String split and join problem solution in python | python problem solution
HackerRank String validators problem solution in python | python problem solution
HackerRank Symmetric Difference solution in python | python question solution
HackerRank Text Alignment problem solution in Python | python problem solution
HackerRank Text Wrap problem solution in Python | python problem solution
HackerRank The Minion Game solution in python | python question solution
HackerRank Time Delta problem solution in python | python question solution
HackerRank Tuples problem solution in python | python Question Solution
HackerRank What’s your name solution in Python | python problem solution
HackerRank Word Order problem solution in Python | python Question solution
HackerRank Write a function problem solution in python | Python Question Solution
HackerRank collections.Counter() solution in Python | python problem solution
HackerRank itertools.combinations() solution in python |python question solution
HackerRank itertools.combinations_with_replacement() solution in python
HackerRank itertools.permutations() solution in Python | python problem solution
HackerRank itertools.product() solution in python | python problem solution
HackerRank sWAP cASE problem solution in python | python problem solution
Hackerrank Mutations problem solution in Python | python problem solution
Hackerrank String Formatting solution in python | python question solution
Python Interview
HackerRank Alphabet Rangoli problem solution in python | python problem solution
HackerRank Calendar Module problem solution in python | python problem solution
HackerRank Capitalize! problem solution in Python | python problem solution
HackerRank Collections.OrderedDict() solution in python | python question solution
HackerRank Collections.deque() solution in python | python problem solution
HackerRank Collections.namedtuple() solution in python | python question solution
HackerRank Compress the String! solution in python | python question solution — New!
HackerRank DefaultDict Tutorial solution in Python | python problem solution
HackerRank Designer Door Mat problem solution in Python | python problem solution
HackerRank Exceptions problem solution in python | python problem solution
HackerRank Find Angle MBC solution in python | python question solution
HackerRank Find a string problem solution in python | python problem solution
HackerRank Find the Runner Up Score solution in python | Python Question Solution
HackerRank Finding the percentage solution in python | hacker rank interview Question solution
HackerRank Incorrect Regex solution in python | python question solution
HackerRank Introduction to Sets solution in python | python question solution
HackerRank Lists problem solution in python | python lists problem
HackerRank Loops problem solution in Python | python question solution
HackerRank Merge the Tools! solution in python | python problem solution
HackerRank Nested Lists problem solution in Python | Hacker Rank Python Question Solution
HackerRank No Idea! problem solution in Python | python question solution
HackerRank Polar Coordinates solution in python | python example solution
HackerRank Print Function problem solution in Python | Python Question Solution
HackerRank Python Division problem solution | python Question Solution
HackerRank Python If-Else problem solution | python Questions Solutions
HackerRank Set .add() problem solution in python | python Question solution
HackerRank Set .discard(), .remove() & .pop() solution in python | python Question Solution
HackerRank String split and join problem solution in python | python problem solution
HackerRank String validators problem solution in python | python problem solution
HackerRank Symmetric Difference solution in python | python question solution
HackerRank Text Alignment problem solution in Python | python problem solution
HackerRank Text Wrap problem solution in Python | python problem solution
HackerRank The Minion Game solution in python | python question solution
HackerRank Time Delta problem solution in python | python question solution
HackerRank Tuples problem solution in python | python Question Solution
HackerRank What’s your name solution in Python | python problem solution
HackerRank Word Order problem solution in Python | python Question solution
HackerRank Write a function problem solution in python | Python Question Solution
HackerRank collections.Counter() solution in Python | python problem solution
HackerRank itertools.combinations() solution in python |python question solution
HackerRank itertools.combinations_with_replacement() solution in python
HackerRank itertools.permutations() solution in Python | python problem solution
HackerRank itertools.product() solution in python | python problem solution
HackerRank sWAP cASE problem solution in python | python problem solution
Hackerrank Mutations problem solution in Python | python problem solution
Hackerrank String Formatting solution in python | python question solution
RAW
Learn Ethical Hacking From Scratch Free & Paid Udemy And More With SoftwareTechIT