Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Node.js – hmac.update() Method
The Hmac class is one of the many utility classes that is used for creating the cryptographic HMAC digests. The Hmac.update() method is used for updating the Hmac content with the data passed. If encoding is not provided and the data is in string format, then the default encoding 'utf8' is enforced.Syntaxhmac.update(data, [encoding])ParametersThe parameters are described below:data − This input parameter takes input for the data with which Hmac will be updated.encoding − This input parameter takes input for the encoding to be considered while updating the Hmac.Example 1Create a file with the name "hmacUpdate.js" and copy the following code snippet. After ...
Read MorePython – Filter Strings within ASCII range
When it is required to filter strings within the ASCII range, the ‘ord’ method that helps with Unicode representation and the ‘all’ operator are used.Below is a demonstration of the same −Examplemy_string = "Hope you are well" print("The string is :") print(my_string) my_result = all(ord(c) < 128 for c in my_string) if(my_result == True): print("The string contains ASCII characters") else: print("The string doesn't contain all ASCII characters")OutputThe string is : Hope you are well The string contains ASCII charactersExplanationA string is defined and is displayed on the console.The ‘ord’ method is called on every letter ...
Read MoreNode.js – forEach() Method
The forEach() method in Node.js is used for iterating over a set of given array items. One can iterate over all the values of the array one-by-one using the forEach array loop.SyntaxarrayName.forEach(function)Parametersfunction − The function takes input for the method that will be executed.arrayName − Array that will be iterated.Example 1Create a file "forEach.js" and copy the following code snippet. After creating the file, use the command "node forEach.js" to run this code.// forEach() Demo Example // Defining a vehicle array const vehicleArray = ['bike', 'car', 'bus']; // Iterating over the array and printing vehicleArray.forEach(element => { console.log(element); });OutputC:\homeode>> ...
Read MorePython – Sort Matrix by Number of elements greater than its previous element
When it is required to sort a matrix based on the number of elements that is greater than the previous element, a list comprehension and the ‘len’ method is used by using a function.Below is a demonstration of the same −Exampledef fetch_greater_freq(row): return len([row[idx] for idx in range(0, len(row) - 1) if row[idx] < row[idx + 1]]) my_list = [[11, 3, 25, 99, 10], [5, 3, 25, 4], [77, 11, 5, 3, 77, 77], [11, 3, 25]] print("The list is :") print(my_list) my_list.sort(key=fetch_greater_freq) print("The resultant list is :") print(my_list)OutputThe list is : [[11, 3, ...
Read MorePython – Maximum in Row Range
When it is required to find the maximum value in a row range, a simple iteration and the ‘max’ method is used.Below is a demonstration of the same −Examplemy_list = [[11, 35, 6], [9, 11, 3], [35, 4, 2], [8, 15, 35], [5, 9, 18], [5, 14, 2]] print("The list is :") print(my_list) i, j = 2, 4 print("The values for integers are ") print(i, j) my_result = 0 for index in range(i, j): my_result = max(max(my_list[index]), my_result) print("The result is :") print(my_result)OutputThe list is : [[11, 35, 6], [9, 11, 3], [35, 4, ...
Read MorePython – Sort by range inclusion
When it is required to sort the list based on range, the ‘abs’ method, the ‘sum’ method and the list comprehension are used using a function.Below is a demonstration of the same −Exampledef sum_range_incl(my_row): return sum([abs(element [1] - element [0]) for element in my_row if element [0] > i and element [0] < j and element [1] > i and element [1] < j]) my_list = [[(12, 4), (55, 10), (11, 16)], [(42, 14)], [(2, 5), (2, 28), (9, 16)], [(12, 6), (6, 13)]] print("The list is :") print(my_list) i, j = 2, 15 ...
Read MorePython – Trim tuples by K
When it is required to trim tuples based on a K value, a simple iteration and the ‘append’ method is used.Below is a demonstration of the same −Examplemy_list = [(44, 3, 68, 11, 5), (68, 44, 9, 5, 8), (8, 11, 2, 68, 5), (44, 68, 2, 5, 7)] print("The list is :") print(my_list) K = 1 print("The value for K is ") print(K) my_result = [] for element in my_list: list_length = len(element) my_result.append(tuple(list(element)[K: list_length - K])) print("The resultant list is :") print(my_result)OutputThe list is : [(44, 3, 68, 11, 5), (68, ...
Read MorePython – Sort row by K multiples
When it is required to sort a row by multiples of K, a method is defined that uses list comprehension and the modulus operator.Below is a demonstration of the same −Exampledef multiple_sort_val(row): return len([ele for ele in row if ele % K == 0]) my_list = [[11, 44, 7, 11], [7, 5, 44, 11], [11, 6, 35, 44], [92, 92, 5]] print("The list is :") print(my_list) K = 11 print("The value for K is ") print(K) my_list.sort(key=multiple_sort_val) print("The resultant list is :") print(my_list)OutputThe list is : [[11, 44, 7, 11], [7, 5, 44, 11], ...
Read MorePython – Filter Sorted Rows
When it is required to filter sorted rows, a list comprehension and the ‘sorted’ and ‘list’ methods are used.Below is a demonstration of the same −Examplemy_list = [[99, 6, 75, 10], [1, 75, 2, 4, 99], [75, 15, 99, 2], [1, 4, 15, 99]] print("The list is :") print(my_list) my_result = [sub for sub in my_list if sub == list(sorted(sub)) or sub == list(sorted(sub, reverse=True))] print("The resultant list is :") print(my_result) OutputThe list is : [[99, 6, 75, 10], [1, 75, 2, 4, 99], [75, 15, 99, 2], [1, 4, 15, 99]] The resultant list is ...
Read MorePython – K middle elements
When it is required to determine K middle elements, the ‘//’ operator and list slicing is used.Below is a demonstration of the same −Examplemy_list = [34, 56, 12, 67, 88, 99, 0, 1, 21, 11] print("The list is : ") print(my_list) K = 5 print("The value of K is ") print(K) beg_indx = (len(my_list) // 2) - (K // 2) end_indx = (len(my_list) // 2) + (K // 2) my_result = my_list[beg_indx: end_indx + 1] print("The result is : " ) print(my_result)OutputThe list is : [34, 56, 12, 67, 88, 99, 0, 1, 21, 11] ...
Read More