Add Label to Kivy Window in Python

Pradeep Elance
Updated on 28-Dec-2020 11:25:51

685 Views

Kivy is an pen source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. It is used to develop the Android application, as well as Desktops applications. In this article we will see how to add labels to the windows created through Kivy.Creating LabelIn the below example we create a window and give it a custom label by using Label function available in uix.lable module. Once we run the app with this code we get the new window showing the custom label.Examplefrom kivy.app import App from kivy.uix.label import Label class ... Read More

Use ClickAndWait in Selenium WebDriver with Java

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:24:42

2K+ Views

We can click and wait in Selenium. This can be achieved by the synchronization concept. We shall use the explicit wait condition and wait for an element to be clickable prior to the next step.The explicit wait waits for a specified amount of time before throwing an exception. To verify if an element is clickable, we can use the expected condition elementToBeClickable.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class ElementClickableWait{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();     ... Read More

Combine Two Lists While Maintaining Duplicates in Python

Pradeep Elance
Updated on 28-Dec-2020 11:22:16

411 Views

In data analysis using python we may come across situation when two lists need to be merged. But it may be a challenge to handle the duplicate elements present in those lists. In this article we will see how to combine two lists by maintain all the elements form the first list and only the unique elements from the second list.Using extendIn this approach we take the first list and create a result list. Then we design a for loop to check for the presence of element of the first list in the second list and if the element is ... Read More

Connect to Chromium Headless Using Selenium

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:21:59

474 Views

We can connect to Chromium headless with Selenium. The headless execution helps in reducing resource utilization and is a modern technique used in the industry.Chrome can be used in headless mode after the 59 version. The ChromeOptions class is used to change the default browser behavior. The headless value is passed to the addArguments method as a parameter for headless execution.SyntaxChromeOptions op = new ChromeOptions(); op.addArguments("headless"); WebDriver d = new ChromeDriver(op);ExampleCode Implementation.import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class HeadlessChromium{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       //ChromeOptions object     ... Read More

Convert 1D List to 2D List of Variable Length in Python

Pradeep Elance
Updated on 28-Dec-2020 11:20:56

3K+ Views

A list in python is normally a 1D list where the elements are listed one after another. But in a 2D list we have list nested inside the outer list. In this article we will see how to create a 2D list from a given 1D list. We also supply the values for the number of elements inside the 2D list to the program.Using append and indexIn this approach we will create a for loop to loop through each element in the 2D list and use it as an index for the new list to be created. We keep incrementing ... Read More

Convert List of Lists into Tree-Like Dict in Python

Pradeep Elance
Updated on 28-Dec-2020 11:19:45

1K+ Views

Given a nested list we want to convert it to a dictionary whose elements can be considered as part of a tree data structure. In this article we will see the two approaches to convert a nested list into to add dictionary whose elements represent a tree like data structure.Using SlicingWe reverse the items in the list aby slicing and then check if the item is present in the list. If it is not present we ignore it else we add it to the tree.Exampledef CreateTree(lst):    new_tree = {}    for list_item in lst:       currTree = ... Read More

Convert Flattened Dictionary into Nested Dictionary in Python

Pradeep Elance
Updated on 28-Dec-2020 11:18:13

709 Views

Python dictionaries have keys and values. If we have two or more dictionaries to be merged a nested dictionary, then we can take the below approaches. Here year the dictionaries are given along with the new keys that will become a key in the nested dictionary.Assigning keysIn this approach we will create a new empty dictionary. Then assigned the given dictionaries to each new key. The resulting dictionary will be a nested dictionary with the keys assigned.ExampledictA = {'Sun': 1, 'Mon': 2} dictB = {'Tue': 3, 'Sun': 5} # Given Dictionaries print("DictA : ", dictA) print("DictB: ", dictB) ... Read More

Combine Two Dictionaries by Adding Values for Common Keys in Python

Pradeep Elance
Updated on 28-Dec-2020 11:17:05

2K+ Views

When analyzing data with python we come across situations when we have to merge two dictionaries in such a way that we add the values of those elements whose keys have equal values. In this article we will see such two dictionaries getting added.With For loop and | OperatorIn this approach we design a for loop to check for the presence of the value of the key in both the dictionaries and then add them. Finally we merge the two dictionaries using the | operator available for the dictionaries.ExampledictA = {'Mon': 23, 'Tue': 11, 'Sun': 6} dictB = {'Wed': 10, ... Read More

Get HTTP Response Code Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:16:29

6K+ Views

We can get an HTTP response code in Selenium webdriver. While running test cases, we can check the response code from a resource. Common HTTP response codes include −5XX – Issue in server.4XX – Resource cannot be determined.3XX - Redirection.2XX – Fine.An object of the class HttpURLConnection is created to get the HTTP response code. To establish a link to an URL, the openConnection method shall be used. Next, we shall utilize the setRequestMethod and pass HEAD as a parameter.For connection, the connect method is to be applied to the instance of the HttpURLConnection class. At last, the getResponseCode method ... Read More

Check if K Occurs At Least N Times in a List

Pradeep Elance
Updated on 28-Dec-2020 11:15:57

334 Views

Many times during data analysis using lists we come across a situation where we need to find out if a given element is present at least N Times in the given list. For example if 5 is present at least three times in the list or not. In this article we will see 2 approaches on how to achieve this.Counting OccurrencesIn the below approach we take the number and it's occurrences as an input. Then we e designer follow to keep the count of the occurrences. If the count value is greater than or equal to the required value then ... Read More

Advertisements