Lakshmi Srinivas has Published 315 Articles

How to view a list of all Python operators via the interpreter?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 05-Mar-2020 07:29:37

209 Views

The help method in the interpreter is very useful for such operations. It provides a rich set of special inputs that you can give to it to get information about the different aspects of the language. Forgetting operator lists, here are some of the commands you can use:All operators>>> help('SPECIALMETHODS')Basic ... Read More

How to find the average of non-zero values in a Python dictionary?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 05-Mar-2020 07:21:53

2K+ Views

You can do this by iterating over the dictionary and filtering out zero values first. Then take the sum of the filtered values. Finally, divide by the number of these filtered values. examplemy_dict = {"foo": 100, "bar": 0, "baz": 200} filtered_vals = [v for _, v in my_dict.items() if v != ... Read More

How to convert JSON data into a Python tuple?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 05-Mar-2020 07:07:37

4K+ Views

You can first convert the json to a dict using json.loads and then convert it to a python tuple using dict.items(). You can parse JSON files using the json module in Python. This module parses the json and puts it in a dict. You can then get the values from ... Read More

How do we compare two tuples in Python?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 05-Mar-2020 05:57:34

6K+ Views

Tuples are compared position by position: the first item of the first tuple is compared to the first item of the second tuple; if they are not equal, this is the result of the comparison, else the second item is considered, then the third and so on. example>>> a = (1, ... Read More

How do we grep a particular keyword from Python tuple?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 05-Mar-2020 05:54:11

174 Views

If you have a tuple of strings and you want to search for a particular string, You can use the in operator. exampletpl = ("Hello", "world", "Foo", "bar") print("world" in tpl)OutputThis will give the output −TrueExampleIf you want to check if there is a substring present. You can loop over the ... Read More

How do I assign a dictionary value to a variable in Python?

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 05-Mar-2020 05:36:33

13K+ Views

You can assign a dictionary value to a variable in Python using the access operator []. examplemy_dict = {    'foo': 42,    'bar': 12.5 } new_var = my_dict['foo'] print(new_var)OutputThis will give the output −42exampleThis syntax can also be used to reassign the value associated with this key. my_dict = { ... Read More

What are CSS pseudo-classes

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 04-Mar-2020 12:38:10

99 Views

CSS pseudo-classes are used to add special effects to some selectors. You do not need to use JavaScript or any other script to use those effects.The most commonly used pseudo-classes are −ValueDescription:linkUse this class to add special style to an unvisited link.:visitedUse this class to add special style to a ... Read More

Usage of margin-right property with CSS

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 04-Mar-2020 12:18:39

70 Views

The margin-right specifies the right margin of an element. It can have a value in length, % or auto. You can try to run the following code to set the right margin −Example                            This is a paragraph ... Read More

CSS max-height property

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 04-Mar-2020 12:13:27

113 Views

The max-height property is used to set a maximum height that a box can be. The value of the max-height property can be a number, a length, or a percentage.Example                            This paragraph is 400px wide and max ... Read More

CSS height property

Lakshmi Srinivas

Lakshmi Srinivas

Updated on 04-Mar-2020 12:09:06

115 Views

The height property is used to set the height of a box. They can take values of a length, a percentage, or the keyword auto. ExampleYou can try to run the following code to set height −                             This paragraph is 200pixels wide and 50 pixels high          

Advertisements