Playing with Lists in Python

–1 vote

I have three lists:

x = ["9", "7", "5"]
y = ["1", "3", "5"]
z = ["6", "8", "2"]

I need to write one from X, one from Y and one from Z into a file with each on a different line. How do i do that? The output should look something similar to this:

7 // 5 // 8
5 // 1 // 2
9 // 3 // 2
7 // 3 // 2
9 // 1 // 6
May 28, 2019 in Python by Fez
998 views

1 answer to this question.

0 votes

Hey @Fez, you can try something like this:

import random

x = ["9", "7", "5"]
y = ["1", "3", "5"]
z = ["6", "8", "2"]
file = open("new.txt",'w')
for a in range(0, 10):
    file.write(x[random.randrange(0,3)] + " // " + y[random.randrange(0,3)] + " // " + z[random.randrange(0,3)] + "\n")
file.close()
answered May 28, 2019 by Thanisha

Related Questions In Python

0 votes
1 answer

Pandas dataframe with multiple lists in Python

You can do it like this import pandas ...READ MORE

answered Apr 6, 2019 in Python by Esha
1,526 views
0 votes
1 answer

Copying lists in python

Assigning one list to another one simply ...READ MORE

answered Apr 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
438 views
0 votes
1 answer

Difference between two lists in python

difference = list(set(list1) - set(list2)) READ MORE

answered May 24, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,578 views
0 votes
1 answer

Using Lists and Tuples in Python

if you are familiar with C programming, ...READ MORE

answered May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
689 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,420 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,090 points
11,146 views
0 votes
1 answer

How can I logarithmic axes with matplotlib in python?

You can use the Axes.set_yscale method. That allows you ...READ MORE

answered Oct 15, 2018 in Python by charlie_brown
• 7,720 points
2,033 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP