Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4342234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:35:28+00:00 2026-05-21T11:35:28+00:00

When I type the following into the interpreter I get the desired output behavior:

  • 0

When I type the following into the interpreter I get the desired output behavior:

>>> x = (7, 2, 1, 1, 6, 2, 1, 2, 1, 2, 2, 6)
>>> y = list(x)
>>> y
[7, 2, 1, 1, 6, 2, 1, 2, 1, 2, 2, 6]

Above, I simply converted a tuple to a list. However, when I run the following code I get an answer that I don’t understand.

pwm = input("enter PWM: ")
npwm = pwm.replace('),(', ', ')
y = list(npwm)
print(y)

Output:

['(', '7', ',', ' ', '2', ',', ' ', '1', ',', ' ', '1', ',', ' ', '6', ',', ' ', '2', ',', ' ', '1', ',', ' ', '2', ',', ' ', '1', ',', ' ', '2', ',', ' ', '2', ',', ' ', '6', ')']

Can anyone explain to me what is happening? Why does the above code not product the desired output of:

[7, 2, 1, 1, 6, 2, 1, 2, 1, 2, 2, 6]

EDIT: Wow, I can’t thank everyone enough for the help! I greatly appreciate everyone’s patients and willingness to help with my beginner questions. Thank you very much. Below is the solution that I got to worked:

pwm = (7, 2, 1, 1),(6, 2, 1, 2),(1, 2, 2, 6)  
npwm = pwm.replace('),(',', ').strip('(').strip(')')  
y = list(ast.literal_eval(npwm))  
print(y)  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:35:28+00:00Added an answer on May 21, 2026 at 11:35 am

    When you call list on a string, it generates a list in which each character is an item in the list. So for example:

    >>> list("hey, you")
    ['h', 'e', 'y', ',', ' ', 'y', 'o', 'u']
    

    Since the data returned from input in this case is a string, calling list on it generates a list of characters.

    For the sake of demonstration, here’s a basic way to convert the string '(1, 2, 3)' into the list [1, 2, 3]:

    >>> pwm = raw_input("enter PWM: ")
    enter PWM: (1, 2, 3)
    >>> pwm
    '(1, 2, 3)'
    >>> npwm = pwm.strip('(').strip(')')
    >>> npwm
    '1, 2, 3'
    >>> npwm = npwm.split(',')
    >>> npwm
    ['1', ' 2', ' 3']
    >>> y = [int(x) for x in npwm]
    >>> y
    [1, 2, 3]
    

    Some people have suggested using eval on the string returned by input. Although that would do what you want, it’s a very bad habit to get into, because python will then evaluate whatever expression the (possibly malicious) user decides to enter.

    Also, as Sven Marnach correctly pointed out, input does what you expect in python 2.x. Fortunately that’s been corrected in 3.0, which you must be using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add the following MIME type to a site run by
I run the following code from a python interpreter, and expect the insert statement
Using a redirect statement in my htaccess file, people who type the following into
I get following type of warnings on my Drupal Site which usually disappear when
I when I type the following command into cygwin: bin/nutch index crawl/crawldb crawl/linkdb crawl/segment/*
I am trying to convert the following code into python: Columns(C:C).Select Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual
If I type the following into IDLE, it gives me the result of 'wordwordword':
I want to convert the following string into Date type this way Date dateToFormat
Assume the following type definitions: public interface IFoo<T> : IBar<T> {} public class Foo<T>
I have come across the following type of code many a times, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.