Created
April 12, 2018 14:45
-
-
Save LuanComputacao/b4b343c749efd1aac9d720e2c2445920 to your computer and use it in GitHub Desktop.
Captura uma string e retorna o dicionario de coordenadas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
def pegar_pontos_cartesianos(pontos_str): | |
"""Captura uma string e retorna o dicionario de coordenadas | |
Ex: | |
In :: pontos = pegar_pontos_cartesianos('P(0,2,3);Y(0.6,3.5,3.9);J(2,5,103)') | |
In :: print(pontos) | |
Out:: {'Y': [0.6, 3.5, 3.9], 'P': [0.0, 2.0, 3.0], 'J': [2.0, 5.0, 103.0]} | |
:param pontos_str: Representação de pontos cartesianos | |
:type pontos_str: str | |
:return: Dicionário de pontos cartezianos | |
:rtype: dict | |
""" | |
import re | |
pontos_dict = {} | |
pontos_str_vec = pontos_str.split(';') | |
for ponto_str in pontos_str_vec: | |
ponto_re = re.search('(.*)\((.*)\)', ponto_str) | |
ponto_dict = {ponto_re.group(1): [float(i) for i in ponto_re.group(2).split(',')]} | |
pontos_dict.update(ponto_dict) | |
return pontos_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment