List of Indian States in Python Format

So I was working on a project where I needed list of Indian States in Python format. I looked around on the web but the data was not available in required format. So I decided to create the list of Indian states in different formats which can be used directly in Python-Django project.

You can simply copy paste the data in any of the below format.


Simple List of Indian states:

Andhra Pradesh
Arunachal Pradesh 
Assam
Bihar
Chhattisgarh
Goa
Gujarat
Haryana
Himachal Pradesh
Jammu and Kashmir 
Jharkhand
Karnataka
Kerala
Madhya Pradesh
Maharashtra
Manipur
Meghalaya
Mizoram
Nagaland
Odisha
Punjab
Rajasthan
Sikkim
Tamil Nadu
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
Andaman and Nicobar Islands
Chandigarh
Dadra and Nagar Haveli
Daman and Diu
Lakshadweep
National Capital Territory of Delhi
Puducherry


Comma Separated List (CSV) of Indian states:

Andhra Pradesh,Arunachal Pradesh ,Assam,Bihar,Chhattisgarh,Goa,Gujarat,Haryana,Himachal Pradesh,Jammu and Kashmir,Jharkhand,Karnataka,Kerala,Madhya Pradesh,Maharashtra,Manipur,Meghalaya,Mizoram,Nagaland,Odisha,Punjab,Rajasthan,Sikkim,Tamil Nadu,Telangana,Tripura,Uttar Pradesh,Uttarakhand,West Bengal,Andaman and Nicobar Islands,Chandigarh,Dadra and Nagar Haveli,Daman and Diu,Lakshadweep,National Capital Territory of Delhi,Puducherry


Python List of Indian states:

["Andhra Pradesh","Arunachal Pradesh ","Assam","Bihar","Chhattisgarh","Goa","Gujarat","Haryana","Himachal Pradesh","Jammu and Kashmir","Jharkhand","Karnataka","Kerala","Madhya Pradesh","Maharashtra","Manipur","Meghalaya","Mizoram","Nagaland","Odisha","Punjab","Rajasthan","Sikkim","Tamil Nadu","Telangana","Tripura","Uttar Pradesh","Uttarakhand","West Bengal","Andaman and Nicobar Islands","Chandigarh","Dadra and Nagar Haveli","Daman and Diu","Lakshadweep","National Capital Territory of Delhi","Puducherry"]


Python Set of Indian states:

("Andhra Pradesh","Arunachal Pradesh ","Assam","Bihar","Chhattisgarh","Goa","Gujarat","Haryana","Himachal Pradesh","Jammu and Kashmir","Jharkhand","Karnataka","Kerala","Madhya Pradesh","Maharashtra","Manipur","Meghalaya","Mizoram","Nagaland","Odisha","Punjab","Rajasthan","Sikkim","Tamil Nadu","Telangana","Tripura","Uttar Pradesh","Uttarakhand","West Bengal","Andaman and Nicobar Islands","Chandigarh","Dadra and Nagar Haveli","Daman and Diu","Lakshadweep","National Capital Territory of Delhi","Puducherry")


Indian states Dropdown choices for Django:

state_choices = (("Andhra Pradesh","Andhra Pradesh"),("Arunachal Pradesh ","Arunachal Pradesh "),("Assam","Assam"),("Bihar","Bihar"),("Chhattisgarh","Chhattisgarh"),("Goa","Goa"),("Gujarat","Gujarat"),("Haryana","Haryana"),("Himachal Pradesh","Himachal Pradesh"),("Jammu and Kashmir ","Jammu and Kashmir "),("Jharkhand","Jharkhand"),("Karnataka","Karnataka"),("Kerala","Kerala"),("Madhya Pradesh","Madhya Pradesh"),("Maharashtra","Maharashtra"),("Manipur","Manipur"),("Meghalaya","Meghalaya"),("Mizoram","Mizoram"),("Nagaland","Nagaland"),("Odisha","Odisha"),("Punjab","Punjab"),("Rajasthan","Rajasthan"),("Sikkim","Sikkim"),("Tamil Nadu","Tamil Nadu"),("Telangana","Telangana"),("Tripura","Tripura"),("Uttar Pradesh","Uttar Pradesh"),("Uttarakhand","Uttarakhand"),("West Bengal","West Bengal"),("Andaman and Nicobar Islands","Andaman and Nicobar Islands"),("Chandigarh","Chandigarh"),("Dadra and Nagar Haveli","Dadra and Nagar Haveli"),("Daman and Diu","Daman and Diu"),("Lakshadweep","Lakshadweep"),("National Capital Territory of Delhi","National Capital Territory of Delhi"),("Puducherry","Puducherry"))

state = models.CharField(choices=state_choices,max_length=255, null=True, blank=True)


HTML select code for Indian states:

<option value="Andhra Pradesh">Andhra Pradesh</option></option>
<option value="Arunachal Pradesh ">Arunachal Pradesh </option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir ">Jammu and Kashmir </option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Manipur">Manipur</option>
<option value="Meghalaya">Meghalaya</option>
<option value="Mizoram">Mizoram</option>
<option value="Nagaland">Nagaland</option>
<option value="Odisha">Odisha</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Telangana">Telangana</option>
<option value="Tripura">Tripura</option>
<option value="Uttar Pradesh">Uttar Pradesh</option>
<option value="Uttarakhand">Uttarakhand</option>
<option value="West Bengal">West Bengal</option>
<option value="Andaman and Nicobar Islands">Andaman and Nicobar Islands</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Dadra and Nagar Haveli">Dadra and Nagar Haveli</option>
<option value="Daman and Diu">Daman and Diu</option>
<option value="Lakshadweep">Lakshadweep</option>
<option value="National Capital Territory of Delhi">National Capital Territory of Delhi</option>
<option value="Puducherry">Puducherry
 

If this article helped you in your project, please share it on facebook.

Hosting Django App for free.

List of USA states in Different Formats.



Python Frequently Asked Question 1: What can I do in Python?


Many beginners ask this questions. What can I do in Python? 

Here is a quick and short answer for this question. You can work on below things in Python.

1. Web Development
2. Automation 
3. Data Analysis and Machine Learning
4. IOT 
5. Desktop Application
6. Web scraping


For more details, Refer below articles:

https://medium.freecodecamp.org/what-can-you-do-with-python-the-3-main-applications-518db9a68a78

https://intersog.com/blog/some-cool-things-you-can-do-with-python/


Python Script 13: Generating ascii code from Image

Adding a new script to the Python Script series. In this article we will see how to convert the colored image to ASCII art.


Dependecies:

You will need to install pillow python package. It is recommended that you create a virtual environment using python3 if not created already. 

Once virtual environment is activated use command pip install pillow to install the package.


Steps:

We are performing below actions to generate the ascii art from image.

- Get an image path as command line argument.
- Open the image from provided path.
- Calculate the aspect ratio.
- Resize the image. Here we are taking new width as 120 pixels. Adjusting the new height as per aspect ratio.
- Convert the image into greyscale format.
- Get all the pixels of image. Replace pixles with intentsity in a defined range with a character from list.
- Print image and save to text file.


Code:

import sys
from PIL import Image


# pass the image as command line argument
image_path = sys.argv[1]
img = Image.open(image_path)

# resize the image
width, height = img.size
aspect_ratio = height/width
new_width = 120
new_height = aspect_ratio * new_width * 0.55
img = img.resize((new_width, int(new_height)))
# new size of image
# print(img.size)

# convert image to greyscale format
img = img.convert('L')

pixels = img.getdata()

# replace each pixel with a character from array
chars = ["B","S","#","&","@","$","%","*","!",":","."]
new_pixels = [chars[pixel//25] for pixel in pixels]
new_pixels = ''.join(new_pixels)

# split string of chars into multiple strings of length equal to new width and create a list
new_pixels_count = len(new_pixels)
ascii_image = [new_pixels[index:index + new_width] for index in range(0, new_pixels_count, new_width)]
ascii_image = "\n".join(ascii_image)
print(ascii_image)

# write to a text file.
with open("ascii_image.txt", "w") as f:
    f.write(ascii_image)


If you are getting an elongated image in terminal, you can adjust the height accordingly. I am generating new_height using formula new_height = aspect_ratio * new_width * 0.55.

Statement list(img.getdata()) returns the list intensity of all pixels. Value of intensity will be between 0 to 255. Lower the value, darker the color. That is why we have characters in char list arranged from higher intensity to lower intensity. 

Value of pixel//25 , where 25 is the intensity range for one character, can be between 0 to 11 i.e why there are 11 characters in chars list. You may keep more characters in list, lets say 16 characters and then keep the range size as 17. 

Line new_pixels = [chars[pixel//25] for pixel in pixels] replaces the pixels with intensity from 0 to 25 with first character from chars list and 26 to 50 with seconds character from chars list and so on.

In the last lines we break the string into a matrix and print it.


How to use script:

To run the script use below command.

python3 script_name path_to_image
python3 image_to_ascii.py /home/Downloads/image.png


Code is available on Github.


References:

1. https://stackoverflow.com/questions/52307290/what-is-the-difference-between-images-in-p-and-l-mode-in-pil
2. https://pillow.readthedocs.io/









SUBSCRIBE
Please subscribe to get the latest articles in your mailbox.


Recent Posts:






© pythoncircle.com 2018-2019
Contact Us: code108labs [at] gmail.com
Address: 3747 Smithfield Avenue, Houston, Texas