[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Tim Peters
Tim Peters added the comment: No problem! If you are trying to swap the values in two variables `x` and `y`, in most languages that's spelled: temp = x x = y y = temp and that works in Python too. But in Python it's more common to do it with a one-liner: x, y = y, x

[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Y3Kv Bv
Y3Kv Bv added the comment: I'm a newbie at Python, also obviously not thinking hard enough over Python's mechanics. Shame on me. -- ___ Python tracker ___

[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Tim Peters
Change by Tim Peters : -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker ___ ___

[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Tim Peters
Tim Peters added the comment: What, exactly, in the output shows "the problem"? When I run it, the `a == b` part is always True, while `len(x)` and `len(crazyQuilt2)` are always 30. The other three (len(coordinates), len(x2), len(x3)) are always equal to each other, but are monotonically

[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Zachary Ware
Zachary Ware added the comment: I suspect your `useAmp` branch is not doing what you think it's doing: it's effectively replacing a random number of entries in your `crazyQuilt2` list with a duplicate entry (try `print`ing the list every time around the main loop to see what's happening to

[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Y3Kv Bv
New submission from Y3Kv Bv : Windows 7 x64, Python 3.8.1 I've encountered a very weird issue where after creating a dictionary from a list the dictionary ends up being shorter/data is lost from it. It's absolutely random when it loses, how many and which items are lost. I've attached

Re: Creating a Dictionary

2017-10-07 Thread Pavol Lisy
On 10/5/17, Chris Angelico wrote: > On Thu, Oct 5, 2017 at 12:24 PM, Stefan Ram wrote: >> One might wish to implement a small language with these commands: >> >> F - move forward >> B - move backward >> L - larger stepsize >> S - smaller stepsize >>

Re: Creating a Dictionary

2017-10-04 Thread Chris Angelico
On Thu, Oct 5, 2017 at 12:24 PM, Stefan Ram wrote: > One might wish to implement a small language with these commands: > > F - move forward > B - move backward > L - larger stepsize > S - smaller stepsize > > . One could start with the following pseudocode for a

Re: Creating a Dictionary

2017-10-04 Thread Bill
Stefan Ram wrote: One might wish to implement a small language with these commands: Explain why. What is the advantage? F - move forward B - move backward L - larger stepsize S - smaller stepsize . One could start with the following pseudocode for a dictionary: { 'F': lambda:

Re: Creating a dictionary from a .txt file

2013-04-03 Thread Neil Cerutti
On 2013-04-01, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 01 Apr 2013 11:41:03 +, Neil Cerutti wrote: I tried searching for Frost*, an interesting artist I recently learned about. Interesting artist -- is that another term for wanker? *wink* hee-hee. It

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Neil Cerutti
On 2013-03-31, Roy Smith r...@panix.com wrote: And, this is a good excuse to explore some of the interesting third-party modules. For example, mwclient (pip install mwclient) gives you a neat Python interface to wikipedia. And there's a whole landscape of string matching packages to

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Steven D'Aprano
On Mon, 01 Apr 2013 11:41:03 +, Neil Cerutti wrote: I tried searching for Frost*, an interesting artist I recently learned about. Interesting artist -- is that another term for wanker? *wink* His name, in combination with a similarly named rap artist, breaks most search tools. As

Re: Creating a dictionary from a .txt file

2013-04-01 Thread C.T.
Thanks for all the help everyone! After I manually edited the txt file, this is what I came up with: car_dict = {} car_file = open('cars.txt', 'r') for line in car_file: temp = line.strip().split(None, 2) temp2 = line.strip().split('\t') if len(temp)==3:

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Dave Angel
On 04/01/2013 07:53 PM, C.T. wrote: Thanks for all the help everyone! After I manually edited the txt file, this is what I came up with: car_dict = {} car_file = open('cars.txt', 'r') for line in car_file: temp = line.strip().split(None, 2) temp2 = line.strip().split('\t')

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Walter Hurry
On Mon, 01 Apr 2013 23:53:40 +, Steven D'Aprano wrote: As far as I'm concerned, anyone in the 21st century who names themselves or their work (a movie, book, programming language, etc.) something which breaks search tools is just *begging* for obscurity, and we ought to respect their

Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this: 1958 MGA Twin Cam 1958 Zunndapp Janus 1961 Amphicar 1961 Corvair 1966 Peel Trident 1970 AMC Gremlin

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 2:52 AM, C.T. swilk...@gmail.com wrote: After playing around with the code, I came up with the following code to get everything into a list: d=[] car_file = open('worstcars.txt', 'r') for line in car_file: d.append(line.strip('\n')) print (d) car_file.close()

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Mark Janssen
Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. Here is a sample of what list d looks like: ['1899 Horsey

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Roy Smith
In article d15c39bc-5d2a-42c9-a76b-23768b61c...@googlegroups.com, C.T. swilk...@gmail.com wrote: Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this:

Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. Here is a

Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:06:18 PM UTC-4, Chris Angelico wrote: On Mon, Apr 1, 2013 at 2:52 AM, C.T. After playing around with the code, I came up with the following code to get everything into a list: d=[] car_file = open('worstcars.txt', 'r') for line in car_file:

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 4:19 AM, C.T. swilk...@gmail.com wrote: Thank you, Chris! I could use slicing and indexing to build the dictionary but the problem is with the car manufacturer an the car model. Either or both could be multiple names. Then you're going to need some other form of magic

Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:38:56 PM UTC-4, Roy Smith wrote: In article d15c39bc-5d2a-42c9-a76b-23768b61c...@googlegroups.com, C.T. wrote: Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Dave Angel
On 03/31/2013 12:52 PM, C.T. wrote: On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: SNIP Thank you, Mark! My problem is the data isn't consistently ordered. I can use slicing and indexing to put the year into a tuple, but because a car manufacturer could have two names (ie,

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Roy Smith
In article mailman.4023.1364751102.2939.python-l...@python.org, Dave Angel da...@davea.name wrote: On 03/31/2013 12:52 PM, C.T. wrote: On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: SNIP Thank you, Mark! My problem is the data isn't consistently ordered. I can use

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Terry Jan Reedy
On 3/31/2013 11:52 AM, C.T. wrote: Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this: 1958 MGA Twin Cam 1958 Zunndapp Janus 1961 Amphicar 1961 Corvair

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Dave Angel
On 03/31/2013 02:41 PM, Roy Smith wrote: In article mailman.4023.1364751102.2939.python-l...@python.org, Dave Angel da...@davea.name wrote: On 03/31/2013 12:52 PM, C.T. wrote: On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: SNIP Thank you, Mark! My problem is the data isn't

Creating a dictionary

2012-10-09 Thread argbsk
below is the text file i have How to create Facility as a key and then assign multiple values to it FACILITY : BACKUP FAILED BACKUP_BEFORE FAILED BACKUP_INTERCHANGE Total : 34 Passed : 32 Failed : 2 Not Run : 0 FACILITY : CDU Total : 9 Passed : 9 Failed : 0 for example Facility BACKUP is a

Re: Creating a dictionary

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote: below is the text file i have How to create Facility as a key and then assign multiple values to it To use Facility as a key in a dict: d = {} d['Facility'] = 'ham' Note that keys are case-sensitive, so that 'Facility', 'facility',

Re: Creating a dictionary

2012-10-09 Thread Roy Smith
In article 50741ffe$0$6574$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote: below is the text file i have How to create Facility as a key and then assign multiple values to it To use

Re: Creating a dictionary

2012-10-09 Thread Ulrich Eckhardt
Am 09.10.2012 13:59, schrieb arg...@gmail.com: below is the text file i have How to create Facility as a key and then assign multiple values to it The value part of a dict element can be any kind of object, like e.g. a tuple, namedtuple or even a dict. Uli --

creating a dictionary from a dictionary with regex

2007-08-22 Thread james_027
Hi, I am trying to create a dictionary from a dictionary which the help of regex to identify which keys to select. I have something like this but I feel its long and not the fastest solution ... could someone contribute? import re d= {'line2.qty':2, 'line3.qty':1, 'line5.qty':12,

Re: creating a dictionary from a dictionary with regex

2007-08-22 Thread Marc 'BlackJack' Rintsch
On Wed, 22 Aug 2007 07:13:40 +, james_027 wrote: I am trying to create a dictionary from a dictionary which the help of regex to identify which keys to select. I have something like this but I feel its long and not the fastest solution ... could someone contribute? import re d=

Re: Creating Unique Dictionary Variables from List

2007-04-12 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : On Wed, 11 Apr 2007 21:03:20 +0200, Bruno Desthuilliers wrote: Greg Corradini a écrit : Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list,

Creating Unique Dictionary Variables from List

2007-04-11 Thread Greg Corradini
/Creating-Unique-Dictionary-Variables-from-List-tf3560469.html#a9943317 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Creating Unique Dictionary Variables from List

2007-04-11 Thread Greg Corradini
://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560470.html#a9943320 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Creating Unique Dictionary Variables from List

2007-04-11 Thread Greg Corradini
://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560471.html#a9943321 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating Unique Dictionary Variables from List

2007-04-11 Thread Bruno Desthuilliers
Greg Corradini a écrit : Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned from a previous function. The pseudo code for this problem would be:

Re: Creating Unique Dictionary Variables from List

2007-04-11 Thread Greg Corradini
://mail.python.org/mailman/listinfo/python-list -- View this message in context: http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560643.html#a9947284 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating Unique Dictionary Variables from List

2007-04-11 Thread Bruno Desthuilliers
Greg Corradini a écrit : Bruno, Your help is much appreciated. Then give thanks to Dennis too !-) I will give this a try tomorrow morning and get back on how it works. Don't worry, it just works - and it's the idiomatic solution to the problem you described. --

Re: Creating Unique Dictionary Variables from List

2007-04-11 Thread Steven D'Aprano
On Wed, 11 Apr 2007 21:03:20 +0200, Bruno Desthuilliers wrote: Greg Corradini a écrit : Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned from a

creating a dictionary

2007-01-29 Thread mark
i have few variables and i want to create a dictionary with these variables such that the keys are the variable names and the corresponding values are the variable values.how do i do this easily? for ex: var1='mark' var2=['1','2','3'] my_dict = create_my_dictionary(var1, var2) and my_dict is

Re: creating a dictionary

2007-01-29 Thread Gabriel Genellina
En Mon, 29 Jan 2007 23:45:40 -0300, mark [EMAIL PROTECTED] escribió: i have few variables and i want to create a dictionary with these variables such that the keys are the variable names and the corresponding values are the variable values.how do i do this easily? for ex: var1='mark'