473,911 Members | 5,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help me!!

I have the following piece of code

a = len(ab_file)
b= 0
while(b<a):
c= 0
d = len(cd_files)
while(c<d):
if cd_files[c] == ab_file[b]:
files.append(ab _file[b].upper())
else:
files.append(ab _file[b])
c = c + 1

b = b +1

print files

I'm trying to compare the list with another list and if it is there in
both I'm changing it to upper case and adding to another list and if
its not there in both I just want to add it to the global list (ie
files).
I'm able to do the first part but when I'm doing the second part the
files which are not there in both are getting repeatedly into the
global file. Some one help me so that
If ab = [a,b,c,d]
and cd = [a,c]
my global list file should be [A,b,C,d]

Aug 16 '07 #1
3 1019
Some one help me so that
If ab = [a,b,c,d]
and cd = [a,c]
my global list file should be [A,b,C,d]

If there is a lot of entries in the list, I would consider using an
indexed data structure such as dict.
>>ab=['a','b','c','d']
cd=['a','c']
common=[x.upper() for x in ab if x in cd]
ab_minus_cd =[x for x in ab if x not in cd]
cd_minus_ab =[x for x in ab if x not in cd]
requested_lis t = common+ab_minus _cd+cd_minus_ab
Aug 16 '07 #2
On Aug 16, 2:26 pm, beginner <zyzhu2...@gmai l.comwrote:
Some one help me so that
If ab = [a,b,c,d]
and cd = [a,c]
my global list file should be [A,b,C,d]
If there is a lot of entries in the list, I would consider using an
indexed data structure such as dict.
ab=['a','b','c','d']
cd=['a','c']
common=[x.upper() for x in ab if x in cd]
ab_minus_cd=[x for x in ab if x not in cd]
cd_minus_ab=[x for x in ab if x not in cd]
requested_list = common+ab_minus _cd+cd_minus_ab- Hide quoted text -

Aug 16 '07 #3
Anhoter HURRA for list comprehensions:
>>a = ['a', 'b', 'c', 'd']
b = ['a','c']
[x in b and x.upper() or x for x in a]
['A', 'b', 'C', 'd']

Is what you want?
Cheers

Gerardo
>I'm trying to compare the list with another list and if it is there in
both I'm changing it to upper case and adding to another list and if
its not there in both I just want to add it to the global list (ie
files).
I'm able to do the first part but when I'm doing the second part the
files which are not there in both are getting repeatedly into the
global file. Some one help me so that
If ab = [a,b,c,d]
and cd = [a,c]
my global list file should be [A,b,C,d]
Aug 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2099
by: Krakatioison | last post by:
Hi all, I need a help to write a simple preg_match. Imagine, I've got like 5kb of text where one part of the text always starts with: and ends with: Number after "[quote:" is always different and changing its length.
3
2332
by: Lodewijk van Haringhal | last post by:
I'am new with javascritping not with programming. Is there nobody who can help me with ths simple promblem? :) Please, please give me a hint. Please help me with this script. I have two lists in my form. One to choose a directory and one to choose a picture. The script bellow works perfect without the directory choose function. I tried to make the directory choose function myself but I did not succeed. I think I made a mistake here:...
6
4379
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
1
1623
by: PerryC | last post by:
Can someone help me accomplish the following in a MSAccess Report: 1. Check if Me.Discipline = "RN" (within the source query) 2. Then check the Me.YearOfEmployment: (again within the same source query) if <2 then Me.BaseRate = BaseRate, if between 2 and <5 then Me.BaseRate = BaseRate * 1.03 if between 5 and <10 then Me.BaseRate = BaseRate * 1.03 * 1.03 ....
1
3733
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
7
1502
by: Mickyd1561 | last post by:
Hey everyone I'm new to this groups thing and thought maybe someone can help me. My problem is that I can't view specific images on only one website. www.baseballu.net is my baseball team's website and after I click "photo albums" on the left of the screen and then click "2006 Baseball U Summer Team Pictures," all of the pictures in the album have that annoying red "x" next to them. I am unable to view the images. Guessing that the...
0
1142
by: debipraad | last post by:
Hi all...... Let me tell all abt me and then i will tell abt my problem and then i need your help to go forward .......... I am debiprasad...Working as a Rigging Artist in Paprikaas Animation Studio.. I did a C & C++ course in System domain in Indira Nagar...Actually my background is Bsc.(Chemistry,Botany,Zoology)...While doing that course my faculty over threre told me .why you are doing this course you will not get ant job in this..bcus you...
22
3297
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of seats as 0 and the flight no. is also repeating. If any can tell why is this please help me. #include<stdio.h> #include<ctype.h> #include<conio.h>
3
1463
by: RedRoses | last post by:
Hey guys i really need ur help in my C++ assignment , its very hard 4 me coz its the first time 4 me to take a course in programming or anything related to computer !!! :s so plzzzzzzzzz help me if u can ?? i'll give u the output, which i have to find its input 4 the assingnment, and u see if u can help me finding the input ! here's the output :...
5
2332
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks for user name, check in the system but does not return the correct answer please help me with it. or if you have better way of doing it would you please mind to tell me.. thanks.. #!/usr/bin/perl -w #use Getopt::Std;
0
10038
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9879
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11349
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10921
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9728
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8099
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7250
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6142
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4776
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

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.