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 5935227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:13:27+00:00 2026-05-22T15:13:27+00:00

I created a Python script with Python2.7 and it works fine. However, when I

  • 0

I created a Python script with Python2.7 and it works fine. However, when I run the same script with Python2.6, I got a “SyntaxError: invalid syntax” error.

After investigating, the problem seems to be related to a for loop.

l1 = [["a1", "a2"], ["b1", "b2"]]
print {item[0]:item[1] for item in l1}

When I run the above code with Python 2.7, I’ve got the following output:

{'a1': 'a2', 'b1': 'b2'}

When I run the same code with Python 2.6, I’ve got the following error:

>>> l1 = [["a1", "a2"], ["b1", "b2"]]
>>> print {item[0]:item[1] for item in l1}
  File "<stdin>", line 1
    print {item[0]:item[1] for item in l1}
                             ^
SyntaxError: invalid syntax
>>>

Any help is appreciated.

Regards,
Allen

  • 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-22T15:13:28+00:00Added an answer on May 22, 2026 at 3:13 pm

    Try this:

    print dict(item for item in l1)
    

    Edit about your comment: If you want to explicitly select items, wrap them in a tuple:

    print dict((item[1], item[4]) for item in l1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My python program (Python 2.6) works fine when I run it using the Python
I have created a Python script that I want to run daily via a
I have a python script that works great when run by itself. Based on
I've created a python script in which an event needs to be executed each
A python script is running two parallel python processes ( created via os.fork() )
I've created a small python script to toggle between two files I'm using for
In my python script i am parsing a user created file and typically there
I've just created my first VIM script, I wrote it in Python. It's a
to interact with my iPhone, i have created a python script that sends and
I want to add QSplashScreen to PyQT4 application. It works fine from Python, but

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.