Tuesday, May 10, 2016

Memory management Python

Memory management in Python involves a private heap containing all Python objects and data structures.
The management of this private heap is ensured internally by the Python memory manager.
 is important to understand that the management of the Python heap is performed by the interpreter itself and that the user has no control over it.

Sunday, December 13, 2015

Printing alternate lines using python

for i, line in enumerate(file('myfile.txt')):

   if i % 5 in (0, 1):
       print line

f = open('filename.txt', 'r')
for index, line in enumerate(f.readlines()):
    if index%5 <= 1:

Regular expressions



 Matchign an email:

 Matching a phone numeber:
(123) 456-7890
123 456 7890
+91 (123) 456-7890

 IP address

Friday, December 11, 2015

print specific lines from files

searchquery = 'am'

with open('Test.txt') as f1:
    with open('Output.txt', 'a') as f2:
        lines = f1.readlines()
        for i, line in enumerate(lines):
            if line.startswith(searchquery):
                f2.write(lines[i + 1])
                f2.write(lines[i + 2]

Wednesday, October 28, 2015

generate permutations of [1,2,3]

import itertools
print list(itertools.permutations([1,2,3]))

compress test using zlib in python

import zlib
s = 'hello world!hello world!hello world!hello world!'
t = zlib.compress(s)
print t
print zlib.decompress(t)

Convert a list to tuple

#Write a program to generate and print another tuple2 ==0 
#whose values are even numbers in the given tuple (1,2,3,4,5,6,7,8,9,10).

for i in tp:
    if i%2==0:

print tp2