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 in Python by Fez
10 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 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 5 in Python by Esha
136 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
34 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
442 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
63 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 175 views
+4 votes
6 answers
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
• 56,520 points
925 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
202 views