2

Let's say I have :

my_args = ["QA-65"]

as the desired result,

but in my function, I have:

            m = re.search("([a-zA-Z]+-\d+)",line)
            print 'printing m.group(1)'
            print m.group(1)
            m_args = m.group(1)
            print 'my_args '
            print m_args
            print type(m_args)

so that the type of "m_args" is string, i.e

How can I convert m_args to a list with just one element with the same content as the string?

2 Answers 2

10

Perhaps this:

my_args = [my_args]
Sign up to request clarification or add additional context in comments.

2 Comments

>>> txt = "hello" >>> txt_list = list(txt) >>> type(txt_list) <type 'list'> >>> type(txt) <type 'str'> >>>
As str is iterable, list(txt) will return a list containing an element for each element in txt.
3

You do it this way:

m_args = [m_args, ]

1 Comment

Note that the comma is optional for creating lists [a,] but is required for tuples (a,)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.