Friday, April 19, 2019

Python split list into sub-lists based on string value


I have a list that is randomly separated by a string value, now I want to make a sub-list at each of the random string that separates the whole list.


in other words as an example, the list below is separated by ':' at random intervals. So, at each occurrence of ':', I want to make a list of those elements.


mylist = [1, 'sistani', ':', 3, ':', 7, 9, 0, 'anita', ':', 20, 8, 4, ':', 12, 5, 10, ':', 56, ':', 6, 30, 56, 'usman', ':']
mysepstring = ':'
# Split list by value - python split list into sublists based on string value
def list_splitz(baseList, sepString):    
    group = []    
    for x in baseList:
        if x != sepString:
            group.append(x)
        elif group:
            yield group
            group = []
            
print(list(list_splitz(mylist, mysepstring)))



Alternative solution....

from itertools import groupby
resulting_list = [list(g) for k, g in groupby(mylist, lambda x: x != mysepstring) if k]



Hope this was useful.

Monday, April 1, 2019

How to Setup Geo-tagging on photos taken by Smart Phone Camera

Today, it is very common for people to use their smart phones to take pictures of locations they visited. However, very few of them know that they can actually tag the pictures with the latitude, longitude and altitude of the places.

In this post, I will show you how enable GPS on your smart phone so that the pictures you snap with the camera adds geo data (latitude, longitude and altitude) to the photos.

This feature is mostly disabled by default on most smart phones. There will be different ways to enable the feature on different phones, here I will use android device for my demonstration.

Android users follow these steps:

Step 1: Go to your phone "Settings".



Step 2: Under personal group of settings icons, select "Location" and turn it on.




Step 3: Now that you got your phone location sensor on, open you camera and select the option button. There you will find "GPS Location Info", turn it on if it is off.



Any picture you take with these settings above properly enabled, will link that picture with GPS coordinate of the location.