Lakshmi Srinivas has Published 315 Articles

How do I run two python loops concurrently?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 17-Jun-2020 12:22:33

610 Views

You will need to use a multiprocessing library. You will need to spawn a new process and provide the code to it as an argument. For example, from multiprocessing import Processdef loop_a():    for i in range(5):       print("a") def loop_b():    for i in range(5):   ... Read More

How to write inline if statement for print in Python?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 17-Jun-2020 12:05:59

6K+ Views

Python provides two ways to write inline if statements. These are:1. if condition: statement2. s1 if condition else s2Note that second type of if cannot be used without an else. Now you can use these inline in a print statement as well. For example, a = True if a: print("Hello")This ... Read More

What is the associativity of Python's ** operator?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 17-Jun-2020 11:55:12

192 Views

From the Python docs:Operators in the same box group left to right (except for comparisons), including tests, which all have the same precedence and chain from left to right — see section Comparisons — and exponentiation, which groups from right to left).So the ** operator(exponentiation) is right to left associative. ... Read More

How to put comments inside a Python dictionary?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 17-Jun-2020 11:46:03

325 Views

You can put comments like you normally would anywhere in a python script. But note that you can only put single line comments using #. Multiline comments act like strings and you cannot put just a string in between definition of a dict. For example, the following declaration is perfectly ... Read More

How to sort a Python dictionary by datatype?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 17-Jun-2020 10:24:04

128 Views

You can sort a list of dictionaries by values of the dictionary using the sorted function and passing it a lambda that tells which key to use for sorting. For example, A = [{'name':'john', 'age':45},      {'name':'andi', 'age':23},      {'name':'john', 'age':22},      {'name':'paul', 'age':35},      {'name':'john', ... Read More

How can I create a non-literal python tuple?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 17-Jun-2020 10:11:15

126 Views

You can first construct a list then change the single value you want to change, then finally convert that to a tuple if you want to create a non-literal python tuple. For example, def create_non_literal_tuple(a, b, c):    x = [1] * a    x[c] = b    return tuple(x) ... Read More

How to create and populate Java array of Hash tables?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 16-Jun-2020 09:52:15

472 Views

One way to create an array of hash tables is to create Hashtable objects and to assign these to a Hashtable array using curly braces:ExampleLive Demoimport java.util.Hashtable; public class HashTableOfArrays {    public static void main(String args[]) {       Hashtable ht1 = new Hashtable();       ... Read More

How to draw a circular gradient in HTML5?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 15-Jun-2020 11:43:34

166 Views

This method returns a CanvasGradient object that represents a radial gradient that paints along the cone given by the circles represented by the arguments. The first three arguments define a circle with coordinates (x1, y1) and radius r1 and the second a circle with coordinates (x2, y2) and radius r2.createRadialGradient(x0, ... Read More

Hide content depending on screen size with Bootstrap

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 12-Jun-2020 22:06:19

476 Views

Use the .hidden-* class in Bootstrap to hide content depending on screen size with BootstrapExampleLive Demo           Bootstrap Example                                 This is visible.       This is hidden.       Hidden on small screen       Hidden on medium screen    

Add plain text next to a form label within a form with Bootstrap

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 12-Jun-2020 21:43:27

369 Views

To add plain text to a form label within a form, use the .form-control-static in Bootstrap.You can try to run the following code to implement a .form-control-static class in BootstrapExampleLive Demo           Bootstrap Example                                                       Email:                            amit@demo.com                                

Previous 1 ... 7 8 9 10 11 ... 32 Next
Advertisements