Found 26504 Articles for Server Side Programming

Python – Test if Rows have Similar frequency

AmitDiwan
Updated on 04-Sep-2021 10:50:50

159 Views

When it is required to check if rows have similar frequency, the ‘all’ operator, the ‘Counter’ method and a simple iteration is used.Below is a demonstration of the same −Example Live Demofrom collections import Counter my_list = [[21, 92, 64, 11, 3], [21, 3, 11, 92, 64], [64, 92, 21, 3, 11]] print("The list is :") print(my_list) my_result = all(dict(Counter(row)) == dict(Counter(my_list[0])) for row in my_list ) if(my_result == True):    print("All rows have similar frequency") else:    print("All rows do not have similar frequency")OutputThe list is : [[21, 92, 64, 11, 3], [21, 3, 11, 92, ... Read More

Python Program that filters out non-empty rows of a matrix

AmitDiwan
Updated on 04-Sep-2021 10:49:43

196 Views

When it is required to filter out non-empty rows from a matrix, a simple list comprehension along with the ‘len’ method can be used.Below is a demonstration of the same −Example Live Demomy_list = [[21, 52, 4, 74], [], [7, 8, 4, 1], [], []] print("The list is :") print(my_list) my_result = [row for row in my_list if len(row) > 0] print("The resultant list is :") print(my_result)OutputThe list is : [[21, 52, 4, 74], [], [7, 8, 4, 1], [], []] The resultant list is : [[21, 52, 4, 74], [7, 8, 4, 1]]ExplanationA list of list with ... Read More

Python – Test if all elements are unique in columns of a Matrix

AmitDiwan
Updated on 04-Sep-2021 10:47:00

469 Views

When it is required to test if all elements are unique in columns of a matrix, a simple iteration and a list comprehension along with the ‘set’ operator are used.Below is a demonstration of the same −Example Live Demomy_list = [[11, 24, 84], [24, 55, 11], [7, 11, 9]] print("The list is :") print(my_list) my_result = True for index in range(len(my_list[0])):    column = [ele[index] for ele in my_list]    if len(list(set(column ))) != len(column ):       my_result = False       break if(my_result == True):    print("All columns are unique") else: ... Read More

Python – Remove characters greater than K

AmitDiwan
Updated on 04-Sep-2021 10:45:18

175 Views

When it is required to remove characters, which are greater than ‘K’, a simple iteration is used along with the ‘ord’ (Unicode representation) method.Below is a demonstration of the same −Example Live Demomy_list = ["python", "is", "easy", "to", "learn"] print("The list is :") print(my_list) K = 9 print("The value of K is ") print(K) my_result = [] for element in my_list:    result_string = ''    for sub in element:       if (ord(sub) - 97

Python – Check if any list element is present in Tuple

AmitDiwan
Updated on 04-Sep-2021 10:44:01

914 Views

When it is required to check if any list element is present in a tuple or not, a Boolean value and a simple iteration are used.Below is a demonstration of the same −Example Live Demomy_tuple = (14, 35, 27, 99, 23, 89, 11) print("The tuple is :") print(my_tuple) my_list = [16, 27, 88, 99] print("The list is :") print(my_list) my_result = False for element in my_list:    if element in my_tuple :       my_result = True       break print("The result is :") if(my_result == True): print("The element is present in the ... Read More

Python Program to sort rows of a matrix by custom element count

AmitDiwan
Updated on 04-Sep-2021 10:42:37

210 Views

When it is required to sort rows of a matrix by custom element count, a method is defined that uses the list comprehension and ‘len’ method to find the output.Below is a demonstration of the same −Example Live Demodef get_count_matrix(my_key):    return len([element for element in my_key if element in custom_list]) my_list = [[31, 5, 22, 7], [85, 5], [9, 11, 22], [7, 48]] print("The list is :") print(my_list) custom_list = [31, 85, 7] my_list.sort(key=get_count_matrix) print("The resultant list is :") print(my_list)OutputThe list is : [[31, 5, 22, 7], [85, 5], [9, 11, 22], [7, 48]] The ... Read More

Python Program to Filter Rows with a specific Pair Sum

AmitDiwan
Updated on 04-Sep-2021 10:40:49

216 Views

When it is required to filter rows with a specific pair sum, a method is defined. It checks to see if elements in a specific index is equal to key, and returns output based on this.Below is a demonstration of the same −Example Live Demodef find_sum_pair(val, key):    for index in range(len(val)):       for ix in range(index + 1, len(val)):          if val[index] + val[ix] == key:             return True    return False my_list = [[71, 5, 21, 6], [34, 21, 2, 71], [21, 2, 34, 5], [6, 9, ... Read More

What are the special symbols in C language?

Bhanu Priya
Updated on 12-Dec-2024 17:16:02

63K+ Views

In C programming language, generally, the special symbols have some special meaning. This language provides low-level access to the memory and it is identified for its performance and efficiency. The C language includes a character set of English alphabets(a-z, A-Z), digits(0-9), and specific meaning with special characters. Some special characters are operators, while combinations like "" are escape sequence. In C symbols are used to perform special operations. Some of the special symbols that are used in C programming are as follows − [] () {}, ; * = # Common Characters in C Programming Let’s understand their definitions, which ... Read More

How to convert binary to Hex by using C language?

Bhanu Priya
Updated on 09-Dec-2024 16:44:29

11K+ Views

Binary numbers are represented in 1’s and 0’s. It can also be referred to as a rational number with a finite representation in the system. This is a quotient of an integer by a power of two. Hexadecimal number system with 16 digits is {0, 1, 2, 3…..9, A(10), B(11), ……F(15)}. In base 16 transfer encoding, each byte of plain text is divided into two 4-bit values, which are represented by two hexadecimal digits. Converting Binary to Hex using C To convert from binary to hexadecimal representation, the bit string is grouped into 4-bit blocks, called nibbles, starting from the ... Read More

What are different types of data in C language?

Bhanu Priya
Updated on 03-Sep-2021 07:05:41

1K+ Views

Datatype is the declaration of memory location or variable. Data can be of different types and some of the examples of data types in C language are as follows −Integers, rational numbers, whole numbers, real numbers, complex numbers, vectors, characters etc.Coming to the machine hardware, the data is everything encoded as a string of binary digits 0 and 1 of finite length. In the machines, the integer data is processed in the arithmetic logic unit (ALU) and fractional data is processed in the floating-point unit (FPU). This gets reflected in the built-in or primitive data types of a high-level language.Built-in ... Read More

Advertisements