Chandu yadav has Published 1163 Articles

Java program to print Pascal's triangle

Chandu yadav

Chandu yadav

Updated on 13-Mar-2020 07:24:47

8K+ Views

Pascal's triangle is one of the classic example taught to engineering students. It has many interpretations. One of the famous one is its use with binomial equations.All values outside the triangle are considered zero (0). The first row is 0 1 0 whereas only 1 acquire a space in Pascal’s ... Read More

Java program to implement linear search

Chandu yadav

Chandu yadav

Updated on 13-Mar-2020 05:51:22

5K+ Views

Linear search is a very simple search algorithm. In this type of search, a sequential search is done for all items one by one. Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data ... Read More

How to identify and print all the perfect numbers in some closed interval [ 2, n ] using Python?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 10:55:58

1K+ Views

A perfect number is a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3.You can find perfect numbers within a given range by testing each number for the given condition in the ... Read More

How to Find ASCII Value of Character using Python?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 10:39:47

134 Views

The ord function in python gives the ordinal value of a character(ASCII). You can use this function to find the ascii codes as followsExamples = "Hello" for c in s:    print(ord(c))OutputThis will give the output72 101 108 108 111

How to check for redundant combinations in a Python dictionary?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 07:09:45

97 Views

There will never be redundant combinations in a Python dictionary because it is a hashmap. This means that each key will have exactly one associated value with it. This value can be a list or another dict though. So if you try to add a duplicate key likeExamplea = {'foo': ... Read More

How to truncate Key Length in Python Dictionary?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 07:00:13

434 Views

You can use a list comprehension to truncate keys in a python dict. Iterate over the keys in the dict, and create a new dict with the truncated keys. exampledef truncate_keys(a, length):    return dict((k[:length], v) for k, v in a.items()) a = {'foo': 125, 'bar': 'hello'} b = truncate_keys(a, 2) ... Read More

How to convert an object x to an expression string in Python?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 06:40:47

567 Views

The str function converts an object in python to a string representation. There is another function called repr() in python that converts object to an expression string. __repr__'s goal is to be unambigous while __str__'s is to be readable. __repr__ is used to compute the “official” string representation of an ... Read More

How can I use Multiple-tuple in Python?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 06:26:10

902 Views

A multiple tuple is a tuple of tuples. example((0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), (12, 13, 14))You can iterate over a multiple tuple using the python destructuring syntax in the following wayx = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), ... Read More

How can I create a Python tuple of Unicode strings?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 06:06:15

145 Views

You can create a tuple of unicode strings in python using the u'' syntax when defining this tuple. examplea = [(u'亀', ), (u'犬', )] print(a)OutputThis will give the output[('亀', ), ('犬', )]Note that you have to provide the u if you want to say that this is a unicode string. Else ... Read More

What are Python coding standards/best practices?

Chandu yadav

Chandu yadav

Updated on 05-Mar-2020 05:03:45

502 Views

You can use the PEP8 guide as a holy grail. Almost all python world uses this guide to write clean understandable and standard python code. This is available as an extension as a linter for all modern text editors. You can check it out at  http://www.python.org/dev/peps/pep-0008/Properly Structure your folders. All ... Read More

Advertisements