martian94
Coder
Task:
I am a little stuck, how to do this with letters? Numbers are ok as from my former posts, but how to do this? All I have this far gives me the names as they are written in the .txt-file (unsorted) and with "None" between each name.
List of names if useful:
My code this far:
Create a text file with at least 10 first names, line separated. This file should be unsorted. Make a program that
- reads the names into a 1-dimensional table which is read line by line
- the names in the list is to be sorted in ascending order (A-Z), you are not allowed to use the sort-function
- the sorted list should be written to a new file, name by name from the list
You should use one version that use the sorting algorithm bubble sort without stop marker and one version that use insertion sorting.
I am a little stuck, how to do this with letters? Numbers are ok as from my former posts, but how to do this? All I have this far gives me the names as they are written in the .txt-file (unsorted) and with "None" between each name.
List of names if useful:
Code:
Anne
Jonas
Aase
David
Stine
Georg
Line
Brede
Camilla
Karl
My code this far:
Python:
name_list = {}
name_file = open('FirstNames.txt','r',encoding='utf-8')
first_name = name_file.readline().rstrip('\n')
while first_name !='':
name_list[first_name] = None
# Read next line
first_name = name_file.readline().rstrip('\n')
name_file.close()
# Print the whole dictionary
print(name_list)