C++, LeetCode

Unordered Map

According to the documentation, the average searching complexity is O(1), by looking more into unordered_map.find()

It is redirected to lower_bound, passing in the original key value

For _Traits, it’s the template operators (open hashing I supposed), for the iterator defined within the _Traits class

   

LeetCode

1. Two Sum

 

 

LeetCode

7. Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Note: The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

Python

Fetch filename into list with relative path

For fetch.py, the input files are in Inputdata/input1.xlsx Inputdata/input2.xlsx   Import os module

  Get current absolute path, for example, C:/Users/Edward/Desktop

  Get current absolute path + Inputdata/, for example, C:/Users/Edward/Desktop/Inputdata/

  Store target path into variable and print all the files inside

  Code required to store all the file name into filelist

 …

Continue Reading

Python

Date & timedelta calculation

It is time-consuming to define the edge case for date calculation For example: 2017-06-27, it’s easy to subtract days < 27, minus directly from the day attribute, however, it’s hard if we want to know the date like 30 days before.

  Import date object & timedelta

Timedelta syntax

  To create the date object, pass in year,…

Continue Reading

C++, Python

Comparison of popular Excel libraries

Simple benchmark of popular library

  Since the data size accessing is relatively large, approx. >50 excel files, >10 sheets in each file and >1k rows in each sheet, performance become very important. OpenPyXL, LibXL can provide both write & read functions xlrd for reading only xlwt, PyExcelerate for writing only   OpenPyXL = Free with relatively slow performance xlwt…

Continue Reading

MS Office, Python

Manage Excel using OpenPyXL

It is simply to read Excel workbook using xlrd, however, saving files as .xlsx is not supported by xlwt   OpenPyXL version 2.4.8 (2017-05-30) Import the module

  To get worksheet

  Get the value of cell

  Get the maximum count of rows & cols

  Set style to the cell

 

Python

Read date in xlrd

Reading date from xlrd using cell_values return float, i.e.

  To extract the correct date, datamode and xldate_as_tuple will be used Example: Let cell_values(2,2) from sheet number 0 be the date targeted   Get the required variables

  Pass them into xldate_as_tuple, we can obtain year, month, day, hour, minute, second as string

 

MS Office, Python

Read excel using xlrd

Targeted excel file: C:/User/Edward/Desktop/data.xlsx

 

Python

Basic setup of Python 3.6

Official link of Python 3.6 installer from Windows 1. Pick Custom installation Change installation path from

TO

  2. Append it to the environment variables Path, pip has been integrated into Python since 3.4, it should also be added into the variable Edit New > C:\Python36-32 New > C:\Python36-32\Scripts   3. Open command prompt, use pip to install xlrd…

Continue Reading