On Sun, Sep 13, 2015 at 7:20 AM, Nym City via Tutor <tutor@python.org> wrote: > Hello, > Sorry for the late response. It took me sometime to find the solution. Below > is my updated code which seems to be working fine now. Just wanted to share > with the group here. > > import csv > DomainList = [] > > domains = open('domainlist.csv', 'r') > DomainList = csv.reader(domains) > DomainList = [column[1] for column in DomainList] > strip_list = [item.rstrip('/') for item in DomainList] > print('\n'.join(strip_list))
Style suggestions. 1. The initial assignment of: DomainList = [] can be omitted: the code does another assignment that completely ignores the initial value. 2. The reassignment of DomainList to the result of csv.reader() is confusing, because the new value isn't of the same type as the old value. I'd recommend that your program set aside a separate variable name for the csv reader. Call it "DomainListCSV" or something that can be distinguished from the list of domains that your program is collecting. ############################################### import csv domains = open('domainlist.csv', 'r') DomainListCSV = csv.reader(domains) DomainList = [column[1] for column in DomainListCSV] strip_list = [item.rstrip('/') for item in DomainList] print('\n'.join(strip_list)) ################################################ That way, if you see the word "DomainList" in your program, its conceptual meaning is more stable: its meaning doesn't have to change from one statement to the next. Assigning to a variable just once makes the program easier to understand. (That being said, we might have technical reasons for doing variable re-assignment. But such cases aren't as prevalent as one might expect!) 3. Finally, it might be good to stick with a single style for naming variables. You're using both underscored names and CapCased names. Consistency suggests that we pick a style and stick with it throughout the program. Doing an eclectic mix of naming conventions hurts readability a bit. If we stick with underscored names: ############################################### import csv domain_file = open('domainlist.csv', 'r') domains_csv = csv.reader(domain_file) domain_list = [column[1] for column in domains_csv] strip_list = [item.rstrip('/') for item in domain_list] print('\n'.join(strip_list)) ################################################ that would be one way to correct this issue. Or use CapWords. The main point is: try to use a single style that's shared across the program as a whole. Hope this helps! _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor