• Register
2 votes
488 views

Problem:

Hello good soul,

I am a newbie in python programming. I am having a problem printing both the name on the list and the email. Let me put it this way, I want to write a for loop to print each contact in contact_emails.
Any solution will be much appreciated.
Thanks.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution:

As per your question, I understood you want to use a for-loop to print each contact in contact_emails. It means you are willing to print both of the strings in a particular dictionary.

Let’s define some contact_emails first and then use the for-loop to print both of the strings below:

contact_emails = {
'Naymul Hasan' : 'n.hasan@gmail.com',
'Fuad Mostofa': 'mostofa.fuad@ymail.com',
'Rifat Rahman': 'rrahman@gmail.com'
}

for email in contact_emails:
print('%s is %s' % ( contact_emails[email], email))

This program will throw back the output below:

n.hasan@gmail.com is Naymul Hasan  
rrahman@gmail.com is Rifat Rahman  
mostofa.fuad@mail.com is Fuad Mostofa  

Hope this helps you. Thanks.

13 9 6
94,240 points

Related questions

2 votes
1 answer 207 views
207 views
Problem: Hi all, I am an entry-level student in Python programming. I have got an assignment from my lecturer to write a program that prints a diamond shape made of *. Well, I want to learn from the very basics. As I understood it might be the very basics of printing ... to write a nested loop program to print a rectangle. sample output for the given program below: * * * * * * Thanks in advance
asked Mar 17, 2020 Gavin 15.3k points
0 votes
1 answer 9 views
9 views
Problem: Hello When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop: Statement 1 is executed (100 time) before the execution of the code block. Statement 2 defines the condition for executing the code block. Statement 3 is executed (every time) after the code block has been executed.
asked Nov 3, 2020 Mashhoodch 9.3k points
0 votes
1 answer 116 views
116 views
I need help with the basics, I need to print 1 to100 numbers in python. Please explain with the help of an example.
asked Oct 10, 2020 Ahsan 1.8k points
0 votes
1 answer 6 views
6 views
Problem: Attention reader! Det hold of all the important Java and Collections concepts with theat a student-friendly price and become industry ready.Please write relevant answer if you find anything correct, or you want to share more information about the topic discussed above.
asked Dec 12, 2020 Mashhoodch 9.3k points
0 votes
1 answer 3 views
3 views
Problem: My code is this : d = unifrnd (0,10,[10,1]); c = d.^(-2); a = round(unifrnd(0,1,[1,10]); e = a*c btotal = e+1 SIR = 1/btotal What I want is to iterate this function 1000 times, each time the value of SIR will vary due to the ... generated. For every iteration, I want the value of SIR to be added together (summed up), and in the end of the 1000th iteration, find the average SIR(mean).
asked 3 days ago Ashty 1.1k points
0 votes
1 answer 47 views
47 views
Problem: Hello kodlogs, How can we use for loop in the python to iterate over the sequence of element I have a confusion over the range() function and the datatype like list, tuple and string. Like how can we access the elements in the list
asked Jun 9, 2020 Gavin 15.3k points
1 vote
1 answer 38 views
38 views
Problem: Hello guys, I’ve got a python list full of data. I want to print them reversely. The only condition that has to follow is to use a for-loop in the program. I know there could be several ways to do that but I want for-loop to do that. ... you've any suggestion in this regard? Please, keep your answer as simple as possible. It would be helpful for me to understand well. Thanks.
asked Jun 2, 2020 adamSw 11.3k points
1 vote
1 answer 52 views
52 views
Problem: Hello Kodlogs, I am here with a problem. This could be a simple problem for you, guys, but it’s driving me crazy. I am in a situation that needs to print multiple values in a single line. Let me describe it in my words. Say, have some integer ... value in a different line and there is no option to concatenate them. Could you please help me out? Thanks for your concern and kind help.
asked Jun 2, 2020 adamSw 11.3k points
0 votes
1 answer 24 views
24 views
Problem: Hi there! I am new to the world of programming and learning loop constructs in C#. My concept for loops is clear but I just recently encountered a code somewhere in which for loop was initialized as follows: for(;;) { } I tried running that code, but it ... I make some mistake but I want to know more about ‘for’ loops and all the possible ways in which it can be used. Thanks!
asked Nov 27, 2020 Code Learner 6k points
0 votes
1 answer 37 views
37 views
Explain with an example?
asked Oct 8, 2020 jagruthi 680 points