473,513 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can only concatenate list (not "str") to list

1 New Member
My program is supposed to reverse the string inputted, print it then extract the numbers and print the numbers of the reversed string in a list.

Expand|Select|Wrap|Line Numbers
  1. def reverse_str(string):
  2.     revstring =('')
  3.     length=len(string)
  4.     i = length - 1
  5.     while i>=0:
  6.         revstring = revstring + string[i]
  7.         i = i - 1
  8.     return revstring
  9. def strip_digits(string):
  10.     result = []
  11.     for c in string:
  12.         result = result + c
  13. string = raw_input("Enter a string->")
  14. new_str = reverse_str(string)
  15. print new_str
  16. numberless_str  = strip_digits(string)
Oct 16 '12 #1
2 5423
Rabbit
12,516 Recognized Expert Moderator MVP
Please use code tags when posting code.

You've told us what you want to do. Now what's your question?
Oct 16 '12 #2
dwblas
626 Recognized Expert Contributor
can only concatenate list (not "str") to list
You should have included the complete error message which includes the offending line.

"+" concatenates 2 lists. To add another string to an existing list use append (see "list methods"). Note also that you pass "string" to strip_digits(), not "new_str". Finally do not use "string" as a variable name as string is already used by python.
Oct 16 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3209
by: roopa | last post by:
I have declared a class with name List; and in main() function, i have declared the List object as follows class List { public: List() { cout<<"In List Constuctor";
6
2747
by: Gonnasi | last post by:
With >glob.glob("*") or >os.listdir(cwd) I can get a combined file list with directory list, but I just wanna a bare file list, no directory list. How to get it? Tons of thanks in advance!
3
3383
by: news.bellatlantic.net | last post by:
I have a fundraising database for an organization. Donations come in from current members anad are found by using a combo box. If the member is found, the After Update macro switches to another...
2
2192
by: ormy28 | last post by:
I really need some help with the following problem if anyone would be willing. I need a list box to list the opposite of what appears in a query. Heres the details: My database is for a...
1
2966
by: tina.boroff | last post by:
I have 3 boxes that essentially use the same code for not in List events (Thank you to David for all of your help on that one). The code opens another form if the user wants to enter data that is...
0
1249
by: BeccyBoo | last post by:
This has probably been posted before but i've searched and couldn't find the answer I'm looking for (or just couldn't understand it) but here's what i'm trying to do: i have a table...
5
11869
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
3474
by: webmaster | last post by:
Pardon my being a total C# noob. I'm trying to take apart the dotNet Time Tracker dotNet C# starterkit sample application and replicate a part of the code. At a high level, I have a very...
5
52298
by: =?Utf-8?B?U3dhcG5pbA==?= | last post by:
hi, I want to copy the elements of one list to the other list. Is there any function to do this operation in C#. Plz explain with example.
3
2658
by: antar2 | last post by:
I already asked a similar question, but encounter problems with python... How can I concatenate the elements in each list of a list of lists list_of_listsA = , , ]
0
7260
marktang
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,...
0
7161
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...
0
7384
Oralloy
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,...
0
7539
jinu1996
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...
0
5686
agi2029
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,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.