Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 modifying a list in an expression
i have some incoming data. each unit of data can be converted to a list. that list can be converted back to that data. the conversions are expressions. i can nest these two expression to convert the data to a list and then back. i have a modification to the data that is defined in terms of it being in the list form. the modification is copying element index B to element index A of the list like. i can do this in 3 lines:

    temp = convert_data_to_list(data)
    temp[A] = temp[B]
    data = convert_list_to_data(temp)
is there an easy way to use slicing (or something else) to make this all be a single expression?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Something like this (as you can see it's readability is not great)?

convert_list_to_data([convert_data_to_list(data)[B] if convert_data_to_list(data).index(x) == A else x for x in convert_data_to_list(data)])
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
that's also going to be slow. the code i gave is actually going to be in a loop affecting many units of data (each unit can be converted to a list). most units are strings and conversion to a list was a workaround because they are immutable. i guess squeezing this to a big expression in one line is just not going to happen.

and, yeah, it is harder to read. so i guess it's back to separate steps.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  modifying variables in local or global space Skaperen 2 61 Aug-14-2019, 07:13 AM
Last Post: Skaperen
  Song Modifying Program Starting Point BadenJaden 0 86 Jul-30-2019, 11:28 PM
Last Post: BadenJaden
Question Why does modifying a list in a for loop not seem to work? umut3806 2 164 Jul-22-2019, 08:25 PM
Last Post: umut3806
  parsing logical expression with pyparsing palo173 2 293 May-13-2019, 09:22 AM
Last Post: palo173
  Read re.split expression NewBeie 2 238 Apr-25-2019, 12:12 PM
Last Post: NewBeie
  looking fo an expression that yields a dictionary without an item Skaperen 5 345 Apr-09-2019, 02:05 AM
Last Post: Skaperen
  Get the variables in a sympy expression SJ001 8 415 Feb-12-2019, 07:25 AM
Last Post: SJ001
  iterate through a list with comparison of expression Alexandro 6 410 Jan-31-2019, 05:16 PM
Last Post: Scorpio
  assignment: not an operator nor expression, but x=y=z=3 works fine? jefdaels 1 285 Jan-29-2019, 02:19 PM
Last Post: perfringo
  Product expression. jarrod0987 1 316 Dec-13-2018, 11:32 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)