Yes, tuples would be great. I am trying this now
(Aug-23-2017, 11:55 AM)Larz60+ Wrote: [ -> ]Sorry, yu said you needed tuples:
slight modification:
import json
fruit = ("Apple", "Orange", "Banana", "Mandarin")
fruitl = list(fruit)
# this can be accessed by index:
print('fruitl[0]: {}, fruitl[2]: {}'.format(fruitl[0], fruitl[2]))
print('fruitl: {}'.format(fruitl))
# To save to file named fruit.dat:
with open('fruit.dat', 'w') as fout:
json.dump(fruitl, fout)
# To load back in:
with open('fruit.dat') as fin:
newfruit = json.load(fin)
print('newfruit: {}'.format(newfruit))
could you give an example (what the results would actually look line) of inputs and outputs
Thanks Larz.
This is what I did :
Rock = ['Hematite', 'Bentonite', 'Phylite', 'Magnetite']
Rock1 = list(Rock)
print('Rock1[0]: {}, ROck1[4]: {}'.format(Rock1[0], Rock1[2], Rock1[3], Rock1[4]))
print('Rock1: {}'.format(Rock1))
and I thought that all files that are scanned by this part of the script are subjected to a complete removal of the four words listed in Rock, and replaced by "Rock".
However I get
IndexError: list index out of range
(Aug-23-2017, 11:55 AM)Larz60+ Wrote: [ -> ]Sorry, yu said you needed tuples:
slight modification:
import json
fruit = ("Apple", "Orange", "Banana", "Mandarin")
fruitl = list(fruit)
# this can be accessed by index:
print('fruitl[0]: {}, fruitl[2]: {}'.format(fruitl[0], fruitl[2]))
print('fruitl: {}'.format(fruitl))
# To save to file named fruit.dat:
with open('fruit.dat', 'w') as fout:
json.dump(fruitl, fout)
# To load back in:
with open('fruit.dat') as fin:
newfruit = json.load(fin)
print('newfruit: {}'.format(newfruit))
could you give an example (what the results would actually look line) of inputs and outputs
PS:
Used new_trans = {}
new_trans[("bentonite", "magnetite")] = "Brittle_Rock"
mc = []
however, it words only for TWO words.
I would like to do the same for 5 words.