-4

This is the input and output I am looking for given the user input

I want to do this using a function. I am assuming you will have to iterate through each set of points to convert them to integers, then back to a list?

1 Answers1

0

Partial answer:

import re

a = '3,4 5,6 7,8 12,8 3,456'

Now you could use:

raw_coords = re.findall(r'[0-9]+,[0-9]+', a)

But then you'd have to use more regex to extract x and y from each "x,y" string

A more straightforward way would be to separately extract the x values and y values from your initial list: look up "lookbehind assertions" and "lookahead assertions".

For example:

xlist = re.findall(r'[0-9]+(?=,)', a)

(explanation: this finds all maximal strings of digits that are placed just before a ',')

For now, I'll let you do some research and try to complete the process.

Swifty
  • 2,630
  • 2
  • 3
  • 21