-3

I have a list that looks like:

{
    'J2EE': 0.0202219636,
    'financial': 0.2439565346,
    'Guru': 0.0202219636,
    'AWS': 0.0202219636,
    'next generation': 0.12072663160000001,
    'Machine Learning': 0.2025762767,
    'technology': 0.066936981
}

How do I extract only the text parts and make my list look like:

['J2EE', 'financial', 'Guru', 'AWS', ...]

Should I use Regular expressions?

a_guest
  • 34,165
  • 12
  • 64
  • 118
The Doctor
  • 332
  • 2
  • 5
  • 16

3 Answers3

5

What you have there is a dictionary, not a list, and what you want are the keys:

your_dict = {'J2EE': 0.0202219636, 'financial': 0.2439565346, 'Guru': 0.0202219636, 'AWS': 0.0202219636, 'next generation': 0.12072663160000001, 'Machine Learning': 0.2025762767, 'technology': 0.066936981}
your_dict_keys = your_dict.keys()
yaizer
  • 326
  • 1
  • 5
1

I doubt it, but if you really want it in the form of {'J2EE','financial','Guru','AWS',....} use set(dict)

Flomp
  • 524
  • 4
  • 17
  • This `set` is quite unnecessary. Dictionary keys are already unique. Simpler to use `dict.keys()`. – Fejs Jul 07 '17 at 12:31
  • True, but OP specified the output to be a set. Although probably by mistake. – Flomp Jul 07 '17 at 12:33
1

As noticed by brittenb in his comment, the data structure in your example is in fact a type we call a dictionary in Python. See https://docs.python.org/3/tutorial/datastructures.html#dictionaries for further details.

Getting the list of keys of a dictionary is done by calling

list(dict.keys())

This is what calling it on your example would look like:

test = {'J2EE': 0.0202219636, 'financial': 0.2439565346, 'Guru': 0.0202219636, 'AWS': 0.0202219636, 'next generation': 0.12072663160000001, 'Machine Learning': 0.2025762767, 'technology': 0.066936981}
list(test.keys())
>>>['financial', 'next generation', 'Guru', 'technology', 'J2EE', 'Machine Learning', 'AWS']
BoboDarph
  • 2,751
  • 1
  • 10
  • 15