The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Shopping list.
Discuss Shopping list. in the Python Programming forum on Dev Shed. Shopping list. Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 9th, 2012, 08:46 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 6
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
|

November 9th, 2012, 08:48 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 6
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
|

November 9th, 2012, 08:51 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Location: Texas
Posts: 24
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?
|

November 9th, 2012, 08:55 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Location: Texas
Posts: 24
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
>>>
|

November 9th, 2012, 09:01 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Location: Texas
Posts: 24
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])
|

November 10th, 2012, 06:06 AM
|
|
Contributing User
|
|
Join Date: Jul 2007
Location: Joensuu, Finland
|
|
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)
|

November 12th, 2012, 05:59 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 6
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)
|

November 14th, 2012, 05:59 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 6
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|