Binary Element List Grouping in Python

Pradeep Elance
Updated on 09-Jul-2020 12:46:49

252 Views

Suppose we have a list of lists in which each sublist has two elements. One element of each sublist is common across many other subjects of the list. We need to create a final list which will show sublists grouped by common elements.With set and mapIn the given list the first element is a string and the second element is a number. So we create a temp list which will hold the second element of each sublist. Then we compare is sublist with each of the element in the temp list and designer follow to group them.Example Live DemolistA = [['Mon', ... Read More

Add the Occurrence of Each Number as Sublists in Python

Pradeep Elance
Updated on 09-Jul-2020 12:42:17

187 Views

We have a list whose elements are numeric. Many elements are present multiple times. We want to create sub list so the frequency of each element along with the elements itself.With for and appendIn this approach we will compare each element in the list with every other elements after it. If there is a match then count will be incremented and both the element and the count will be made into a subsist. List will be made which should contain subsists showing every element and its frequency.Example Live Demodef occurrences(list_in):    for i in range(0, len(listA)):       a = ... Read More

Add Only Numeric Values Present in a List in Python

Pradeep Elance
Updated on 09-Jul-2020 12:38:59

1K+ Views

We have a Python list which contains both string and numbers. In this article we will see how to sum up the numbers present in such list by ignoring the strings.With filter and isinstanceThe isinstance function can be used to filter out only the numbers from the elements in the list. Then we apply and the sum function and get the final result.Example Live DemolistA = [1, 14, 'Mon', 'Tue', 23, 'Wed', 14, -4] #Given dlist print("Given list: ", listA) # Add the numeric values res = sum(filter(lambda i: isinstance(i, int), listA)) print ("Sum of numbers in listA: ", res)OutputRunning the ... Read More

Accessing Key-Value in a Python Dictionary

Pradeep Elance
Updated on 09-Jul-2020 12:37:20

5K+ Views

While analyzing data using Python data structures we will eventually come across the need for accessing key and value in a dictionary. There are various ways to do it in this article we will see some of the ways.With for loopUsing a for loop we can access both the key and value at each of the index position in dictionary as soon in the below program.Example Live DemodictA = {1:'Mon', 2:'Tue', 3:'Wed', 4:'Thu', 5:'Fri'} #Given dictionary print("Given Dictionary: ", dictA) # Print all keys and values print("Keys and Values: ") for i in dictA :    print(i, dictA[i])OutputRunning the above code ... Read More

Accessing Index and Value in a Python List

Pradeep Elance
Updated on 09-Jul-2020 12:34:46

3K+ Views

When we use a Python list, will be required to access its elements at different positions. In this article we will see how to get the index of specific elements in a list.With list.IndexThe below program sources the index value of different elements in given list. We supply the value of the element as a parameter and the index function returns the index position of that element.Example Live DemolistA = [11, 45, 27, 8, 43] # Print index of '45' print("Index of 45: ", listA.index(45)) listB = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Print index of 'Wed' print("Index of ... Read More

Make GridLayout Fit Screen Size in Android

Azhar
Updated on 09-Jul-2020 12:07:43

2K+ Views

This example demonstrates how How to make a GridLayout fit screen size in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                                                                 Step 3 − Add the following code to src/MainActivity.javapackage com.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.Gravity; import android.widget.GridLayout; import android.widget.ImageView; ... Read More

Binary to Gray Code Using Recursion in C Program

sudhir sharma
Updated on 09-Jul-2020 11:49:04

2K+ Views

A Binary number is a number that has only two bits 0 and 1.Gray code is a special type of binary number that has a property that two successive number of the code cannot differ more than one bit. This property of gray code makes it useful more K-maps, error correction, communication, etc.This makes the conversion of binary to gray code necessary. So, let’s see an algorithm to convert binary to gray code using recursion.ExampleLet’s take an example of gray code coInput : 1001 Output : 1101AlgorithmStep 1 : Do with input n :    Step 1.1 : if n ... Read More

Binary Representation of Previous Number in C++

sudhir sharma
Updated on 09-Jul-2020 11:40:57

314 Views

In this problem, we are given the binary representation of a number and we have to find the binary representation of the previous number i.e. the number that is resulted after subtracting one from the given number.Binary representation of a number is changing the base of the number to base 2 and representing the number using only 0 or 1.For example, Binary representation of 23 is 10111.So, here we would be given a number, let's say n in binary form. And we have to find the binary representation of n-1.To solve this problem, we need to know the basics of ... Read More

Styling Tables with CSS

AmitDiwan
Updated on 09-Jul-2020 09:25:55

181 Views

We can define styles for tables using CSS. The following properties are used to style and its elements −borderThe CSS border property is used to define border-width, border-style and border-color.border-collapseThis property is used to specify whether a elements should have a shared or separate border.captionThe caption-side property is used to vertically position the table caption box.empty-cellsThis property is used to specify the display of empty cells of a table.table-layout To define the algorithm to be used by the browser for laying out rows, columns and cells of a table.ExampleThe following examples illustrate styling of tables − Live Demo ... Read More

Find Rate Percentage from Compound Interest of Consecutive Years in C++

Ayush Gupta
Updated on 09-Jul-2020 08:55:38

189 Views

In this tutorial, we will be discussing a program to find the rate percentage from compound interest of the consecutive years.For this, we will be provided with two integers say A and B that are the interests of two consecutive years. Our task is to find the rate of interest for the given values.Finding the relation between the given values and eliminating the principal amount, we get the formula asrate = ((B-A)*100)/AExample#include using namespace std; //calculating the rate of interest float calc_rate(int N1, int N2) {    float rate = (N2 - N1) * 100 / float(N1);    return ... Read More

Advertisements