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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:13:08+00:00 2026-05-20T14:13:08+00:00

I looked around and found a few examples of how to split text in

  • 0

I looked around and found a few examples of how to split text in python but having problems on my example. Here’s what I want to parse:

<img alt="" src="http://example.com/servlet/charting?base_color=grey&amp;chart_width=288&amp;chart_height=160&amp;chart_type=png&amp;chart_style=manufund_pie&amp;3DSet=true&amp;chart_size=small&amp;leg_on=left&amp;static_xvalues=10.21,12.12,43.12,12.10,&amp;static_labels=blue,red,green,purple">

Here’s what I tried:

dict(kvpair.split('=') for kvpair in variableIwantToParse.split('&'))

I get the error “ValueError: dictionary update sequence element #0 has length 5; 2 is required”

I tried also to use variableIwantToParse.strip(‘&’) but when I tried to print variableIwantToParse it only displaced one letter at a time.

I’m sure this is easy but can’t seem to figure out how to parse it. I basically want 10.21,12.12,43.12,12.10 to be associated with blue,red,green,purple (in the order displayed)

Thanks very much for your help(and sorry if this is too easy..I just can’t for the life of me figure out the command to parse this) 🙂

  • 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-20T14:13:09+00:00Added an answer on May 20, 2026 at 2:13 pm

    Use the built-in urlparse module, do not do these splits yourself.

    >>> import urlparse
    >>> url_to_parse = "http://example.com/servlet/charting?base_color=grey&amp;chart_width=288&amp;chart_height=160&amp;chart_type=png&amp;chart_style=manufund_pie&amp;3DSet=true&amp;chart_size=small&amp;leg_on=left&amp;static_xvalues=10.21,12.12,43.12,12.10,&amp;static_labels=blue,red,green,purple"
    >>> parsed_url = urlparse.urlparse(url_to_parse)
    >>> query_as_dict = urlparse.parse_qs(parsed_url.query)
    >>> print query_as_dict
    {'chart_size': ['small'], 'base_color': ['grey'], 'chart_style': ['manufund_pie'], 'chart_height': ['160'], 'static_xvalues': ['10.21,12.12,43.12,12.10,'], 'chart_width': ['288'], 'static_labels': ['blue,red,green,purple'], 'leg_on': ['left'], 'chart_type': ['png'], '3DSet': ['true']}
    

    If you’re using Python with a version less than 2.6, then you have to import the cgi module. Do this instead:

    >>> import urlparse
    >>> import cgi
    >>> parsed_url = urlparse.urlparse(url_to_parse)
    >>> query_as_dict = cgi.parse_qs(parsed_url.query)
    >>> print query_as_dict
    {'chart_size': ['small'], 'base_color': ['grey'], 'chart_style': ['manufund_pie'], 'chart_height': ['160'], 'static_xvalues': ['10.21,12.12,43.12,12.10,'], 'chart_width': ['288'], 'static_labels': ['blue,red,green,purple'], 'leg_on': ['left'], 'chart_type': ['png'], '3DSet': ['true']}
    

    Then to associate them to a dictionary, use the provided dict constructor alongside zip.

    >>> print dict(zip( query_as_dict['static_labels'][0].split(','), query_as_dict['static_xvalues'][0].split(',')))
    {'blue': '10.21', 'purple': '12.10', 'green': '43.12', 'red': '12.12'}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looked around and found a few similar questions but none of them were the
I looked around and found that there is an onerror function for flexigrid but
I have looked all around and only found solutions for python 2.6 and earlier,
I've looked around on stackoverflow for a similar question, but haven't found exactly what
So I have looked around and saw a few posts on similar things but
I've looked around but haven't found an answer so I wanted to confirm this
Looked around SO but couldn't find anything useful, so.. I have a Backbone.js contacts
I've looked around for a physics engine that will play nicely with Android, but
I've looked around at pretty much all the SMS posts here on SO and
I've looked around for this for a while now and haven't really found anything

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.