Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Basic Python Questions
New Posts  All Forums:Forum Nav:

Basic Python Questions

post #1 of 4
Thread Starter 
I'm sure my questions are going to be so easy that it's common knowledge to most, but on a CSC 220 (Data Structures in Algorithms [Python]) assignment I have, I'm having trouble with what seems should be a pretty basic concept. In this chapter, we are dealing with Stacks, Queues, and Deques, and their operations. Here are the questions I have:

Given a list LST of objects, write Python code to perform the following
list operations:

(1) add an object to the end of the list,
(2) add an object to the beginning of the list,
(3) remove an object from the end of the list,
(4) remove an item from the beginning of the list,
(5) retrieve an item from the end of the list without removing it,
(6) retrieve an item from the beginning of the list without removing it.

What I have so far (based on the chapter reading and PowerPoint notes):

1. LST.addRear(4)
2. LST.addFront('cat') or LST.enqueue('cat')
3. LST.removeRear()
4. LST.removeFront() or LST.dequeue()
5.
6. LST.peek()

Questions 5 and 6 are what I'm having the most trouble with. The peek function allows you to look at the 'top' of a stack (basically the last entry) and it returns what's there. I can't find a function that lets you see the end of the list, but also does not remove said object/item, though.

I'm unsure about 2 and 4 as well, as both answers I provided to seem to be correct, but I'm not sure if one is more correct than the other. If I need to post some more info, please let me know.
 
OverCoaster
(14 items)
 
 
CPUMotherboardGraphicsRAM
i7 7700K [4.5GHz] ASUS Z270i STRIX Titan X Pascal + Hybrid Corsair Vengeance LPX 3K [16GB] 
Hard DriveHard DriveCoolingOS
Kingston HyperX Savage [480GB] Mushkin Enhanced Reactor [1TB] Corsair H75 + F120MP Windows 10 Professional [x64] 
MonitorMonitorKeyboardPower
Acer Predator X34 Dell P2012Ht Razer Blackwidow X [Tournament Ed.] Corsair SF600 [600w] 
CaseMouseMouse PadAudio
NCASE M1 [v5] G403 Wireless QcK+ [Vault 111 Ed.] Schiit Bifrost Uber + Schiit Asgard 2 + TH-X00... 
CPUMotherboardGraphicsRAM
i5 4670K ASRock Z97E-ITX/ac ASUS GTX 1070 FE Kingston HyperX Fury DDR3 1866 [White Ed.] 
Hard DriveCoolingOSMonitor
Samsung Evo 840 [250GB] Phanteks PH-TC14PE  Win 10 Pro [x64] Dell S2716DGR [144hz] 
KeyboardPowerCaseMouse
KC60 [Miami Ed.] EVGA 550 G2 Phanteks Enthoo Evolv ITX [White] Logitech G403 
Mouse PadAudio
SS QcK Heavy AudioQuest Dragonfly Black + Sennhesier HD650 
  hide details  
Reply
 
OverCoaster
(14 items)
 
 
CPUMotherboardGraphicsRAM
i7 7700K [4.5GHz] ASUS Z270i STRIX Titan X Pascal + Hybrid Corsair Vengeance LPX 3K [16GB] 
Hard DriveHard DriveCoolingOS
Kingston HyperX Savage [480GB] Mushkin Enhanced Reactor [1TB] Corsair H75 + F120MP Windows 10 Professional [x64] 
MonitorMonitorKeyboardPower
Acer Predator X34 Dell P2012Ht Razer Blackwidow X [Tournament Ed.] Corsair SF600 [600w] 
CaseMouseMouse PadAudio
NCASE M1 [v5] G403 Wireless QcK+ [Vault 111 Ed.] Schiit Bifrost Uber + Schiit Asgard 2 + TH-X00... 
CPUMotherboardGraphicsRAM
i5 4670K ASRock Z97E-ITX/ac ASUS GTX 1070 FE Kingston HyperX Fury DDR3 1866 [White Ed.] 
Hard DriveCoolingOSMonitor
Samsung Evo 840 [250GB] Phanteks PH-TC14PE  Win 10 Pro [x64] Dell S2716DGR [144hz] 
KeyboardPowerCaseMouse
KC60 [Miami Ed.] EVGA 550 G2 Phanteks Enthoo Evolv ITX [White] Logitech G403 
Mouse PadAudio
SS QcK Heavy AudioQuest Dragonfly Black + Sennhesier HD650 
  hide details  
Reply
post #2 of 4
This should help:
http://docs.python.org/tutorial/datastructures.html
post #3 of 4
Thread Starter 
Surprisingly, I found the answers . My friend and I emailed our teacher. We were under the impression that we had to use the 'Stack, Queue, and Deque' functions. But he told us that this was not the case. We ended up using different commands (which are actually in the link you provided). I wish I could rep you for the help, though .
 
OverCoaster
(14 items)
 
 
CPUMotherboardGraphicsRAM
i7 7700K [4.5GHz] ASUS Z270i STRIX Titan X Pascal + Hybrid Corsair Vengeance LPX 3K [16GB] 
Hard DriveHard DriveCoolingOS
Kingston HyperX Savage [480GB] Mushkin Enhanced Reactor [1TB] Corsair H75 + F120MP Windows 10 Professional [x64] 
MonitorMonitorKeyboardPower
Acer Predator X34 Dell P2012Ht Razer Blackwidow X [Tournament Ed.] Corsair SF600 [600w] 
CaseMouseMouse PadAudio
NCASE M1 [v5] G403 Wireless QcK+ [Vault 111 Ed.] Schiit Bifrost Uber + Schiit Asgard 2 + TH-X00... 
CPUMotherboardGraphicsRAM
i5 4670K ASRock Z97E-ITX/ac ASUS GTX 1070 FE Kingston HyperX Fury DDR3 1866 [White Ed.] 
Hard DriveCoolingOSMonitor
Samsung Evo 840 [250GB] Phanteks PH-TC14PE  Win 10 Pro [x64] Dell S2716DGR [144hz] 
KeyboardPowerCaseMouse
KC60 [Miami Ed.] EVGA 550 G2 Phanteks Enthoo Evolv ITX [White] Logitech G403 
Mouse PadAudio
SS QcK Heavy AudioQuest Dragonfly Black + Sennhesier HD650 
  hide details  
Reply
 
OverCoaster
(14 items)
 
 
CPUMotherboardGraphicsRAM
i7 7700K [4.5GHz] ASUS Z270i STRIX Titan X Pascal + Hybrid Corsair Vengeance LPX 3K [16GB] 
Hard DriveHard DriveCoolingOS
Kingston HyperX Savage [480GB] Mushkin Enhanced Reactor [1TB] Corsair H75 + F120MP Windows 10 Professional [x64] 
MonitorMonitorKeyboardPower
Acer Predator X34 Dell P2012Ht Razer Blackwidow X [Tournament Ed.] Corsair SF600 [600w] 
CaseMouseMouse PadAudio
NCASE M1 [v5] G403 Wireless QcK+ [Vault 111 Ed.] Schiit Bifrost Uber + Schiit Asgard 2 + TH-X00... 
CPUMotherboardGraphicsRAM
i5 4670K ASRock Z97E-ITX/ac ASUS GTX 1070 FE Kingston HyperX Fury DDR3 1866 [White Ed.] 
Hard DriveCoolingOSMonitor
Samsung Evo 840 [250GB] Phanteks PH-TC14PE  Win 10 Pro [x64] Dell S2716DGR [144hz] 
KeyboardPowerCaseMouse
KC60 [Miami Ed.] EVGA 550 G2 Phanteks Enthoo Evolv ITX [White] Logitech G403 
Mouse PadAudio
SS QcK Heavy AudioQuest Dragonfly Black + Sennhesier HD650 
  hide details  
Reply
post #4 of 4
Quote:
Originally Posted by pez View Post
Surprisingly, I found the answers . My friend and I emailed our teacher. We were under the impression that we had to use the 'Stack, Queue, and Deque' functions. But he told us that this was not the case. We ended up using different commands (which are actually in the link you provided). I wish I could rep you for the help, though .
Glad you figured it out
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Basic Python Questions