Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6082685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:19:02+00:00 2026-05-23T11:19:02+00:00

I am quite new in python.I want to get unique string from a file.txt

  • 0

I am quite new in python.I want to get unique string from a file.txt
I have some data like so…

Tempranillo     Rioja_%28wine%29%23Wine_regions
Gr%C3%BCner_Veltliner       Czech_Republic_%28wine%29
Marsanne        California_%28wine%29
Carm%C3%A9n%C3%A8re     Wines_of_Chile
Carm%C3%A9n%C3%A8re     Washington_%28U.S._state%29
Gr%C3%BCner_Veltliner       Czech_Republic_%28wine%29

So, I have tried with the following code:

import re
import string
import urllib

for line in open('file.txt', 'r').readlines():
    left, right = string.split(line)
    relation = string.split(line)


    dom = relation[0]
    rang = relation[1]

    dom = urllib.unquote(relation[0])
    dom = dom.replace('_', ' ')


    rang= urllib.unquote(relation[1])
    rang = rang.replace('_', ' ')

How to proceed further.I need to get unique co-occurrence of (dom rang) in this format:

Tempranillo     Rioja (wine) Wine regions
Marsanne        California (wine)

Any kind of help will be greatly appreciated.Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:19:02+00:00Added an answer on May 23, 2026 at 11:19 am

    I would recommend using urllib2 — and a functional style is good for string processing like this:

    import urllib2
    
    def process_item(x):
        return urllib2.unquote(x).replace('_', ' ')
    
    def process_line(line):
        return tuple(process_item(i) for i in line.split())
    
    with open('t.txt', 'r') as infile:
        unique_wines = set(process_line(l) for l in infile)
    
    for dom, rang in sorted(unique_wines):
        print dom, ':', rang
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am quite new in python.I want to match string in some lines of
Still quite new to Haskell.. I want to read the contents of a file,
Hi I am quite new to php but i have been following some tutorials
I am new with GTKBuilder. I have included a GTKBuilder file in my Python
I'm quite new to programming in Python . I want to make an application
I am new to computer programming and have some experience programming with python. I
I'm quite new to Java and from Python and PHP, I'm used to default
I'm creating a game, and am quite new to Python generally. I created a
Iam quite new to functions in SQL and I would like to create a
I'm quite new to php and have been reading Larry Ullman book to develop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.