Python Code Samples



Filters


Matrix transpose using list comprehensions in python
harika | 5 years, 9 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
Connect to mongo db using python and list of databases
kishore_kumar | 5 years, 8 months
import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017")
pymongo python mongodb
Ramya
PYTHON: To download AWS ELB access log files from S3 bucket based on last modified time
Ramya | 4 years, 9 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
Ramya
PYTHON: AWS IAM password reset
Ramya | 4 years, 8 months
import boto3
client = boto3.client('iam')
UserName=input("Enter UserName:")
boto3 python
Usage of Operator functions instead of lambda functions
harika | 5 years, 9 months
import functools
import operator
list = [1, 2, 3, 4, 5]
Both lines generates the same result
lambda operator python
fetch all documents from mongo db collection using python
kishore_kumar | 5 years, 8 months
import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017")
pymongo python mongodb
Get current environment variables in python
kishore_kumar | 6 years, 4 months
import os
env = os.environ

python python-os
sandeep
Python Script to create AWS beanstalk
sandeep | 6 years, 5 months
#!/usr/bin/python
  
import boto
python aws beanstalk
json string to python dictionary using json module
kishore_kumar | 6 years
import json

my_str = '{"1": 4, "4": 2, "5":3 }'
python json
How to connect to PostgreSQL database and display list of tables in python
kishore_kumar | 5 years, 8 months
import psycopg2

conn = psycopg2.connect(host="localhost", database="mydb", user="kishore", passwo
python psycopg2 postgresql
Prev Next