Thread: Shopping list.

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Shopping list.


    Hello over there !
    I have a shopping list, and wanted to find in the list all the milk ones, because i want to find all the next buying thing.
    Here's the code :
    #-*-coding :iso-9959-1-*-
    #!/usr/bin/python -tt
    import sys
    # +++your code here+++
    shopping= ["milk", "bread", "apples", "milk", "eggs"]
    c = 0
    for "milk" in shopping:
    for shopping[c] in shopping["milk"]
    shopping[c] in shopping
    c = c+1
    milknext = shopping[c]

    print milknext



    ## thanks you for any kind of help bye
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    #excuse me i forget to say the answers i'd luve to have are : bread and eggs.
    THANKS
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Texas
    Posts
    24
    Rep Power
    0
    Originally Posted by myrmounet
    Hello over there !
    I have a shopping list, and wanted to find in the list all the milk ones, because i want to find all the next buying thing.
    Here's the code :
    #-*-coding :iso-9959-1-*-
    #!/usr/bin/python -tt
    import sys
    # +++your code here+++
    shopping= ["milk", "bread", "apples", "milk", "eggs"]
    c = 0
    for "milk" in shopping:
    for shopping[c] in shopping["milk"]
    shopping[c] in shopping
    c = c+1
    milknext = shopping[c]

    print milknext



    ## thanks you for any kind of help bye
    Not quite sure what you're asking. Could you show the result you'd like the code to produce?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Texas
    Posts
    24
    Rep Power
    0
    Originally Posted by myrmounet
    #excuse me i forget to say the answers i'd luve to have are : bread and eggs.
    THANKS
    This would work, as long as there's something after 'milk' every time.

    Code:
    >>> shopping= ["milk", "bread", "apples", "milk", "eggs"]
    >>> for i in range (0,shopping.count('milk')):
    ...   e = shopping.index('milk',i)
    ...   print (shopping[e+1])
    ...
    bread
    eggs
    >>>
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Texas
    Posts
    24
    Rep Power
    0
    Here's the breakdown:

    Create the shopping list.
    Code:
    shopping= ["milk", "bread", "apples", "milk", "eggs"]
    Loop through the number of occurrences of 'milk'
    Code:
    for i in range (0,shopping.count('milk')):
    Find the position of the i occurrence of 'milk' and assign it to e
    Code:
    e = shopping.index('milk',i)
    Print what's on the position after the occurrence (e+1)
    Code:
    print (shopping[e+1])
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    434
    Rep Power
    67
    Originally Posted by myrmounet
    #excuse me i forget to say the answers i'd luve to have are : bread and eggs.
    Not spam and eggs and spam? Weird.
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (mini laptop, work laptop), Ubuntu 14.04 LTS (server), Android 4.2.1 (tablet), Windows 7 Ultimate (testbed)
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    let's try


    let me try your piece of code you just gave me, excuse me my email with devshed is a secondary email... i'm coding now ! (not too much ! lol)
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    def shopping:
    """Returns mimic dict mapping each word to list of words which follow it."""
    # +++your code here+++
    shopping= {}
    shopping2= []
    i=0
    name = "and"
    write = "NOM"
    shopping = {milk : 1, bread : 1, milk : 1, eggs : 1, pan : 1}
    shopping2 = shopping.keys()
    write = shopping2.index(milk')
    print shopping2[write+1]
    answer wanted : bread eggs.
    thanks you're pretty kindful

IMN logo majestic logo threadwatch logo seochat tools logo