-2

I have a string that consists of a list which made of different product code.

"['B00GHX7H0A', 'B00FRERO7G', 'B00R68QXCS', 'B000Z65AZE', 'B07GFHJRMX', 'B074KGBGL7', 'B00R68QXJG', 'B00025WYZC', 'B07H3W9BM5', 'B00KOBT82G', 'B072N2M1P6', 'B071G8FG2N', 'B00FASVFI8', 'B00GHXE4N8', 'B00EPG2QJI', 'B01MQ4MEFE', 'B01M8ML0SY', 'B074KHCPLH', 'B004XQWY4W', 'B00FASV6UU', 'B01M31HJBJ', 'B00KC8TU7O', 'B00B9TU5T2', 'B00K75EZ04', 'B000Q2Y0FI', 'B00FEGOCCM', 'B00EPFXFBW', 'B00H6SQY3Q', 'B00HZAOWUC', 'B07GFJF1DN', 'B001WBS68E', 'B074KJZCPH']"

How can I extract each product code out of this string?

Celius Stingher
  • 11,967
  • 4
  • 12
  • 37

1 Answers1

0

There is nother option than to replace the unnecessary characters and then splitting it by the commas:

myList = "['123','231','312','123']"
myList = myList.replace("[","").replace("]","").replace("'", "").split(",")
print(myList)
# output: ["123","231","312","123"]

But with this you would get problems if the items inside the list could potentially contain commas.

Sofian
  • 577
  • 3
  • 10