i think this should be very easy , but i really don’t know how to write it in a better way, if you know please tell me
#there are some points in text files and was read into a list
s = ['3,4','4,5','6,5','7,8']
#break s element to (x,y) form every element should convert to number type
points = []
for pStr in s:
ss = pStr.split(',')
points.append([int(p) for p in ss])
print(points) #[[3, 4], [4, 5], [6, 5], [7, 8]]
better write it in one line please
If using Python 2.x you can do the following:
If using Python 3.x you’ll need to pass the result of map() to list(), as it returns an iterator:
In action: