I struggled a lot to create a JSON object which should also contain foreign field values.So after Googling and trying a lot, I came up with this masterpiece code ðŸ™‚This code is very simple does not require any JSON serialization.…

# Category: python

## How to Shuffle (Randomize) QuerySet in Django

Suppose you want get a random item from a QuerySet, It should be random but non repeating.In many posts I saw they use my_list = MyModel.objects.order_by(“?”) but it will produce repeating items. 1st Step: get a QuerySet my_qset = MyModel.objects.all()…

## Python Program to Add two binary numbers using built function

Here we will see how to easily add two numbers in python3 using built-in functions. please run this program with python3. Steps: 1. Take input of the two binary numbers as string using the input function.2. convert them into integers…

## Ipython, an alternative Interactive Python interpreter [tutorial]

Ipython is an interactive python shell which can be used as a replacement for your default python interpreter. Install Ipython pip install Ipython Launch Ipython Just enter ipython in your terminal aman@vostro:~$ ipythonPython 3.5.2 (default, Nov 23 2017, 16:37:01) Type…

## 3 Common ways to Reverse a String in Python

One of the very common problems in any programming language is how to reverse a String. Let’s see a few ways to do this in python. 1. Using String Slicing well first of all the most easy way.. Here we…

## Python Program to Check if a number is FIbonacci

In Fibonacci Sequence, every previous two numbers gives the next number. the first 10 Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 35 In this python Program we will see how to test if a number given…

## Python Program to check if a number is Perfect Square

A number that can be expressed as the product of two equal integers is a Perfect Square number. for example: 25 can be expressed as 5 x 5 In the given python3 code we take a user input and take…

## Merge Sort Program in Python

We will look at the Merge Sort Algorithm which is used to sort an unsorted list. The input list is divided into two parts and they are solved recursively and then they are merged. Worst Case Time Complexity: O(n log…

## Python Program to Generate Fibonacci Series using Recursion

Fibonacci Series: A sequence of numbers in which each number is the sum of the previous two numbers. First 10 Fibonacci numbers: 0,1,1,2,3,5,8,13,21,34,… In the following python program we have used recursive function to find out the Fibonacci series up…

## Understand Python Dictionary (key-value pair / Hash Map)

This tutorial is about Python dictionary which is data-structure representing key-value pairs, you can also call it a HashMap. One of the very common use of hashmap is finding frequency of characters in a string Basically a dictionary is like…