473,545 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List iteration returns only last value

1 New Member
Hey guys. I am working on a pretty special program here IMO. But i keep encountering one problem. I am trying to append items from one word list to another(filtrat ion reasons). But when the program runs, the list in the end only has the last value from the other list, whereas i know for a fact that there are more values. I am only filtering alphabets out of number.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. def cleanlist(wordlist):
  2.     for word in wordlist:
  3.         lex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
  4.         for i in range(0,len(lex)):
  5.             word = word.replace(lex[i], "")
  6.             if len(word) > 0:
  7.                 clean_list = []
  8.                 clean_list.append(word)
  9.         print(clean_list)
  10.     f.write(str(clean_list))
  11.  
  12.  
Jan 2 '17 #1
1 1351
dwblas
626 Recognized Expert Contributor
A new, empty list is created each time, so only contains that one entry. See the next line under the "if len(word) > 0:" line. Also, use "".join() to cast a list into a string.
Jan 3 '17 #2

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

Similar topics

2
5187
by: Edward | last post by:
I have the following function to determine if a form is loaded: Public Function modIsloaded(ByVal vstrFormName As String) As Boolean ' Error handling removed for concision ' Determine if form open modIsloaded = False If (SysCmd(acSysCmdGetObjectState, acForm, vstrFormName) = acObjStateOpen) Then
1
3995
by: Jean Stax | last post by:
Hi ! I created a sample library project. In my second project I reference this library and make the following call, which returns "undefined value": Type myType = Type.GetType("SampleLib.MyClass"); My guess was that the function fails because my library isn't loaded yet.
3
2533
by: Stephan | last post by:
Hi, I'm working on a page with multiple Datalist-controls on it. The problem I'm facing is that when I try to update a record, the ItemIndex returns a value which is one lower than the Item I want to edit, so when I update the record, the previous record is changed. I put some code here, but not all. Adding, of course, is no problem...
10
6384
by: MaRCeLO PeReiRA | last post by:
Hi guys, I am in troubles with a SERIAL field. I have five tables. A parent table and four child tables. When I do the INSERT in the parent table, I have an ID (generated) by the sequence (SERIAL field), and I have to use this ID to reference all child tables.
12
1927
by: chellappa | last post by:
hi All, function automatically returns the value,am not used "return" i am using Linux -gcc complier please tell me.... what is problem... source ===== #include <stdio.h> main() {
2
1925
by: nikolacace | last post by:
Hi, I have a stored procedure (the code is below) that I use to retrieve one value from my database. I tested the code in Query Analyzer, and it works (I get the value I was looking for). However, when I call the same code from the stored procedure, I get no value. The code that is executed is the same and the input parameter is the same....
3
1237
by: Renar | last post by:
Hello, My name is Tim and I am new here so i would just like to start of with saying hi to everyone! the problem i have is i am using asp.net and SQL and I want to get the last value of the called vidid and increase it by one. I have found this code SELECT MAX(vidid) + 1 FROM dbo.Videos I am using dreamweaver 8 and I use the test...
2
1556
by: emeryk | last post by:
I am trying to loop through a gridview and insert the selected value of a dropdown list and textbox from each row into another table. I was finally able to get the insert statment to work but it only inserts the value from the last row in the GridView. Here is the code I am using to pass the values to my insert statment. Protected Sub...
6
1523
by: Shriphani | last post by:
Hello all, Let us say I have a function like this: def efficientFiller(file): worthless_list = pot_file = open(file,'r') pot_file_text = pot_file.readlines() for line in pot_file_text: if line.find("msgid") != -1:
3
2628
by: raamay | last post by:
can anybody tell me why the following query returns null value. SELECT * FROM yjdf4_tbltenders AS a LEFT JOIN yjdf4_tblclass AS b ON a.cls = b.clid LEFT JOIN yjdf4_tblcategory AS c ON a.wcategory = c.catid LEFT JOIN (yjdf4_tblclient AS d JOIN yjdf4_tblclscategory AS e ON d.clcatid = e.clsid ) ON a.clientagency = d.cid LEFT JOIN...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7807
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7756
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
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 we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.