What is unique about GO language? Here are some of the advantages of GO programming language: Code runs fast Garbage collection Simpler objects Efficient concurrency Code runs faster: Before understanding why GO runs faster, let us know the process of software translation. Basically, we have three broad categories of languages: Machine level language · Machine level language is a low-level language where instructions are directly executed on the CPU. Machine level instructions are small steps which are straight forward and simple (Ex: ADD, SUBTRACT, MULTIPLY ) Assembly language · Assembly language is similar to machine level language but a bit more specific for humans to understand. For example, 1000...
Get link
Facebook
X
Pinterest
Email
Other Apps
Sets in Python Part - 2
Get link
Facebook
X
Pinterest
Email
Other Apps
By
Anonymous
-
If the inputs are given on one line separated by a space
character, usesplit()to get
the separate values in the form of a list:
>> a = raw_input()
5 4 3 2
>> lis = a.split()
>> print (lis)
['5', '4', '3', '2']
If the list values are all integer types, use themap()method to convert all the strings to
integers.
>> newlis = list(map(int, lis))
>> print (newlis)
[5, 4, 3, 2]
Sets are an unordered bag of unique values. A single set
contains values of any immutable data type.
CREATING SETS
>> myset = {1, 2} # Directly assigning values to a set
>> myset = set() # Initializing a set
>> myset = set(['a', 'b']) # Creating a set from a list
>> myset
{'a', 'b'}
MODIFYING SETS
Using theadd()function:
>> myset.add('c')
>> myset
{'a', 'c', 'b'}
>> myset.add('a') # As 'a' already exists in the set, nothing happens
>> myset.add((5, 4))
>> myset
{'a', 'c', 'b', (5, 4)}
Using theupdate()function:
>> myset.update([1, 2, 3, 4]) # update() only works for iterable objects
Both thediscard()andremove()functions take a single value as an
argument and removes that value from the set. If that value is not present,discard()does nothing, butremove()will raise a KeyError exception.
COMMON SET OPERATIONSUsingunion(),intersection()anddifference()functions.
>> a = {2, 4, 5, 9}
>> b = {2, 4, 11, 12}
>> a.union(b) # Values which exist in a or b
{2, 4, 5, 9, 11, 12}
>> a.intersection(b) # Values which exist in a and b
{2, 4}
>> a.difference(b) # Values which exist in a but not in b
{9, 5}
Theunion()andintersection()functions are symmetric methods:
>> a.union(b) == b.union(a)
True
>> a.intersection(b) == b.intersection(a)
True
>> a.difference(b) == b.difference(a)
False
Task
Given sets of integers, and , print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either or but do not exist in both.
Input Format
The first line of input contains an integer, .
The second line contains space-separated integers.
The third line contains an integer, .
The fourth line contains space-separated integers.
Output Format
Output the symmetric difference integers in ascending order, one per line.
Sample Input
4
2 4 5 9
4
2 4 11 12
Sample Output
5
9
11
12
Solution :
m = int(input()) # read m
mstring = input() # read the list of integers
n = int(input()) #read n
nstring = input() # read the list of integers
mlist = mstring.split(" ") #split the list
nlist = nstring.split(" ")
mlist = set(map(int,mlist)) #convert the list into a set of integer type data
nlist = set(map(int,nlist))
l = mlist ^ nlist # performing the operation
slist = sorted(l) #sorting the set
for i in slist: print(i)
# printing the items Problem statement source : HackerRank If you still have a simplest way, then please post your solution in the comments below !!
What is Big data? Data represents useful information. Over the past decade, data has been significantly increasing. Generally we store data in traditional relational databases. This is by far the most efficient method to store and retrieve considering small amounts (generally in megabytes or gigabytes) of data. But what if the data is huge? (By huge I mean really huge.ie, in terms of terabytes or petabytes or exabytes or even zetabytes of data). Such large amount of data is considered as big data. There is no specific meaning for Big Data. It can be defined in many ways. But, if we were to define what big data is, we can define it in the following way: “Big data is the data which cannot be processed on a single machine” So we need some way to store and process data in an efficient manner. This can be achieved using “Hadoop”. What is Hadoop? Hadoop is an open source software framework used for distributed storage and processing of big...
User Location on Android Getting the user’s location on Android is a little less straightforward than on iOS. To start the confusion, there are two totally different ways you can do it. The first is using Android APIs from android.location.LocationListener , and the second is using Google Play Services APIs com.google.android.gms.location.LocationListener . Let’s go through both of them. 1. Android’s Location API The Android’s location APIs use three different providers to get location - · LocationManager.GPS_PROVIDER — This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. · LocationManager.NETWORK_PROVIDER — This provider determines location based on availability of cell tower and WiFi access points. Results are r...
What is unique about GO language? Here are some of the advantages of GO programming language: Code runs fast Garbage collection Simpler objects Efficient concurrency Code runs faster: Before understanding why GO runs faster, let us know the process of software translation. Basically, we have three broad categories of languages: Machine level language · Machine level language is a low-level language where instructions are directly executed on the CPU. Machine level instructions are small steps which are straight forward and simple (Ex: ADD, SUBTRACT, MULTIPLY ) Assembly language · Assembly language is similar to machine level language but a bit more specific for humans to understand. For example, 1000...