Question

In: Computer Science

Create an array of ten strings. Write a program to join and split these strings. Feel...

Create an array of ten strings. Write a program to join and split these strings. Feel free to use any whitespace character. Explain how the program works, when to use Python arrays, and when to use tuples, dictionaries, and sets. Explain how the program works and how it can be utilized to support an organization’s requirements.

Solutions

Expert Solution

n = int(input("Enter the number of strings you want to enter: "))
strings = []                #   created a list to store numbers
for i in range (n):
    strings.append(input("Enter the string: "))
print("Entered strings are: \n")
for i in range (n):
    print(strings[i])
    
joined_strings = ""
print("Joined strings are: ")    
joined_strings.join(strings)
joined_strings = ' '.join([str(elem) for elem in strings]) 
print(joined_strings)
split_string = joined_strings.split(" ")
print(split_string)

In the above program, string are captured into a list first. Then, using the join keyword, the list elements are appended to the string variable 'Joined_strings. Then after, the program uses split function on space delimeter to the 'joined_string' variable to split the string to multiple individual strings.

Tuples: Tuples are almost similar to Python lists. The distinction is that tuples are not modifiable. Less space is often used for tuples than lists. When we want a list of constants, we can use tuples. We may also use tuples as a key in the dictionary.


Sets: Where we do not want the collection to have redundant elements.We  have two different lists, and the common elements between them are what we want. The best alternative for this is the set. Unordered collections of basic elements are set.


Dictionaries: When we require a logical association between a key and value pair, there we need dictionary. If we want a username and password to be kept. We  should use a user name dictionary as a key and a password as a value. Dictionary is also mutable.

List: When we have a set of information that does not require random access, ,we can use lists. When we need a simple, iterable set that is updated regularly, we tend to select lists.


Related Solutions

IN JAVA write a program that creates an array of strings with 8 people in it....
IN JAVA write a program that creates an array of strings with 8 people in it. Second,  Assign a random rank between 1 to 8 to each of the players. The rankings do not change throughout the tournament. Finally, Sort the players based on the rankings and print the data (show rankings of players, in square brackets, at every step after they are ranked). USING JAVA COLLECTIONS IS NOT ALLOWED
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of...
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of strings will contain the seasons, “Winter”, “Spring”, “Summer”, and “Fall”. Your program will then contain a function that will use your seasons array to display a menu and ask the user to choose their favorite season and return that value to the main() function. Your function must include a data validation loop. The user must enter in a 1 for winter, a 2 for...
Write program to store ten integers in an array and the program will do the following...
Write program to store ten integers in an array and the program will do the following Find the average of even marks Find how many prime integers inserted Note: please solve it by c , not c++
The split method in the String class returns an array of strings consisting of the substrings...
The split method in the String class returns an array of strings consisting of the substrings split by the delimiters. However, the delimiters are not returned. Implement the following new method that returns an array of strings consisting of the substrings split by the matching delimiters, including the matching delimiters. public static String[] split(String s, String regex) For example, split("ab#12#453", "#") returns ab, #, 12, #, 453 in an array of String, and split("a?b?gf#e", "[?#]") returns a, ?, b, ?,...
Programming lang C++ Write a program that reads 10,000 words into an array of strings. The...
Programming lang C++ Write a program that reads 10,000 words into an array of strings. The program will then read a second file that contains an undetermined number of words and search the first array for each word. The program will then report the number of words in the second list that were found on the first list.
Please in C++ language Write a program that reads 10,000 words into an array of strings....
Please in C++ language Write a program that reads 10,000 words into an array of strings. The program will then read a second file that contains an undetermined number of words and search the first array for each word. The program will then report the number of words in the second list that were found on the first list.
Write a program in Java that initializes an array with ten random integers and then print...
Write a program in Java that initializes an array with ten random integers and then print three lines of output, containing: Every element at an odd index Every odd element All elements in reverse order   The program should use three different methods to implement the functionalities above. Call the primary source file ArrayManipulator.java
1.        In your program, demo the split() method for strings and attach it to one of the...
1.        In your program, demo the split() method for strings and attach it to one of the buttons. "Numbers" lesson 2.        Check if 3===3.0. Why? 3.        Find the number of zeros such that 3===3.000…01. Why can this happen? 4.    If var x=123e15, and var y=123e-15, does x===x+y? why? 5.    What is typeof NaN? Comment on its (il)logicality. "Number Methods" lesson 6.    What is the hexadecimal number ff (written in JavaScript as 0xff) in base 10? 7.    Write all the numbers from 0 to 20 in hexadecimal form....
write a java prog that include an array of strings of size 50    String[] strings...
write a java prog that include an array of strings of size 50    String[] strings = new String[50]; then find the max length of the inputs inside a method keep reading from the user until user enters keyword to stop input : may ala jony ram asd fgghff daniel jwana output : max length : 10
Create and initialize a string array, write and use 3 functions.Write a program. Create a string...
Create and initialize a string array, write and use 3 functions.Write a program. Create a string array in the main(),called firstNameArray, initialize with7 first namesJim, Tuyet, Ann, Roberto, Crystal, Valla, Mathilda Write a first function, named searchArray, that passes two arguments: a single person’s name and the array reference, into a function,This function should then search the array to see if the name is in the firstNameArray. If found, it will return the array index where the name is found,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT