Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2012, 08:46 PM
myrmounet myrmounet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 myrmounet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 16 sec
Reputation 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

Reply With Quote
  #2  
Old November 9th, 2012, 08:48 PM
myrmounet myrmounet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 myrmounet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 16 sec
Reputation Power: 0
#excuse me i forget to say the answers i'd luve to have are : bread and eggs.
THANKS

Reply With Quote
  #3  
Old November 9th, 2012, 08:51 PM
KING-OLE KING-OLE is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Texas
Posts: 24 KING-OLE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 45 sec
Reputation Power: 0
Quote:
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?

Reply With Quote
  #4  
Old November 9th, 2012, 08:55 PM
KING-OLE KING-OLE is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Texas
Posts: 24 KING-OLE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 45 sec
Reputation Power: 0
Quote:
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
>>>

Reply With Quote
  #5  
Old November 9th, 2012, 09:01 PM
KING-OLE KING-OLE is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Texas
Posts: 24 KING-OLE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 45 sec
Reputation 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])

Reply With Quote
  #6  
Old November 10th, 2012, 06:06 AM
SuperOscar SuperOscar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Joensuu, Finland
Posts: 404 SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 5 h 17 m 59 sec
Reputation Power: 65
Quote:
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 12.3 (home desktop, laptop, work desktop), Ubuntu 12.04 LTS (mini laptop), Debian GNU/Linux 7.0 (server), Mythbuntu 12.04 LTS (HTPC), Bodhi Linux 2.0 & Windows 7 Ultimate (test desktop), FreeBSD 9.1 (test server)

Reply With Quote
  #7  
Old November 12th, 2012, 05:59 PM
myrmounet myrmounet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 myrmounet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 16 sec
Reputation 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)

Reply With Quote
  #8  
Old November 14th, 2012, 05:59 PM
myrmounet myrmounet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 myrmounet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 16 sec
Reputation 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Shopping list.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap