Skip to content

Instantly share code, notes, and snippets.

View Dhrumilcse's full-sized avatar

Dhrumil Patel Dhrumilcse

View GitHub Profile
@Dhrumilcse
Dhrumilcse / dictionary_4-2.py
Created November 18, 2018 08:21
Dictionary Part 4.2
#Import library
import json
# This is a python library for 'Text Processing Serveices', as the offcial site suggests.
import difflib
from difflib import get_close_matches
#Let's load the same data again
data = json.load(open("dictionary.json"))
#Before you dive in, the basic template of this function is as follows
@Dhrumilcse
Dhrumilcse / dictionary_5.py
Created November 18, 2018 08:36
Dictionary Part 5
#Check for non existing words
#1st elif: To make sure the program return the definition of words that start with a capital letter (e.g. Delhi, Texas)
#2nd elif: To make sure the program return the definition of acronyms (e.g. USA, NATO)
if word in data:
return data[word]
elif word.title() in data:
return data[word.title()]
elif word.upper() in data:
return data[word.upper()]
#3rd elif: To find a similar word
@Dhrumilcse
Dhrumilcse / dictionary_6.py
Last active November 18, 2018 08:52
Dictionary Part 6
elif len(get_close_matches(word, data.keys())) > 0:
action = input("Did you mean %s instead? [y or n]: " % get_close_matches(word, data.keys())[0])
#-- If the answers is yes, retrive definition of suggested word
if (action == "y"):
return data[get_close_matches(word, data.keys())[0]]
elif (action == "n"):
return ("The word doesn't exist, yet.")
else:
return ("We don't understand your entry. Apologies.")
@Dhrumilcse
Dhrumilcse / dictionary_7.py
Created November 18, 2018 08:59
Dictionary Part 7
#Retrive the definition using function and print the result
output = retrive_definition(word_user)
#If a word has more than one definition, print them recursively
if type(output) == list:
for item in output:
print("-",item)
#For words having single definition
else:
print("-",output)
@Dhrumilcse
Dhrumilcse / geo1.py
Last active December 11, 2018 14:26
Folium
#Import Library
import folium
#Create base map
map = folium.Map(location=[37.296933,-121.9574983], zoom_start = 8)
#Save the map
map.save("map1.html")
#Import Library
import folium
#Create base map
map = folium.Map(location=[37.296933,-121.9574983], zoom_start = 8, tiles = "Mapbox bright")
#Add Marker
folium.Marker(location=[37.4074687,-122.086669], popup = "Google HQ", icon=folium.Icon(color = 'gray')).add_to(map)
#Save the map
#Import Library
import folium
#Create base map
map = folium.Map(location=[37.296933,-121.9574983], zoom_start = 8, tiles = "Mapbox bright")
#Multiple Markers
for coordinates in [[37.4074687,-122.086669],[37.8199286,-122.4804438]]:
folium.Marker(location=coordinates, icon=folium.Icon(color = 'green')).add_to(map)
#Import Library
import folium
import pandas as pd
#Load Data
data = pd.read_csv("Volcanoes_USA.txt")
lat = data['LAT']
lon = data['LON']
elevation = data['ELEV']
#Import Library
import folium
import pandas as pd
#Load Data
data = pd.read_csv("Volcanoes_USA.txt")
lat = data['LAT']
lon = data['LON']
elevation = data['ELEV']
@Dhrumilcse
Dhrumilcse / geo6.py
Last active December 11, 2018 14:38
#Import Library
import folium
from folium.plugins import MarkerCluster
import pandas as pd
#Load Data
data = pd.read_csv("Volcanoes_USA.txt")
lat = data['LAT']
lon = data['LON']
elevation = data['ELEV']