ExampleBelow is a demonstration of the samedef diff_summation_elem(row): return sum([abs(row[index + 1] - row[index]) for index in range(0, len(row) - 1)]) my_list = [[97, 6, 47, 3], [6, 88, 3, 26], [71, 53, 34, 65], [15, 36, 5, 62]] print("The list is : ") print(my_list) my_list.sort(key=diff_summation_elem) print("The resultant list is :" ) print(my_list)OutputThe list is : [[97, 6, 47, 3], [6, 88, 3, 26], [71, 53, 34, 65], [15, 36, 5, 62]] The resultant list is : [[71, 53, 34, 65], [15, 36, 5, 62], [97, 6, 47, 3], [6, 88, 3, 26]]ExplanationA ... Read More
When it is required to append given number with every element of the list, a list comprehension is used.ExampleBelow is a demonstration of the samemy_list = [25, 36, 75, 36, 17, 7, 8, 0] print ("The list is :") print(my_list) my_key = 6 my_result = [x + my_key for x in my_list] print ("The resultant list is :") print(my_result)OutputThe list is : [25, 36, 75, 36, 17, 7, 8, 0] The resultant list is : [31, 42, 81, 42, 23, 13, 14, 6]ExplanationA list is defined and is displayed on the console.An integer value for key ... Read More
When it is required to get the cumulative row frequencies in a list, the ‘Counter’ method, and a list comprehension are used.ExampleBelow is a demonstration of the samefrom collections import Counter my_list = [[11, 2, 32, 4, 31], [52, 52, 3, 71, 71, 3], [1, 3], [19, 19, 40, 40, 40]] print("The list is :") print(my_list) my_element_list = [19, 2, 71] my_frequency = [Counter(element) for element in my_list] my_result = [sum([freq[word] for word in my_element_list if word in freq]) for freq in my_frequency] print("The resultant matrix is :") print(my_result)OutputThe list is : [[11, 2, ... Read More
When it is required to get the minimum element to construct a string, the ‘set’ operator, the ‘combinations’ method, the ‘issubset’ method and a simple iteration is required.ExampleBelow is a demonstration of the samefrom itertools import combinations my_list = ["python", "is", "fun", "to", "learn"] print("The list is :") print(my_list) my_target_str = "onis" my_result = -1 my_set_string = set(my_target_str) complete_val = False for value in range(0, len(my_list) + 1): for sub in combinations(my_list, value): temp_set = set(ele for subl in sub for ele in subl) ... Read More
To sum all the rows of a DataFrame, use the sum() function and set the axis value as 1. The value axis 1 will add the row values.At first, let us create a DataFrame. We have Opening and Closing Stock columns in itdataFrame = pd.DataFrame({"Opening_Stock": [300, 700, 1200, 1500], "Closing_Stock": [200, 500, 1000, 900]})Finding sum of row values. Axis is set 1 to add row valuesdataFrame = dataFrame.sum(axis = 1) ExampleFollowing is the complete code import pandas as pd dataFrame = pd.DataFrame({"Opening_Stock": [300, 700, 1200, 1500], "Closing_Stock": [200, 500, 1000, 900]}) print"DataFrame...", dataFrame # finding sum of ... Read More
To create a subset by choosing specific values from columns based on indexes, use the iloc() method. Let us first import the pandas libraryimport pandas as pdCreate a Pandas DataFrame with Product records. We have 3 columns in itdataFrame = pd.DataFrame({"Product": ["SmartTV", "ChromeCast", "Speaker", "Earphone"], "Opening_Stock": [300, 700, 1200, 1500], "Closing_Stock": [200, 500, 1000, 900]})Creating a subset with 2 columns and 1st 2 rows using iloc(print"Displaying a subset using iloc() = ", dataFrame.iloc[0:2, 0:2] ExampleFollowing is the complete codeimport pandas as pd dataFrame = pd.DataFrame({"Product": ["SmartTV", "ChromeCast", "Speaker", "Earphone"], "Opening_Stock": [300, 700, 1200, 1500], "Closing_Stock": [200, 500, 1000, 900]}) ... Read More
Encapsulating Security Payload (ESP) provides all encryption services in IPSec based on integrity for the payload and not for the IP header, confidentiality and authentication that using encryption, without authentication is strongly discouraged because it is insecure.Any translations in readable message format into an unreadable format are encrypted and used to hide the message content against data tampering.IPSec provides an open framework, such as SHA and MD5 for implementing industry standard algorithms.Encryption/decryption allows only the sender and the authorised receiver to make the data to be received in readable form and only after the integrity verification process is complete, the ... Read More
Authentication Header (AH) is used to provide integrity and authentication to IP datagrams. Replay protection is also possible. The services are connectionless, that means they work on a per-packet basis.AH is used in two modes as follows −Transport modeTunnel modeAH authenticates are the same as IP datagram. In transport mode, some fields in the IP header change en-route and their value cannot be predicted by the receiver. These fields are called mutable and they are not protected by AH.Mutable IPv4 fieldsThe mutable IPv4 fields are as follows −Type of service (TOS)FlagsFragment offsetTime to live (TTL)Header checksumTo protect these fields, tunnelling ... Read More
IP Security (IPSec) is a collection of protocols which is designed by Internet Engineering Task Force (IETF) to provide security for a packet at the network level. It helps to create confidential and authenticated and packets for the IP layer as shown in below diagram −IPSec protocol aim is to provide security services for IP packets like encrypting sensitive data/packets, authentication, and protection against replay and data confidentiality. It can be configured to operate in two different modes −Tunnel ModeTransport mode.The original packet is generated as follows −IP HeaderUDP HeaderDataLet us discuss each mode in detail.Tunnel modeIPSec tunnel mode is ... Read More
Let us understand what the domain name system (DNS) is.Domain Name SystemAll the web servers connected to the internet have a unique IP address in textual form. Now, the process of translating the textual form into an IP address is called DNS or DOMAIN NAME SERVICE name resolution.Theoretically during the name resolution process the program that wishes for the name translation contacts a DNS server that returns the translated IP address, but in reality the entire translation may not occur at a single DNS server, rather the DNS server contacted first will recursively call upon other DNS servers to complete ... Read More
 Data Structure
 Networking
 RDBMS
 Operating System
 Java
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP