Python Code Samples



Filters


Connect to mongo db using python and list of databases
kishore_kumar | 6 years, 1 month
import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017")
pymongo python mongodb
Matrix transpose using list comprehensions in python
harika | 6 years, 2 months
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
#Procedure1:--------
transposed = [[row[i] for row in a ] fo
List comprehensions in python basically reduce the loc. Check the difference between two procudures
python matrix list
Ramya
PYTHON: To download AWS ELB access log files from S3 bucket based on last modified time
Ramya | 5 years, 2 months
import boto3
import datetime
from datetime import datetime,timedelta,date
Before using this script, you need to set up AWS CLI first as below: ubuntu@ip-172-31-46-2:~$ aws
python boto3 s3
fetch all documents from mongo db collection using python
kishore_kumar | 6 years, 1 month
import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017")
pymongo python mongodb
Usage of Operator functions instead of lambda functions
harika | 6 years, 2 months
import functools
import operator
list = [1, 2, 3, 4, 5]
Both lines generates the same result
lambda operator python
How to get the master IP Address of EMR Cluster
Reshma | 5 years, 9 months
import os
import boto3
session = boto3.Session(profile_name='aws_profile_name')
python aws ipaddress
How to connect to PostgreSQL database and display list of tables in python
kishore_kumar | 6 years, 1 month
import psycopg2

conn = psycopg2.connect(host="localhost", database="mydb", user="kishore", passwo
python psycopg2 postgresql
json string to python dictionary using json module
kishore_kumar | 6 years, 5 months
import json

my_str = '{"1": 4, "4": 2, "5":3 }'
python json
sandeep
Python Script to create AWS beanstalk
sandeep | 6 years, 10 months
#!/usr/bin/python
  
import boto
python aws beanstalk
Ramya
Difference between normal def defined function and lambda function in Python
Ramya | 5 years, 9 months
li = [4,65,65,23,86,343,75,3,7,5,87,34,56,64,90] 
final_list = list(filter(lambda x: (x%2 == 0) , l
lambda python
Prev Next