Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Missing Assignments

Views: 711
Kernel: Python 3 (Anaconda 5)
#Ex 18: import numpy as np file = open('Mixed.txt') mixed = [] #initialises the list i=0 for line in file: #reads a line in the file words = line.split() for word in words: if word.isdigit(): #checks if that string is a numerical digit word = int(word) #converts that to an integer mixed.append(word) #adds that integer to a list sortedmixed = sorted(mixed) #sorts the list in ascending order np.savetxt('sortedMixed.txt', sortedmixed, fmt = '%1i')