Malhar Lathkar has Published 86 Articles

How do I sort a list of dictionaries by values of the dictionary in Python?

Malhar Lathkar

Malhar Lathkar

Updated on 31-Jan-2023 18:05:35

In this article, we will show how to sort a list of dictionaries by the values of the dictionary in Python. Sorting has always been a useful technique in everyday programming. Python's dictionary is often used in a wide range of applications, from competitive to developer-oriented (example-handling JSON data). It ... Read More

How to replace backward "" slash from a string

Malhar Lathkar

Malhar Lathkar

Updated on 23-Jun-2020 14:44:01

In Python it does give the desired result>>> var  = "aaa\bbb\ccc and ddd\eee" >>> var.split('\') ['aaa', 'bbb', 'ccc and ddd', 'eee']

How to replace Digits into String using Java?

Malhar Lathkar

Malhar Lathkar

Updated on 20-Jun-2020 13:19:39

For this purpose, we create an object of HashMap class which is defined in java.util packageMap map = new HashMap();This hashmap object associates each digit with its corresponding word representationmap.put("0", "zero");Initialize an empty string object.String newstr="";Next, run a for loop over the length of given string and extract each character by ... Read More

How i can replace number with string using Python?

Malhar Lathkar

Malhar Lathkar

Updated on 20-Jun-2020 09:05:51

For this purpose let us use a dictionary object having digit as key and its word representation as value −dct={'0':'zero', '1':'one', '2':'two', '3':'three', '4':'four',      '5':'five', '6':'six', '7':'seven', '8':'eight', '9':'nine'Initializa a new string object newstr=''Using a for loop traverse each character  ch from input string at check if it is ... Read More

Python3 - Why loop doesn't work?

Malhar Lathkar

Malhar Lathkar

Updated on 20-Jun-2020 07:39:18

It does work. As you have used sleep() method inside the loop, no activity takes place for (0.9*36) seconds. It is not asking for input. After the end of loop, the window will show text field with the given string inside it.

How to indent an if...else statement in Python?

Malhar Lathkar

Malhar Lathkar

Updated on 18-Jun-2020 13:04:11

One of the characteristic features of Python is use of uniform indent to denote a block of statements. A block is initiated by − symbol As soon as − symbol is typed and enter pressed, any Python aware editor will take cursor to next line with increased indent. All lines ... Read More

Can we use pass statement in a Python if clause?

Malhar Lathkar

Malhar Lathkar

Updated on 18-Jun-2020 13:01:38

In Python, pass keyword is a dummy statement. It is used where a statement is necessary to fulfill syntax requirement but the actual implementation of processing logic is yet to be finalized. It can be used in if as well as else blockif expr==True:    pass else:    pass

What does colon ':' operator do in Python?

Malhar Lathkar

Malhar Lathkar

Updated on 18-Jun-2020 12:59:27

The : symbol is used for more than one purpose in PythonAs slice operator with sequence −The − operator slices a part from a sequence object such as list, tuple or string. It takes two arguments. First is the index of start of slice and second is index of end ... Read More

What is tilde (~) operator in Python?

Malhar Lathkar

Malhar Lathkar

Updated on 18-Jun-2020 08:35:21

The bitwise operator ~ (pronounced as tilde) is a complement operator. It takes one bit operand and returns its complement. If the operand is 1, it returns 0, and if it is 0, it returns 1For example if a=60 (0011 1100 in binary) its complement is -61 (-0011 1101) stored ... Read More

How can I iterate through two lists in parallel in Python?

Malhar Lathkar

Malhar Lathkar

Updated on 16-Jun-2020 11:23:44

Assuming that two lists may be of unequal length, parallel traversal over common indices can be done using for loop over over range of minimum length>>> L1 ['a', 'b', 'c', 'd'] >>> L2 [4, 5, 6] >>> l=len(L1) if len(L1)>> l 3 >>> for i in range(l):     print ... Read More

1 2 3 4 5 ... 9 Next
Advertisements