Take and edit values from map variable

i have map variable(below), and i need to do actions on names, to remove ‘_data-green’ and ‘_data_blue’ and then remove duplicates to have for example only list variable with items: “api-1”, “api-2”

locals {
  apps = {
    "api-1_data-green" = {
         is_enabled   = false
     },
    "api-1_data-blue" = {
         is_enabled   = true
    },
    "api-2_data-green" = {
         is_enabled   = false
    },
    "api-2_data-blue" = {
         is_enabled   = true
    },
 }

I think below should help you get that.

answer = toset([
    for i in keys(local.apps) : split("_", i)[0]
])