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

  • SEARCH
  • Home
  • 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 8896345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:01:17+00:00 2026-06-15T00:01:17+00:00

Using a single statement, print a dictionary containing only the atomic symbols and their

  • 0

Using a single statement, print a dictionary containing only the atomic symbols and their corresponding weights for those elements in wts (my dictionary) which have only a single letter in their atomic symbols. I.e., include ‘H’ but omit ‘He’. My dictionary is set up as {'H':'1.00794','He':'4.002602','Li':'6.941','Be':'9.012182','B':'10.811','C':'12.0107','N':'14.0067','O':'15.9994'}

[for element in wts if len(element) == 1]

I was thinking a list comprehension would would work but, how would i have it look only at the element symbol. This returns an error of :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_45.py", line 10, in <module>
    exec compile(u"print _support_.syseval(python, u'[for element in wts if len(element) == 1]', __SAGE_TMP_DIR__)" + '\n', '', 'single')
  File "", line 1, in <module>

  File "/sagenb/sage_install/sage-5.3-sage.math.washington.edu-x86_64-Linux/devel/sagenb-git/sagenb/misc/support.py", line 487, in syseval
    return system.eval(cmd, sage_globals, locals = sage_globals)
  File "/sagenb/sage_install/sage-5.3-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/misc/python.py", line 53, in eval
    eval(compile(s, '', 'exec'), globals, globals)
  File "", line 3
    [for element in wts if len(element) == 1]
       ^
SyntaxError: invalid syntax
  • 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-06-15T00:01:19+00:00Added an answer on June 15, 2026 at 12:01 am

    You have a syntax error (as noted by Python). Use:

    [element for element in wts if len(element) == 1]
    

    A list comprehension must start with an expression before the for. With this syntax you can apply further operations, such as uppercasing for example:

    [element.upper() for element in wts if len(element) == 1]
    

    Because you have to repeat the iteration variable name so much, you will often see comprehensions written with short variable names. I might write that using x as:

    [x for x in wts if len(x) == 1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i insert multiple values in a sql table using single statement. Doing
how to get all data in single array without using while statement. here is
I am using Single Table Inheritance for managing different types of projects. Models: class
why php escapes backslashes when using single quotes? I'm trying to output \\ on
I am in a computer arch class and we are doing mips using single
In Bash script, what is the difference between the following snippets? 1) Using single
I am using the Single Access Token from authlogic to sync data from a
I am using a single module a lot in the Erlang shell. Is there
Currently I am using a single thread and fseek/fwrite to save data into a
I'm using the single page application template in MVC 4. The template created the

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.