I have a function that won't work is it possible for someone to debug it for me?...i've been trying to play with everything... -
def reverse(L):
-
"""Given a list, return a new list that is the same as the original list except that its members are in reverse order, without changing the original."""
-
M=list()
-
for i in L:
-
M.append(L[i])
-
M.reverse()
-
return M
2 1306
These lines are the problem: - for i in L:
-
M.append(L[i])
i contains items from the list, not list indices. The code should be
However, a more compact way to copy a list is with a slice:
I hope this is helpful.
bvdet 2,851
Expert Mod 2GB
To give you some alternatives, you can create a reversed list using the slice operator and the range function in a list comprehension. You could also use a for loop in combination with range() instead of the comprehension. - >>> aList = [0,1,2,3,4,5,6,7,8,9]
-
>>> anotherList = aList[::-1]
-
>>> aList
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-
>>> anotherList
-
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
-
>>> anotherList2 = [aList[i] for i in range(len(aList)-1, -1, -1)]
-
>>> anotherList2
-
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve Wark |
last post by:
I have a Windows 2003 Web server on which I was debugging remotely with no
problems.
I then moved this server to a different domain and now remote debugging will
not work, the error is;
...
|
by: Jeffrey Frabutt |
last post by:
Hey... I'm reletively new to ASP.NET and am having some frustrating
debugging issues. Everything is configured correctly for me to debug
my VERY simple one-page application. That said, after just...
|
by: keyser_Soze |
last post by:
I have MS Visual Studio 2003 on Windows XP Pro. I have IIS running on
this machine and I am trying to debug some existing code which has both
ASP and ASP.NET components.
When I try and launch...
|
by: snicks |
last post by:
I'm trying to exec a program external to my ASP.NET app using the following
code. The external app is a VB.NET application.
Dim sPPTOut As String
sPPTOut = MDEPDirStr + sID + ".ppt"
Dim p As...
|
by: Joseph S. |
last post by:
hi all,
debugging PHP applications interactively is possible, easy and free. I
am talking about PHPEclipse and using it for debugging over several
scripts or debugging through a session. Since I...
|
by: krypto.wizard |
last post by:
Is there any editor or IDE in Python (either Windows or Linux) which
has very good debugging facilites like MS VisualStudio has or something
like that.
I like SPE but couldn't easily use winPDP....
|
by: Greg |
last post by:
I have a very simple Visual Basic .NET 2003 class library project
ClassLibrary1 configured to run an external program (in this case
C:\WINDOWS\system32\wscript.exe), in the Debugging Configuration...
|
by: DR |
last post by:
Unable to start TSQL Debugging. Could not attach to SQL Server Process on
'srvname'. The RPC server is unavailable.
I get this error when I try to run a SQL Server Project with a CLR stored...
|
by: fmassei |
last post by:
Hello!
I made a short piece of code that I find very useful for debugging,
and I wanted to ask you if it is correct, somehow acceptable or if I
simply reinvented the wheel.
To deal with some bad...
|
by: Jeff |
last post by:
hi
asp.net 2.0
vista business 32bit
I have placed a break point with the Page_Load event of a UserControl.
The break point wasn't triggered.. I have also put
Debug.WriteLine("Page_Load"); in...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |