473,544 Members | 1,948 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 1009
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
2070
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
2309
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...
6
4310
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)...
1
1602
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
3696
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...
7
1485
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...
0
1130
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...
22
3223
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
1450
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...
5
2292
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...
0
7420
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...
0
7362
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
7602
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. ...
0
7764
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
7368
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
3407
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...
1
1837
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
983
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
657
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.