User Profile

Collapse

Profile Sidebar

Collapse
sudipb
sudipb
Last Activity: Mar 31 '10, 02:52 PM
Joined: Jan 2 '10
Location: New Delhi
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Python:Query on Conditional Loops and the setdefault method

    >>>listoflist s = [['a', 'first'], ['b', 'second'], ['a', 'next'], ['c', 'third'], ['b', 'last']]
    >>> dd = {}
    >>>for item in listoflists:
    ... dd.setdefault(i tem[0], []).append(item)

    - The part which mentions 'item[0]' would be to have the first letter of each item in the list we created right ?
    - what does the ' [ ] ' signify in this case ? Does it mean to have a null value...
    See more | Go to post

  • Hey Thanks a ton !!!

    Your answer's been very helpful.

    A couple of clarifications that you could perhaps help me with:

    You mentioned:
    >>>for item in listoflists:
    ... dd.setdefault(i tem[0], []).append(item[1])

    - The part which mentions 'item[0]' would be to have the first letter of each item in the list we created right ?
    - what's the ' [ ] ' signify in this case...
    See more | Go to post

    Leave a comment:


  • sudipb
    started a topic A problem that I am facing on Python Dictionaries

    A problem that I am facing on Python Dictionaries

    I input the following:
    >>> collection={} #Initiate an empty dictionary
    >>>collection={ 'a':'first', 'a':'second','d ':'third','b':' fourth','e':'fi fth','b':'sixth '}
    >>> collection
    {'a':'second',' b':'sixth','e': 'fifth','d':'th ird'}

    Now my question is:

    Why does the output not include all the values (2 values for 'a' AND 2 values for 'b) BUT only shows the output of ONLY the...
    See more | Go to post
    Last edited by bvdet; Feb 20 '10, 01:45 PM. Reason: Removed email address
No activity results to display
Show More
Working...