Python: for a list of strings :Pulling the first 3-6 digit number in a string and a second 3-6 digit number in same string seperated by a space -
i have loaded directory python, has 135+ files in them, got data each file , put array. data has 22 lines of (x y) points, in general, appear 1 of:
{123.123 123.123} {123 123.123} {123.1 123.123} {12 123.123} i need keep (x y) points belong 1 file. trying use 2d array cant pull first number (x) , second number(y) due differences in number of digits. have been working on far long. guidance appreciated
assuming {123.123 123.123} of type str :
remove first , last char point[1:-1] , split(' ') on space.
convert resulted list of string values float float(f).
assign resulted 2 floats x, y.
point = '{123.123 123.123}' x, y = [float(f) f in point[1:-1].split (' ')] print('x:{}, y:{}'.format(x, y)) >>>x:123.123, y:123.123
Comments
Post a Comment