1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
torisob [31]
3 years ago
12

How to format each dictionary item as a text string in the input file. How to covert each input string into a dictionary item. H

ow to format each item of your inverted dictionary as a text string in the output file.
Computers and Technology
1 answer:
Jet001 [13]3 years ago
7 0

Answer:

- To get the items of a dictionary and print them as a string, use the items() method to unpack the keys and values in a for and print or write them into a file.

for key, value in mydict.items():

   print(f"{key}, {value}")

- To convert string from user input into dictionary;

   mystring = input().split(" ")  #assuming the words are separated by a space.

   from word in mystring:

       mydict[word] = mydict.get(word, 0) + 1

This would use the words in the string as the keys of the dictionary and the count of each word as the respective values.

Explanation:

A dictionary is a data structure in python used to store data in key-value pairs. The items are enclosed in curly braces and can be accessed with the key in dot or bracket notation.

You might be interested in
19. Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program
BaLLatris [955]

Answer:

Explanation:

import java.util.Scanner;

public class SquareDisplay {

   public static void main(String []args){

    // Scanner is used to get value from command line

       Scanner console = new Scanner(System.in);

       System.out.print("Enter an integer in the range of 1-15:");

       int number = console.nextInt();

   // check if number is greater then 15 or less then 1 then return error message

       if(number>0 && number<=15){

           System.out.println("Error :Wrong Input");

           return;

       }

       for( int i=0; i< number; i++){

           for( int j =0; j<number; j++){

               System.out.print("X");

           }

           System.out.print(" ");

       }

   }

}

Code Explanation

As we want to show the square of X's we need to execute 2 nested for loop to achieve the target result. Outer for loop will determine that how many times we need to show the group of X's.

And the inner for loop will actually display's number of X's for every outer loop iteration.

Output

Case 1:

Enter an integer in the range of 1-15:5

XXXXX XXXXX XXXXX XXXXX XXXXX

Case 2:

Enter an integer in the range of 1-15:16

Error :Wrong Input

Case 3:

Enter an integer in the range of 1-15:2

XX XX

4 0
3 years ago
Parts of a Computer
Ivan

Answer:

Monitor Sorry If I’m wrong!

Explanation:

7 0
3 years ago
Read 2 more answers
Why is it important to recognize web adress endings ?
MArishka [77]

so u know were your going

7 0
4 years ago
2) List three (3) negative impact of Technology on society
Nataly [62]

Answer:

1. social media and mobile devices may lead to psychological.

2. They may contribute to more serious health conditions such as depression.

3. The overuse of technology may have a more significant impact on developing children and teenagers.

Explanation:

may this help you have a good day

5 0
3 years ago
Is Filmora 9 or Final Cut Pro Better for personal use?
padilas [110]
Final Cut Pro is better for personal use
3 0
3 years ago
Other questions:
  • Fill in the blanks.
    6·2 answers
  • Ron is the IT director at a medium-sized company and is constantly bombarded by requests from users who want to select customize
    5·1 answer
  • How can a Word user insert a page break into a document to isolate a table on a new page?
    13·2 answers
  • Which option will you use to expose your presentation to the audience
    11·2 answers
  • I have 2 questions How do i send a picture for someone to answer the hw?
    6·2 answers
  • an individual’s Body Mass Index (BMI) is a measure of a person’s weight in relation to their height. it is calculated as follows
    6·1 answer
  • what is hardware ? Name the four functional hardware of a computer system Define each of them with the help of a diagram​
    12·1 answer
  • Help a fellow coder and anser these 5 questions
    15·1 answer
  • What is binary number system? Why is it used in computer system?
    13·2 answers
  • Which object event is an indication that something has been created but not committed into the database?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!